71
63
TRANSACTION= 1, /* A GPB Transaction Message */
72
64
BLOB= 2 /* A BLOB value */
74
typedef std::pair<plugin::TransactionReplicator *, plugin::TransactionApplier *> ReplicationPair;
75
typedef std::vector<ReplicationPair> ReplicationStreams;
77
* Method which is called after plugins have been loaded but
78
* before the first client connects. It determines if the registration
79
* of applier and replicator plugins is proper and pairs
80
* the applier and requested replicator plugins into the replication
85
* This is only necessary because we don't yet have plugin dependency
88
bool evaluateRegisteredPlugins();
90
* Helper method which pushes a constructed message out to the registered
91
* replicator and applier plugins.
93
* @param Session descriptor
66
typedef std::vector<plugin::TransactionReplicator *> Replicators;
67
typedef std::vector<plugin::TransactionApplier *> Appliers;
70
* Atomic boolean set to true if any *active* replicators
71
* or appliers are actually registered.
73
atomic<bool> is_active;
75
* The timestamp of the last time a Transaction message was successfully
76
* applied (sent to an Applier)
78
atomic<uint64_t> last_applied_timestamp;
79
/** Our collection of replicator plugins */
80
Replicators replicators;
81
/** Our collection of applier plugins */
84
* Helper method which is called after any change in the
85
* registered appliers or replicators to evaluate whether
86
* any remaining plugins are actually active.
88
* This method properly sets the is_active member variable.
90
void evaluateActivePlugins();
92
* Helper method which returns the active Transaction message
93
* for the supplied Session. If one is not found, a new Transaction
94
* message is allocated, initialized, and returned.
96
* @param The session processing the transaction
98
drizzled::message::Transaction *getActiveTransaction(Session *in_session) const;
100
* Helper method which attaches a transaction context
101
* the supplied transaction based on the supplied Session's
102
* transaction information. This method also ensure the
103
* transaction message is attached properly to the Session object
105
* @param The transaction message to initialize
106
* @param The Session processing this transaction
108
void initTransaction(drizzled::message::Transaction &in_command, Session *in_session) const;
110
* Helper method which finalizes data members for the
111
* supplied transaction's context.
113
* @param The transaction message to finalize
114
* @param The Session processing this transaction
116
void finalizeTransaction(drizzled::message::Transaction &in_command, Session *in_session) const;
118
* Helper method which deletes transaction memory and
119
* unsets Session's transaction and statement messages.
121
void cleanupTransaction(message::Transaction *in_transaction,
122
Session *in_session) const;
124
* Returns true if the transaction contains any Statement
125
* messages which are not end segments (i.e. a bulk statement has
126
* previously been sent to replicators).
128
* @param The transaction to check
130
bool transactionContainsBulkSegment(const drizzled::message::Transaction &transaction) const;
132
* Helper method which initializes a Statement message
134
* @param The statement to initialize
135
* @param The type of the statement
136
* @param The session processing this statement
138
void initStatement(drizzled::message::Statement &statement,
139
drizzled::message::Statement::Type in_type,
140
Session *in_session) const;
142
* Helper method which returns an initialized Statement
143
* message for methods doing insertion of data.
145
* @param[in] Pointer to the Session doing the processing
146
* @param[in] Pointer to the Table object being inserted into
148
message::Statement &getInsertStatement(Session *in_session,
149
Table *in_table) const;
152
* Helper method which initializes the header message for
155
* @param[inout] Statement message container to modify
156
* @param[in] Pointer to the Session doing the processing
157
* @param[in] Pointer to the Table being inserted into
159
void setInsertHeader(message::Statement &statement,
161
Table *in_table) const;
163
* Helper method which returns an initialized Statement
164
* message for methods doing updates of data.
166
* @param[in] Pointer to the Session doing the processing
167
* @param[in] Pointer to the Table object being updated
168
* @param[in] Pointer to the old data in the record
169
* @param[in] Pointer to the new data in the record
171
message::Statement &getUpdateStatement(Session *in_session,
173
const unsigned char *old_record,
174
const unsigned char *new_record) const;
176
* Helper method which initializes the header message for
179
* @param[inout] Statement message container to modify
180
* @param[in] Pointer to the Session doing the processing
181
* @param[in] Pointer to the Table being updated
182
* @param[in] Pointer to the old data in the record
183
* @param[in] Pointer to the new data in the record
185
void setUpdateHeader(message::Statement &statement,
188
const unsigned char *old_record,
189
const unsigned char *new_record) const;
191
* Helper method which returns an initialized Statement
192
* message for methods doing deletion of data.
194
* @param[in] Pointer to the Session doing the processing
195
* @param[in] Pointer to the Table object being deleted from
197
message::Statement &getDeleteStatement(Session *in_session,
198
Table *in_table) const;
201
* Helper method which initializes the header message for
204
* @param[inout] Statement message container to modify
205
* @param[in] Pointer to the Session doing the processing
206
* @param[in] Pointer to the Table being deleted from
208
void setDeleteHeader(message::Statement &statement,
210
Table *in_table) const;
212
* Helper method which pushes a constructed message out
213
* to the registered replicator and applier plugins.
94
215
* @param Message to push out
96
plugin::ReplicationReturnCode pushTransactionMessage(Session &in_session,
97
message::Transaction &to_push);
217
void push(drizzled::message::Transaction &to_push);
116
237
* a replicator and an applier that are *active*?
118
239
bool isActive() const;
121
* Returns the list of replication streams
123
ReplicationStreams &getReplicationStreams();
126
241
* Attaches a replicator to our internal collection of
129
244
* @param Pointer to a replicator to attach/register
131
void attachReplicator(plugin::TransactionReplicator *in_replicator);
246
void attachReplicator(drizzled::plugin::TransactionReplicator *in_replicator);
134
248
* Detaches/unregisters a replicator with our internal
135
249
* collection of replicators.
137
251
* @param Pointer to the replicator to detach
139
void detachReplicator(plugin::TransactionReplicator *in_replicator);
253
void detachReplicator(drizzled::plugin::TransactionReplicator *in_replicator);
142
255
* Attaches a applier to our internal collection of
145
258
* @param Pointer to a applier to attach/register
146
* @param The name of the replicator to pair with
148
void attachApplier(plugin::TransactionApplier *in_applier, const std::string &requested_replicator);
260
void attachApplier(drizzled::plugin::TransactionApplier *in_applier);
151
262
* Detaches/unregisters a applier with our internal
152
263
* collection of appliers.
154
265
* @param Pointer to the applier to detach
156
void detachApplier(plugin::TransactionApplier *in_applier);
159
* Returns the timestamp of the last Transaction which was sent to an
267
void detachApplier(drizzled::plugin::TransactionApplier *in_applier);
269
* Commits a normal transaction (see above) and pushes the
270
* transaction message out to the replicators.
272
* @param Pointer to the Session committing the transaction
274
void commitTransaction(Session *in_session);
276
* Marks the current active transaction message as being rolled
277
* back and pushes the transaction message out to replicators.
279
* @param Pointer to the Session committing the transaction
281
void rollbackTransaction(Session *in_session);
283
* Finalizes a Statement message and sets the Session's statement
286
* @param The statement to initialize
287
* @param The session processing this statement
289
void finalizeStatement(drizzled::message::Statement &statement,
290
Session *in_session) const;
292
* Creates a new InsertRecord GPB message and pushes it to
295
* @param Pointer to the Session which has inserted a record
296
* @param Pointer to the Table containing insert information
298
* Grr, returning "true" here on error because of the cursor
299
* reversed bool return crap...fix that.
301
bool 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 TruncateTable Statement GPB message and add it
325
* to the Session's active Transaction GPB message for pushing
326
* out to the replicator streams.
328
* @param[in] Pointer to the Session which issued the statement
329
* @param[in] The Table being truncated
331
void truncateTable(Session *in_session, Table *in_table);
333
* Creates a new RawSql GPB message and pushes it to
336
* @TODO With a real data dictionary, this really shouldn't
337
* be needed. CREATE TABLE would map to insertRecord call
338
* on the I_S, etc. Not sure what to do with administrative
339
* commands like CHECK TABLE, though..
341
* @param Pointer to the Session which issued the statement
342
* @param Query string
343
* @param Length of the query string
345
void rawStatement(Session *in_session, const char *in_query, size_t in_query_len);
347
* Returns the timestamp of the last Transaction which was sent to
162
350
uint64_t getLastAppliedTimestamp() const;
164
typedef std::vector<plugin::TransactionReplicator *> Replicators;
165
typedef std::vector<std::pair<std::string, plugin::TransactionApplier *> > Appliers;
167
* Atomic boolean set to true if any *active* replicators
168
* or appliers are actually registered.
172
* The timestamp of the last time a Transaction message was successfully
173
* applied (sent to an Applier)
175
atomic<uint64_t> last_applied_timestamp;
176
/** Our collection of registered replicator plugins */
177
Replicators replicators;
178
/** Our collection of registered applier plugins and their requested replicator plugin names */
180
/** Our replication streams */
181
ReplicationStreams replication_streams;
183
* Strips underscores and lowercases supplied replicator name
184
* or requested name, and appends the suffix "replicator" if missing...
186
void normalizeReplicatorName(std::string &name);
189
} /* namespace drizzled */
353
} /* end namespace drizzled */
191
355
#endif /* DRIZZLED_REPLICATION_SERVICES_H */