~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.h

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#define DRIZZLED_REPLICATION_SERVICES_H
26
26
 
27
27
#include "drizzled/atomics.h"
 
28
 
 
29
#include "drizzled/message/transaction.pb.h"
 
30
 
28
31
#include <vector>
29
32
 
30
33
/* some forward declarations needed */
35
38
{
36
39
  namespace plugin
37
40
  {
38
 
    class CommandReplicator;
39
 
    class CommandApplier;
40
 
  }
41
 
  namespace message
42
 
  {
43
 
    class Command;
44
 
  }
45
 
 
 
41
    class TransactionReplicator;
 
42
    class TransactionApplier;
 
43
  }
46
44
 
47
45
/**
48
46
 * This is a class which manages transforming internal 
54
52
public:
55
53
  static const size_t DEFAULT_RECORD_SIZE= 100;
56
54
  typedef uint64_t GlobalTransactionId;
 
55
  /**
 
56
   * Types of messages that can go in the transaction
 
57
   * log file.  Every time something is written into the
 
58
   * transaction log, it is preceded by a header containing
 
59
   * the type of message which follows.
 
60
   */
 
61
  enum MessageType
 
62
  {
 
63
    TRANSACTION= 1, /* A GPB Transaction Message */
 
64
    BLOB= 2 /* A BLOB value */
 
65
  };
57
66
private:
58
67
  /** 
59
68
   * Atomic boolean set to true if any *active* replicators
61
70
   */
62
71
  atomic<bool> is_active;
63
72
  /**
64
 
   * The timestamp of the last time a Command message was successfully
 
73
   * The timestamp of the last time a Transaction message was successfully
65
74
   * applied (sent to an Applier)
66
75
   */
67
76
  atomic<uint64_t> last_applied_timestamp;
68
77
  /** Our collection of replicator plugins */
69
 
  std::vector<drizzled::plugin::CommandReplicator *> replicators;
 
78
  std::vector<drizzled::plugin::TransactionReplicator *> replicators;
70
79
  /** Our collection of applier plugins */
71
 
  std::vector<drizzled::plugin::CommandApplier *> appliers;
 
80
  std::vector<drizzled::plugin::TransactionApplier *> appliers;
72
81
  /**
73
82
   * Helper method which is called after any change in the
74
83
   * registered appliers or replicators to evaluate whether
77
86
   * This method properly sets the is_active member variable.
78
87
   */
79
88
  void evaluateActivePlugins();
 
89
  /**
 
90
   * Helper method which returns the active Transaction message
 
91
   * for the supplied Session.  If one is not found, a new Transaction
 
92
   * message is allocated, initialized, and returned.
 
93
   *
 
94
   * @param The session processing the transaction
 
95
   */
 
96
  drizzled::message::Transaction *getActiveTransaction(Session *in_session) const;
80
97
  /** 
81
98
   * Helper method which attaches a transaction context
82
 
   * the supplied command based on the supplied Session's
83
 
   * transaction information.
84
 
   */
85
 
  void setCommandTransactionContext(drizzled::message::Command &in_command, Session *in_session) const;
 
99
   * the supplied transaction based on the supplied Session's
 
100
   * transaction information.  This method also ensure the
 
101
   * transaction message is attached properly to the Session object
 
102
   *
 
103
   * @param The transaction message to initialize
 
104
   * @param The Session processing this transaction
 
105
   */
 
106
  void initTransaction(drizzled::message::Transaction &in_command, Session *in_session) const;
 
107
  /** 
 
108
   * Helper method which finalizes data members for the 
 
109
   * supplied transaction's context.
 
110
   *
 
111
   * @param The transaction message to finalize 
 
112
   * @param The Session processing this transaction
 
113
   */
 
114
  void finalizeTransaction(drizzled::message::Transaction &in_command, Session *in_session) const;
 
115
  /**
 
116
   * Helper method which deletes transaction memory and
 
117
   * unsets Session's transaction and statement messages.
 
118
   */
 
119
  void cleanupTransaction(message::Transaction *in_transaction,
 
120
                          Session *in_session) const;
 
121
  /**
 
122
   * Helper method which initializes a Statement message
 
123
   *
 
124
   * @param The statement to initialize
 
125
   * @param The type of the statement
 
126
   * @param The session processing this statement
 
127
   */
 
128
  void initStatement(drizzled::message::Statement &statement,
 
129
                     drizzled::message::Statement::Type in_type,
 
130
                     Session *in_session) const;
 
131
  /**
 
132
   * Helper method which returns an initialized Statement
 
133
   * message for methods doing insertion of data.
 
134
   *
 
135
   * @param[in] Pointer to the Session doing the processing
 
136
   * @param[in] Pointer to the Table object being inserted into
 
137
   */
 
138
  message::Statement &getInsertStatement(Session *in_session,
 
139
                                         Table *in_table) const;
 
140
 
 
141
  /**
 
142
   * Helper method which initializes the header message for
 
143
   * insert operations.
 
144
   *
 
145
   * @param[inout] Statement message container to modify
 
146
   * @param[in] Pointer to the Session doing the processing
 
147
   * @param[in] Pointer to the Table being inserted into
 
148
   */
 
149
  void setInsertHeader(message::Statement &statement,
 
150
                       Session *in_session,
 
151
                       Table *in_table) const;
 
152
  /**
 
153
   * Helper method which returns an initialized Statement
 
154
   * message for methods doing updates of data.
 
155
   *
 
156
   * @param[in] Pointer to the Session doing the processing
 
157
   * @param[in] Pointer to the Table object being updated
 
158
   * @param[in] Pointer to the old data in the record
 
159
   * @param[in] Pointer to the new data in the record
 
160
   */
 
