69
63
TRANSACTION= 1, /* A GPB Transaction Message */
70
64
BLOB= 2 /* A BLOB value */
72
typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
73
typedef std::vector<ReplicationPair> ReplicationStreams;
75
* Method which is called after plugins have been loaded but
76
* before the first client connects. It determines if the registration
77
* of applier and replicator plugins is proper and pairs
78
* the applier and requested replicator plugins into the replication
83
* This is only necessary because we don't yet have plugin dependency
86
bool evaluateRegisteredPlugins();
88
* Helper method which pushes a constructed message out to the registered
89
* replicator and applier plugins.
91
* @param Session descriptor
68
* Atomic boolean set to true if any *active* replicators
69
* or appliers are actually registered.
71
atomic<bool> is_active;
73
* The timestamp of the last time a Transaction message was successfully
74
* applied (sent to an Applier)
76
atomic<uint64_t> last_applied_timestamp;
77
/** Our collection of replicator plugins */
78
std::vector<drizzled::plugin::TransactionReplicator *> replicators;
79
/** Our collection of applier plugins */
80
std::vector<drizzled::plugin::TransactionApplier *> appliers;
82
* Helper method which is called after any change in the
83
* registered appliers or replicators to evaluate whether
84
* any remaining plugins are actually active.
86
* This method properly sets the is_active member variable.
88
void evaluateActivePlugins();
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.
94
* @param The session processing the transaction
96
drizzled::message::Transaction *getActiveTransaction(Session *in_session) const;
98
* Helper method which attaches a transaction context
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
103
* @param The transaction message to initialize
104
* @param The Session processing this transaction
106
void initTransaction(drizzled::message::Transaction &in_command, Session *in_session) const;
108
* Helper method which finalizes data members for the
109
* supplied transaction's context.
111
* @param The transaction message to finalize
112
* @param The Session processing this transaction
114
void finalizeTransaction(drizzled::message::Transaction &in_command, Session *in_session) const;
116
* Helper method which deletes transaction memory and
117
* unsets Session's transaction and statement messages.
119
void cleanupTransaction(message::Transaction *in_transaction,
120
Session *in_session) const;
122
* Helper method which initializes a Statement message
124
* @param The statement to initialize
125
* @param The type of the statement
126
* @param The session processing this statement
128
void initStatement(drizzled::message::Statement &statement,
129
drizzled::message::Statement::Type in_type,
130
Session *in_session) const;
132
* Helper method which returns an initialized Statement
133
* message for methods doing insertion of data.
135
* @param[in] Pointer to the Session doing the processing
136
* @param[in] Pointer to the Table object being inserted into
138
message::Statement &getInsertStatement(Session *in_session,
139
Table *in_table) const;
142
* Helper method which initializes the header message for
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
149
void setInsertHeader(message::Statement &statement,
151
Table *in_table) const;
153
* Helper method which returns an initialized Statement
154
* message for methods doing updates of data.
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
161
message::Statement &getUpdateStatement(Session *in_session,
163
const unsigned char *old_record,
164
const unsigned char *new_record) const;
166
* Helper method which initializes the header message for
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
175
void setUpdateHeader(message::Statement &statement,
178
const unsigned char *old_record,
179
const unsigned char *new_record) const;
181
* Helper method which returns an initialized Statement
182
* message for methods doing deletion of data.
184
* @param[in] Pointer to the Session doing the processing
185
* @param[in] Pointer to the Table object being deleted from
187
message::Statement &getDeleteStatement(Session *in_session,
188
Table *in_table) const;
191
* Helper method which initializes the header message for
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
198
void setDeleteHeader(message::Statement &statement,
200
Table *in_table) const;
202
* Helper method which pushes a constructed message out
203
* to the registered replicator and applier plugins.
92
205
* @param Message to push out
94
plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
95
message::Transaction &to_push);
207
void push(drizzled::message::Transaction &to_push);
114
227
* a replicator and an applier that are *active*?
116
229
bool isActive() const;
119
* Returns the list of replication streams
121
ReplicationStreams &getReplicationStreams();
124
231
* Attaches a replicator to our internal collection of
127
234
* @param Pointer to a replicator to attach/register
129
void attachReplicator(plugin::TransactionReplicator *in_replicator);
236
void attachReplicator(drizzled::plugin::TransactionReplicator *in_replicator);
132
238
* Detaches/unregisters a replicator with our internal
133
239
* collection of replicators.
135
241
* @param Pointer to the replicator to detach
137
void detachReplicator(plugin::TransactionReplicator *in_replicator);
243
void detachReplicator(drizzled::plugin::TransactionReplicator *in_replicator);
140
245
* Attaches a applier to our internal collection of
143
248
* @param Pointer to a applier to attach/register
144
* @param The name of the replicator to pair with
146
void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
250
void attachApplier(drizzled::plugin::TransactionApplier *in_applier);
149
252
* Detaches/unregisters a applier with our internal
150
253
* collection of appliers.
152
255
* @param Pointer to the applier to detach
154
void detachApplier(plugin::TransactionApplier *in_applier);
157
* Returns the timestamp of the last Transaction which was sent to an
257
void detachApplier(drizzled::plugin::TransactionApplier *in_applier);
259
* Creates a new Transaction GPB message and attaches the message
260
* to the supplied session object.
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.
268
* @param Pointer to the Session starting the transaction
270
void startNormalTransaction(Session *in_session);
272
* Commits a normal transaction (see above) and pushes the
273
* transaction message out to the replicators.
275
* @param Pointer to the Session committing the transaction
277
void commitNormalTransaction(Session *in_session);
279
* Marks the current active transaction message as being rolled
280
* back and pushes the transaction message out to replicators.
282
* @param Pointer to the Session committing the transaction
284
void rollbackTransaction(Session *in_session);
286
* Finalizes a Statement message and sets the Session's statement
289
* @param The statement to initialize
290
* @param The session processing this statement
292
void finalizeStatement(drizzled::message::Statement &statement,
293
Session *in_session) const;
295
* Creates a new InsertRecord GPB message and pushes it to
298
* @param Pointer to the Session which has inserted a record
299
* @param Pointer to the Table containing insert information
301
void insertRecord(Session *in_session, Table *in_table);
303
* Creates a new UpdateRecord GPB message and pushes it to
306
* @param Pointer to the Session which has updated a record
307
* @param Pointer to the Table containing update information
308
* @param Pointer to the raw bytes representing the old record/row
309
* @param Pointer to the raw bytes representing the new record/row
311
void updateRecord(Session *in_session,
313
const unsigned char *old_record,
314
const unsigned char *new_record);
316
* Creates a new DeleteRecord GPB message and pushes it to
319
* @param Pointer to the Session which has deleted a record
320
* @param Pointer to the Table containing delete information
322
void deleteRecord(Session *in_session, Table *in_table);
324
* Creates a new RawSql GPB message and pushes it to
327
* @TODO With a real data dictionary, this really shouldn't
328
* be needed. CREATE TABLE would map to insertRecord call
329
* on the I_S, etc. Not sure what to do with administrative
330
* commands like CHECK TABLE, though..
332
* @param Pointer to the Session which issued the statement
333
* @param Query string
334
* @param Length of the query string
336
void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
338
* Returns the timestamp of the last Transaction which was sent to
160
341
uint64_t getLastAppliedTimestamp() const;
162
typedef std::vector<plugin::TransactionReplicator *> Replicators;
163
typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
165
* Atomic boolean set to true if any *active* replicators
166
* or appliers are actually registered.
170
* The timestamp of the last time a Transaction message was successfully
171
* applied (sent to an Applier)
173
atomic<uint64_t> last_applied_timestamp;
174
/** Our collection of registered replicator plugins */
175
Replicators replicators;
176
/** Our collection of registered applier plugins and their requested replicator plugin names */
178
/** Our replication streams */
179
ReplicationStreams replication_streams;
181
* Strips underscores and lowercases supplied replicator name
182
* or requested name, and appends the suffix "replicator" if missing...
184
void normalizeReplicatorName(std::string &name);
187
} /* namespace drizzled */
344
} /* end namespace drizzled */
189
346
#endif /* DRIZZLED_REPLICATION_SERVICES_H */