~drizzle-trunk/drizzle/development

636.1.1 by Mark Atwood
add replicator plugin type
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
4
 *  Copyright (C) 2008-2009 Sun Microsystems
636.1.1 by Mark Atwood
add replicator plugin type
5
 *
1039.5.11 by Jay Pipes
Adds multi-value INSERT test, modifies TransactionServices to support UPDATE statements (though WHERE clause still not done...)
6
 *  Authors:
7
 *
8
 *    Jay Pipes <joinfu@sun.com>
9
 *
636.1.1 by Mark Atwood
add replicator plugin type
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; version 2 of the License.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
 */
23
1039.5.31 by Jay Pipes
This patch does a few things:
24
#ifndef DRIZZLED_REPLICATION_SERVICES_H
25
#define DRIZZLED_REPLICATION_SERVICES_H
636.1.1 by Mark Atwood
add replicator plugin type
26
1039.5.5 by Jay Pipes
This commit does two things:
27
#include "drizzled/atomics.h"
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
28
#include <vector>
636.1.1 by Mark Atwood
add replicator plugin type
29
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
30
/* some forward declarations needed */
31
class Session;
32
class Table;
33
34
namespace drizzled
35
{
36
  namespace plugin
37
  {
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
38
    class CommandReplicator;
39
    class CommandApplier;
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
40
  }
41
  namespace message
42
  {
43
    class Command;
44
  }
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
45
971.1.49 by Monty Taylor
Hooked transaction_services into Plugin_registry.
46
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
47
/**
48
 * This is a class which manages transforming internal 
49
 * transactional events into GPB messages and sending those
50
 * events out through registered replicators and appliers.
51
 */
1039.5.31 by Jay Pipes
This patch does a few things:
52
class ReplicationServices
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
53
{
1039.5.19 by Jay Pipes
Per Stew's suggestions in code review:
54
public:
55
  static const size_t DEFAULT_RECORD_SIZE= 100;
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
56
  typedef uint64_t GlobalTransactionId;
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
57
private:
1039.5.5 by Jay Pipes
This commit does two things:
58
  /** 
59
   * Atomic boolean set to true if any *active* replicators
60
   * or appliers are actually registered.
61
   */
62
  atomic<bool> is_active;
1039.5.31 by Jay Pipes
This patch does a few things:
63
  /**
64
   * The timestamp of the last time a Command message was successfully
65
   * applied (sent to an Applier)
66
   */
67
  atomic<uint64_t> last_applied_timestamp;
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
68
  /** Our collection of replicator plugins */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
69
  std::vector<drizzled::plugin::CommandReplicator *> replicators;
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
70
  /** Our collection of applier plugins */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
71
  std::vector<drizzled::plugin::CommandApplier *> appliers;
1039.5.5 by Jay Pipes
This commit does two things:
72
  /**
73
   * Helper method which is called after any change in the
74
   * registered appliers or replicators to evaluate whether
75
   * any remaining plugins are actually active.
76
   * 
77
   * This method properly sets the is_active member variable.
78
   */
79
  void evaluateActivePlugins();
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
80
  /** 
81
   * Helper method which attaches a transaction context
82
   * the supplied command based on the supplied Session's
83
   * transaction information.
84
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
85
  void setCommandTransactionContext(drizzled::message::Command &in_command, Session *in_session) const;
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
86
  /**
87
   * Helper method which pushes a constructed message out
88
   * to the registered replicator and applier plugins.
89
   *
90
   * @param Message to push out
91
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
92
  void push(drizzled::message::Command &to_push);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
93
public:
94
  /**
1039.5.5 by Jay Pipes
This commit does two things:
95
   * Constructor
96
   */
1039.5.31 by Jay Pipes
This patch does a few things:
97
  ReplicationServices();
1130.1.2 by Monty Taylor
Re-org'd the replication stuff into slots.
98
99
  /**
100
   * Singleton method
101
   * Returns the singleton instance of ReplicationServices
102
   */
103
  static inline ReplicationServices &singleton()
104
  {
105
    static ReplicationServices replication_services;
106
    return replication_services;
107
  }
108
1039.5.5 by Jay Pipes
This commit does two things:
109
  /**
1039.5.31 by Jay Pipes
This patch does a few things:
110
   * Returns whether the ReplicationServices object
1039.5.5 by Jay Pipes
This commit does two things:
111
   * is active.  In other words, does it have both
112
   * a replicator and an applier that are *active*?
113
   */
114
  bool isActive() const;
115
  /**
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
116
   * Attaches a replicator to our internal collection of
117
   * replicators.
118
   *
119
   * @param Pointer to a replicator to attach/register
120
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
121
  void attachReplicator(drizzled::plugin::CommandReplicator *in_replicator);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
122
  /**
123
   * Detaches/unregisters a replicator with our internal
124
   * collection of replicators.
125
   *
126
   * @param Pointer to the replicator to detach
127
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
128
  void detachReplicator(drizzled::plugin::CommandReplicator *in_replicator);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
129
  /**
130
   * Attaches a applier to our internal collection of
131
   * appliers.
132
   *
133
   * @param Pointer to a applier to attach/register
134
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
135
  void attachApplier(drizzled::plugin::CommandApplier *in_applier);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
136
  /**
137
   * Detaches/unregisters a applier with our internal
138
   * collection of appliers.
139
   *
140
   * @param Pointer to the applier to detach
141
   */
1039.5.39 by Jay Pipes
This patch does a couple things in preparation for publisher and
142
  void detachApplier(drizzled::plugin::CommandApplier *in_applier);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
143
  /**
144
   * Creates a new StartTransaction GPB message and pushes
145
   * it to replicators.
146
   *
147
   * @param Pointer to the Session starting the transaction
148
   */
149
  void startTransaction(Session *in_session);
150
  /**
151
   * Creates a new CommitTransaction GPB message and pushes
152
   * it to replicators.
153
   *
154
   * @param Pointer to the Session committing the transaction
155
   */
156
  void commitTransaction(Session *in_session);
157
  /**
158
   * Creates a new RollbackTransaction GPB message and pushes
159
   * it to replicators.
160
   *
161
   * @param Pointer to the Session committing the transaction
162
   */
163
  void rollbackTransaction(Session *in_session);
164
  /**
165
   * Creates a new InsertRecord GPB message and pushes it to
166
   * replicators.
167
   *
168
   * @param Pointer to the Session which has inserted a record
169
   * @param Pointer to the Table containing insert information
170
   */
171
  void insertRecord(Session *in_session, Table *in_table);
172
  /**
173
   * Creates a new UpdateRecord GPB message and pushes it to
174
   * replicators.
175
   *
176
   * @param Pointer to the Session which has updated a record
177
   * @param Pointer to the Table containing update information
1039.5.11 by Jay Pipes
Adds multi-value INSERT test, modifies TransactionServices to support UPDATE statements (though WHERE clause still not done...)
178
   * @param Pointer to the raw bytes representing the old record/row
179
   * @param Pointer to the raw bytes representing the new record/row 
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
180
   */
1039.5.11 by Jay Pipes
Adds multi-value INSERT test, modifies TransactionServices to support UPDATE statements (though WHERE clause still not done...)
181
  void updateRecord(Session *in_session, 
182
                    Table *in_table, 
183
                    const unsigned char *old_record, 
184
                    const unsigned char *new_record);
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
185
  /**
186
   * Creates a new DeleteRecord GPB message and pushes it to
187
   * replicators.
188
   *
189
   * @param Pointer to the Session which has deleted a record
190
   * @param Pointer to the Table containing delete information
191
   */
192
  void deleteRecord(Session *in_session, Table *in_table);
193
  /**
194
   * Creates a new RawSql GPB message and pushes it to 
195
   * replicators.
196
   *
197
   * @TODO With a real data dictionary, this really shouldn't
198
   * be needed.  CREATE TABLE would map to insertRecord call
199
   * on the I_S, etc.  Not sure what to do with administrative
200
   * commands like CHECK TABLE, though..
201
   *
202
   * @param Pointer to the Session which issued the statement
203
   * @param Query string
204
   * @param Length of the query string
205
   */
206
  void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
1039.5.31 by Jay Pipes
This patch does a few things:
207
  /**
208
   * Returns the timestamp of the last Command which was sent to 
209
   * an applier.
210
   */
211
  uint64_t getLastAppliedTimestamp() const;
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
212
};
213
214
} /* end namespace drizzled */
215
1039.5.31 by Jay Pipes
This patch does a few things:
216
#endif /* DRIZZLED_REPLICATION_SERVICES_H */