~drizzle-trunk/drizzle/development

1039.5.1 by Jay Pipes
* New serial event log plugin
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008-2009 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
/**
22
 * @file
23
 *
24
 * Defines the implementation of the default replicator.
25
 *
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
26
 * @see drizzled/plugin/command_replicator.h
27
 * @see drizzled/plugin/command_applier.h
1039.5.1 by Jay Pipes
* New serial event log plugin
28
 *
29
 * @details
30
 *
31
 * This is a very simple implementation.  All we do is pass along the 
32
 * event to the supplier.  This is meant as a skeleton replicator only.
33
 *
34
 * @todo
35
 *
36
 * Want a neat project?  Take this skeleton replicator and make a
37
 * simple filtered replicator which allows the user to filter out
38
 * events based on a schema or table name...
39
 */
40
41
#include "default_replicator.h"
42
43
#include <drizzled/gettext.h>
1039.5.36 by Jay Pipes
transaction.pb.h is now replication.pb.h
44
#include <drizzled/message/replication.pb.h>
1039.5.1 by Jay Pipes
* New serial event log plugin
45
46
#include <vector>
47
#include <string>
48
49
using namespace std;
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
50
using namespace drizzled;
1039.5.1 by Jay Pipes
* New serial event log plugin
51
52
static bool sysvar_default_replicator_enable= false;
53
54
bool DefaultReplicator::isActive()
55
{
56
  return sysvar_default_replicator_enable;
57
}
58
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
59
void DefaultReplicator::replicate(plugin::CommandApplier *in_applier, message::Command &to_replicate)
1039.5.1 by Jay Pipes
* New serial event log plugin
60
{
61
  /* 
62
   * We do absolutely nothing but call the applier's apply() method, passing
63
   * along the supplied Command.  Yep, told you it was simple...
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
64
   *
65
   * Perfectly fine to use const_cast<> below.  All that does is allow the replicator
66
   * to conform to the CommandApplier::apply() API call which dictates that the applier
67
   * shall never modify the supplied Command message argument.  Since the replicator 
68
   * itself *can* modify the supplied Command message, we use const_cast<> here to
69
   * set the message to a readonly state that the compiler will like.
1039.5.1 by Jay Pipes
* New serial event log plugin
70
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
71
  in_applier->apply(const_cast<const message::Command&>(to_replicate));
1039.5.1 by Jay Pipes
* New serial event log plugin
72
}
73
74
static DefaultReplicator *default_replicator= NULL; /* The singleton replicator */
75
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
76
static int init(drizzled::plugin::Registry &registry)
1039.5.1 by Jay Pipes
* New serial event log plugin
77
{
78
  default_replicator= new DefaultReplicator();
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
79
  registry.command_replicator.add(default_replicator);
1039.5.1 by Jay Pipes
* New serial event log plugin
80
  return 0;
81
}
82
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
83
static int deinit(drizzled::plugin::Registry &registry)
1039.5.1 by Jay Pipes
* New serial event log plugin
84
{
85
  if (default_replicator)
86
  {
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
87
    registry.command_replicator.remove(default_replicator);
1039.5.1 by Jay Pipes
* New serial event log plugin
88
    delete default_replicator;
89
  }
90
  return 0;
91
}
92
93
static DRIZZLE_SYSVAR_BOOL(
94
  enable,
95
  sysvar_default_replicator_enable,
96
  PLUGIN_VAR_NOCMDARG,
97
  N_("Enable default replicator"),
98
  NULL, /* check func */
99
  NULL, /* update func */
100
  false /* default */);
101
102
static struct st_mysql_sys_var* default_replicator_system_variables[]= {
103
  DRIZZLE_SYSVAR(enable),
104
  NULL
105
};
106
107
drizzle_declare_plugin(default_replicator)
108
{
109
  "default_replicator",
110
  "0.1",
111
  "Jay Pipes",
112
  N_("Default Replicator"),
113
  PLUGIN_LICENSE_GPL,
114
  init, /* Plugin Init */
115
  deinit, /* Plugin Deinit */
116
  NULL, /* status variables */
117
  default_replicator_system_variables, /* system variables */
118
  NULL    /* config options */
119
}
120
drizzle_declare_plugin_end;