161
  message::Statement &getUpdateStatement(Session *in_session,
 
162
                                         Table *in_table,
 
163
                                         const unsigned char *old_record, 
 
164
                                         const unsigned char *new_record) const;
 
165
  /**
 
166
   * Helper method which initializes the header message for
 
167
   * update operations.
 
168
   *
 
169
   * @param[inout] Statement message container to modify
 
170
   * @param[in] Pointer to the Session doing the processing
 
171
   * @param[in] Pointer to the Table being updated
 
172
   * @param[in] Pointer to the old data in the record
 
173
   * @param[in] Pointer to the new data in the record
 
174
   */
 
175
  void setUpdateHeader(message::Statement &statement,
 
176
                       Session *in_session,
 
177
                       Table *in_table,
 
178
                       const unsigned char *old_record, 
 
179
                       const unsigned char *new_record) const;
 
180
  /**
 
181
   * Helper method which returns an initialized Statement
 
182
   * message for methods doing deletion of data.
 
183
   *
 
184
   * @param[in] Pointer to the Session doing the processing
 
185
   * @param[in] Pointer to the Table object being deleted from
 
186
   */
 
187
  message::Statement &getDeleteStatement(Session *in_session,
 
188
                                         Table *in_table) const;
 
189
 
 
190
  /**
 
191
   * Helper method which initializes the header message for
 
192
   * insert operations.
 
193
   *
 
194
   * @param[inout] Statement message container to modify
 
195
   * @param[in] Pointer to the Session doing the processing
 
196
   * @param[in] Pointer to the Table being deleted from
 
197
   */
 
198
  void setDeleteHeader(message::Statement &statement,
 
199
                       Session *in_session,
 
200
                       Table *in_table) const;
86
201
  /**
87
202
   * Helper method which pushes a constructed message out
88
203
   * to the registered replicator and applier plugins.
89
204
   *
90
205
   * @param Message to push out
91
206
   */
92
 
  void push(drizzled::message::Command &to_push);
 
207
  void push(drizzled::message::Transaction &to_push);
93
208
public:
94
209
  /**
95
210
   * Constructor
118
233
   *
119
234
   * @param Pointer to a replicator to attach/register
120
235
   */
121
 
  void attachReplicator(drizzled::plugin::CommandReplicator *in_replicator);
 
236
  void attachReplicator(drizzled::plugin::TransactionReplicator *in_replicator);
122
237
  /**
123
238
   * Detaches/unregisters a replicator with our internal
124
239
   * collection of replicators.
125
240
   *
126
241
   * @param Pointer to the replicator to detach
127
242
   */
128
 
  void detachReplicator(drizzled::plugin::CommandReplicator *in_replicator);
 
243
  void detachReplicator(drizzled::plugin::TransactionReplicator *in_replicator);
129
244
  /**
130
245
   * Attaches a applier to our internal collection of
131
246
   * appliers.
132
247
   *
133
248
   * @param Pointer to a applier to attach/register
134
249
   */
135
 
  void attachApplier(drizzled::plugin::CommandApplier *in_applier);
 
250
  void attachApplier(drizzled::plugin::TransactionApplier *in_applier);
136
251
  /**
137
252
   * Detaches/unregisters a applier with our internal
138
253
   * collection of appliers.
139
254
   *
140
255
   * @param Pointer to the applier to detach
141
256
   */
142
 
  void detachApplier(drizzled::plugin::CommandApplier *in_applier);
 
257
  void detachApplier(drizzled::plugin::TransactionApplier *in_applier);
143
258
  /**
144
 
   * Creates a new StartTransaction GPB message and pushes
145
 
   * it to replicators.
 
259
   * Creates a new Transaction GPB message and attaches the message
 
260
   * to the supplied session object.
 
261
   *
 
262
   * @note
 
263
   *
 
264
   * This method is called when a "normal" transaction -- i.e. an 
 
265
   * explicitly-started transaction from a client -- is started with 
 
266
   * BEGIN or START TRANSACTION.
146
267
   *
147
268
   * @param Pointer to the Session starting the transaction
148
269
   */
149
 
  void startTransaction(Session *in_session);
 
270
  void startNormalTransaction(Session *in_session);
150
271
  /**
151
 
   * Creates a new CommitTransaction GPB message and pushes
152
 
   * it to replicators.
 
272
   * Commits a normal transaction (see above) and pushes the
 
273
   * transaction message out to the replicators.
153
274
   *
154
275
   * @param Pointer to the Session committing the transaction
155
276
   */
156
 
  void commitTransaction(Session *in_session);
 
277
  void commitNormalTransaction(Session *in_session);
157
278
  /**
158
 
   * Creates a new RollbackTransaction GPB message and pushes
159
 
   * it to replicators.
 
279
   * Marks the current active transaction message as being rolled
 
280
   * back and pushes the transaction message out to replicators.
160
281
   *
161
282
   * @param Pointer to the Session committing the transaction
162
283
   */
163
284
  void rollbackTransaction(Session *in_session);
164
285
  /**
 
286
   * Finalizes a Statement message and sets the Session's statement
 
287
   * message to NULL.
 
288
   *
 
289
   * @param The statement to initialize
 
290
   * @param The session processing this statement
 
291
   */
 
292
  void finalizeStatement(drizzled::message::Statement &statement,
 
293
                         Session *in_session) const;
 
294
  /**
165
295
   * Creates a new InsertRecord GPB message and pushes it to
166
296
   * replicators.
167
297
   *
205
335
   */
206
336
  void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
207
337
  /**
208
 
   * Returns the timestamp of the last Command which was sent to 
 
338
   * Returns the timestamp of the last Transaction which was sent to 
209
339
   * an applier.
210
340
   */
211
341
  uint64_t getLastAppliedTimestamp() const;