~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/filtered_replicator/filtered_replicator.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-04-17 01:38:47 UTC
  • mfrom: (1237.9.238 bad-staging)
  • Revision ID: osullivan.padraig@gmail.com-20100417013847-ibjioqsfbmf5yg4g
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include <drizzled/plugin/transaction_applier.h>
42
42
#include <drizzled/message/transaction.pb.h>
43
43
#include <drizzled/plugin.h>
44
 
#include <drizzled/plugin/registry.h>
45
44
 
46
45
#include "filtered_replicator.h"
47
46
 
51
50
using namespace std;
52
51
using namespace drizzled;
53
52
 
54
 
static bool sysvar_filtered_replicator_enabled= false;
55
53
static char *sysvar_filtered_replicator_sch_filters= NULL;
56
54
static char *sysvar_filtered_replicator_tab_filters= NULL;
57
55
static char *sysvar_filtered_replicator_sch_regex= NULL;
127
125
  pthread_mutex_init(&sysvar_tab_lock, NULL);
128
126
}
129
127
 
130
 
bool FilteredReplicator::isEnabled() const
131
 
{
132
 
  return sysvar_filtered_replicator_enabled;
133
 
}
134
 
 
135
128
void FilteredReplicator::parseStatementTableMetadata(const message::Statement &in_statement,
136
129
                                                     string &in_schema_name,
137
130
                                                     string &in_table_name) const
205
198
    }
206
199
  }  
207
200
}
208
 
void FilteredReplicator::enable()
209
 
{
210
 
  sysvar_filtered_replicator_enabled= true;
211
 
}
212
 
 
213
 
void FilteredReplicator::disable()
214
 
{
215
 
  sysvar_filtered_replicator_enabled= false;
216
 
}
217
 
 
218
 
void FilteredReplicator::replicate(plugin::TransactionApplier *in_applier, 
219
 
                                   message::Transaction &to_replicate)
 
201
 
 
202
plugin::ReplicationReturnCode
 
203
FilteredReplicator::replicate(plugin::TransactionApplier *in_applier,
 
204
                              Session &in_session,
 
205
                              message::Transaction &to_replicate)
220
206
{
221
207
  string schema_name;
222
208
  string table_name;
288
274
     */
289
275
    message::TransactionContext *tc= filtered_transaction.mutable_transaction_context();
290
276
    *tc= to_replicate.transaction_context(); /* copy construct */
291
 
    in_applier->apply(filtered_transaction);
 
277
    return in_applier->apply(in_session, filtered_transaction);
292
278
  }
 
279
  return plugin::SUCCESS;
293
280
}
294
281
 
295
282
void FilteredReplicator::populateFilter(std::string input,
507
494
 
508
495
static FilteredReplicator *filtered_replicator= NULL; /* The singleton replicator */
509
496
 
510
 
static int init(plugin::Registry &registry)
511
 
{
512
 
  if (sysvar_filtered_replicator_enabled)
513
 
  {
514
 
    filtered_replicator= new(std::nothrow) 
515
 
      FilteredReplicator("filtered_replicator",
516
 
                         sysvar_filtered_replicator_sch_filters,
517
 
                         sysvar_filtered_replicator_tab_filters);
518
 
    if (filtered_replicator == NULL)
519
 
    {
520
 
      return 1;
521
 
    }
522
 
    registry.add(filtered_replicator);
523
 
  }
524
 
  return 0;
525
 
}
526
 
 
527
 
static int deinit(plugin::Registry &registry)
528
 
{
529
 
  if (filtered_replicator)
530
 
  {
531
 
    registry.remove(filtered_replicator);
532
 
    delete filtered_replicator;
533
 
  }
 
497
static int init(plugin::Context &context)
 
498
{
 
499
  filtered_replicator= new(std::nothrow) 
 
500
    FilteredReplicator("filtered_replicator",
 
501
                       sysvar_filtered_replicator_sch_filters,
 
502
                       sysvar_filtered_replicator_tab_filters);
 
503
  if (filtered_replicator == NULL)
 
504
  {
 
505
    return 1;
 
506
  }
 
507
  context.add(filtered_replicator);
534
508
  return 0;
535
509
}
536
510
 
600
574
  }
601
575
}
602
576
 
603
 
static DRIZZLE_SYSVAR_BOOL(enable,
604
 
                           sysvar_filtered_replicator_enabled,
605
 
                           PLUGIN_VAR_NOCMDARG,
606
 
                           N_("Enable filtered replicator"),
607
 
                           NULL, /* check func */
608
 
                           NULL, /* update func */
609
 
                           false /*default */);
610
577
static DRIZZLE_SYSVAR_STR(filteredschemas,
611
578
                          sysvar_filtered_replicator_sch_filters,
612
579
                          PLUGIN_VAR_OPCMDARG,
637
604
                          NULL);
638
605
 
639
606
static drizzle_sys_var* filtered_replicator_system_variables[]= {
640
 
  DRIZZLE_SYSVAR(enable),
641
607
  DRIZZLE_SYSVAR(filteredschemas),
642
608
  DRIZZLE_SYSVAR(filteredtables),
643
609
  DRIZZLE_SYSVAR(schemaregex),
645
611
  NULL
646
612
};
647
613
 
648
 
DRIZZLE_DECLARE_PLUGIN
649
 
{
650
 
  DRIZZLE_VERSION_ID,
651
 
  "filtered_replicator",
652
 
  "0.2",
653
 
  "Padraig O'Sullivan",
654
 
  N_("Filtered Replicator"),
655
 
  PLUGIN_LICENSE_GPL,
656
 
  init, /* Plugin Init */
657
 
  deinit, /* Plugin Deinit */
658
 
  filtered_replicator_system_variables, /* system variables */
659
 
  NULL    /* config options */
660
 
}
661
 
DRIZZLE_DECLARE_PLUGIN_END;
 
614
DRIZZLE_PLUGIN(init, filtered_replicator_system_variables);