63
68
static TransactionServices transaction_services;
64
69
return transaction_services;
67
* Method which returns the active Transaction message
68
* for the supplied Session. If one is not found, a new Transaction
69
* message is allocated, initialized, and returned.
71
* @param The session processing the transaction
73
message::Transaction *getActiveTransactionMessage(Session *in_session);
75
* Method which attaches a transaction context
76
* the supplied transaction based on the supplied Session's
77
* transaction information. This method also ensure the
78
* transaction message is attached properly to the Session object
80
* @param The transaction message to initialize
81
* @param The Session processing this transaction
83
void initTransactionMessage(message::Transaction &in_transaction, Session *in_session);
85
* Helper method which finalizes data members for the
86
* supplied transaction's context.
88
* @param The transaction message to finalize
89
* @param The Session processing this transaction
91
void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
93
* Helper method which deletes transaction memory and
94
* unsets Session's transaction and statement messages.
96
void cleanupTransactionMessage(message::Transaction *in_transaction,
99
* Helper method which initializes a Statement message
101
* @param The statement to initialize
102
* @param The type of the statement
103
* @param The session processing this statement
105
void initStatementMessage(message::Statement &statement,
106
message::Statement::Type in_type,
107
Session *in_session);
73
* Returns true if the transaction manager should construct
74
* Transaction and Statement messages, false otherwise.
76
bool shouldConstructMessages();
109
79
* Finalizes a Statement message and sets the Session's statement
110
80
* message to NULL.
112
* @param The statement to initialize
113
* @param The session processing this statement
82
* @param statement The statement to initialize
83
* @param session The Session object processing this statement
115
85
void finalizeStatementMessage(message::Statement &statement,
116
Session *in_session);
117
/** Helper method which returns an initialized Statement message for methods
118
* doing insertion of data.
120
* @param[in] Pointer to the Session doing the processing
121
* @param[in] Pointer to the Table object being inserted into
123
message::Statement &getInsertStatement(Session *in_session,
127
* Helper method which initializes the header message for
130
* @param[inout] Statement message container to modify
131
* @param[in] Pointer to the Session doing the processing
132
* @param[in] Pointer to the Table being inserted into
134
void setInsertHeader(message::Statement &statement,
138
* Helper method which returns an initialized Statement
139
* message for methods doing updates of data.
141
* @param[in] Pointer to the Session doing the processing
142
* @param[in] Pointer to the Table object being updated
143
* @param[in] Pointer to the old data in the record
144
* @param[in] Pointer to the new data in the record
146
message::Statement &getUpdateStatement(Session *in_session,
148
const unsigned char *old_record,
149
const unsigned char *new_record);
151
* Helper method which initializes the header message for
154
* @param[inout] Statement message container to modify
155
* @param[in] Pointer to the Session doing the processing
156
* @param[in] Pointer to the Table being updated
157
* @param[in] Pointer to the old data in the record
158
* @param[in] Pointer to the new data in the record
160
void setUpdateHeader(message::Statement &statement,
163
const unsigned char *old_record,
164
const unsigned char *new_record);
166
* Helper method which returns an initialized Statement
167
* message for methods doing deletion of data.
169
* @param[in] Pointer to the Session doing the processing
170
* @param[in] Pointer to the Table object being deleted from
172
message::Statement &getDeleteStatement(Session *in_session,
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 deleted from
183
void setDeleteHeader(message::Statement &statement,
187
* Commits a normal transaction (see above) and pushes the transaction
188
* message out to the replicators.
190
* @param Pointer to the Session committing the transaction
192
void commitTransactionMessage(Session *in_session);
194
* Marks the current active transaction message as being rolled back and
195
* pushes the transaction message out to replicators.
197
* @param Pointer to the Session committing the transaction
199
void rollbackTransactionMessage(Session *in_session);
86
Session::reference session);
201
89
* Creates a new InsertRecord GPB message and pushes it to
204
* @param Pointer to the Session which has inserted a record
205
* @param Pointer to the Table containing insert information
92
* @param session Session object which has inserted a record
93
* @param table Table object containing insert information
207
95
* Grr, returning "true" here on error because of the cursor
208
96
* reversed bool return crap...fix that.
210
bool insertRecord(Session *in_session, Table *in_table);
98
bool insertRecord(Session::reference session, Table &in_table);
212
101
* Creates a new UpdateRecord GPB message and pushes it to
215
* @param Pointer to the Session which has updated a record
216
* @param Pointer to the Table containing update information
217
* @param Pointer to the raw bytes representing the old record/row
218
* @param Pointer to the raw bytes representing the new record/row
104
* @param session Session object which has updated a record
105
* @param table Table object containing update information
106
* @param old_record Pointer to the raw bytes representing the old record/row
107
* @param new_record Pointer to the raw bytes representing the new record/row
220
void updateRecord(Session *in_session,
109
void updateRecord(Session::reference session,
222
111
const unsigned char *old_record,
223
112
const unsigned char *new_record);
225
115
* Creates a new DeleteRecord GPB message and pushes it to
228
* @param Pointer to the Session which has deleted a record
229
* @param Pointer to the Table containing delete information
118
* @param session Session object which has deleted a record
119
* @param table Table object containing delete information
120
* @param use_update_record If true, uses the values from the update row instead
231
void deleteRecord(Session *in_session, Table *in_table);
122
void deleteRecord(Session::reference session,
124
bool use_update_record= false);
233
127
* Creates a CreateSchema Statement GPB message and adds it
234
128
* to the Session's active Transaction GPB message for pushing
235
129
* out to the replicator streams.
237
* @param[in] Pointer to the Session which issued the statement
238
* @param[in] message::Schema message describing new schema
131
* @param[in] session Session object which issued the statement
132
* @param[in] schema message::Schema message describing new schema
240
void createSchema(Session *in_session, const message::Schema &schema);
134
void createSchema(Session::reference session, const message::Schema &schema);
242
137
* Creates a DropSchema Statement GPB message and adds it
243
138
* to the Session's active Transaction GPB message for pushing
244
139
* out to the replicator streams.
246
* @param[in] Pointer to the Session which issued the statement
247
* @param[in] message::Schema message describing new schema
249
void dropSchema(Session *in_session, const std::string &schema_name);
141
* @param[in] session Session object which issued the statement
142
* @param[in] identifier Identifier for the schema to drop
144
void dropSchema(Session::reference session,
145
identifier::Schema::const_reference identifier);
148
* Creates an AlterSchema Statement GPB message and adds it
149
* to the Session's active Transaction GPB message for pushing
150
* out to the replicator streams.
152
* @param[in] session Session object which issued the statement
153
* @param[in] old_schema Original schema definition
154
* @param[in] new_schema New schema definition
156
void alterSchema(Session::reference session,
157
const message::schema::shared_ptr &old_schema,
158
const message::Schema &new_schema);
251
161
* Creates a CreateTable Statement GPB message and adds it
252
162
* to the Session's active Transaction GPB message for pushing
253
163
* out to the replicator streams.
255
* @param[in] Pointer to the Session which issued the statement
256
* @param[in] message::Table message describing new schema
165
* @param[in] session Session object which issued the statement
166
* @param[in] table message::Table message describing new schema
258
void createTable(Session *in_session, const message::Table &table);
168
void createTable(Session::reference session, const message::Table &table);
260
171
* Creates a DropTable Statement GPB message and adds it
261
172
* to the Session's active Transaction GPB message for pushing
262
173
* out to the replicator streams.
264
* @param[in] Pointer to the Session which issued the statement
265
* @param[in] The schema of the table being dropped
266
* @param[in] The table name of the table being dropped
267
* @param[in] Did the user specify an IF EXISTS clause?
175
* @param[in] session Session object which issued the statement
176
* @param[in] table Identifier for the table being dropped
177
* @param[in] if_exists Did the user specify an IF EXISTS clause?
269
void dropTable(Session *in_session,
270
const std::string &schema_name,
271
const std::string &table_name,
179
void dropTable(Session::reference session,
180
const identifier::Table &table,
274
184
* Creates a TruncateTable Statement GPB message and adds it
275
185
* to the Session's active Transaction GPB message for pushing
276
186
* out to the replicator streams.
278
* @param[in] Pointer to the Session which issued the statement
279
* @param[in] The Table being truncated
188
* @param[in] session Session object which issued the statement
189
* @param[in] table The Table being truncated
281
void truncateTable(Session *in_session, Table *in_table);
191
void truncateTable(Session::reference session, Table &table);
283
194
* Creates a new RawSql GPB message and pushes it to
288
199
* on the I_S, etc. Not sure what to do with administrative
289
200
* commands like CHECK TABLE, though..
291
* @param Pointer to the Session which issued the statement
292
* @param Query string
202
* @param session Session object which issued the statement
203
* @param query Query string
294
void rawStatement(Session *in_session, const std::string &query);
205
void rawStatement(Session::reference session, const std::string &query);
295
207
/* transactions: interface to plugin::StorageEngine functions */
296
int ha_commit_one_phase(Session *session, bool all);
297
int ha_rollback_trans(Session *session, bool all);
299
/* transactions: these functions never call plugin::StorageEngine functions directly */
300
int ha_commit_trans(Session *session, bool all);
301
int ha_autocommit_or_rollback(Session *session, int error);
208
int rollbackTransaction(Session::reference session, bool all);
211
* Commit the current transaction.
214
* @retval 1 transaction was rolled back
215
* @retval 2 error during commit, data may be inconsistent
218
* Since we don't support nested statement transactions in 5.0,
219
* we can't commit or rollback stmt transactions while we are inside
220
* stored functions or triggers. So we simply do nothing now.
221
* This should be fixed in later ( >= 5.1) releases.
223
int commitTransaction(Session::reference session, bool all);
226
* This is used to commit or rollback a single statement depending on
227
* the value of error.
230
* Note that if the autocommit is on, then the following call inside
231
* InnoDB will commit or rollback the whole transaction (= the statement). The
232
* autocommit mechanism built into InnoDB is based on counting locks, but if
233
* the user has used LOCK TABLES then that mechanism does not know to do the
236
int autocommitOrRollback(Session::reference session, int error);
304
int ha_rollback_to_savepoint(Session *session, NamedSavepoint &sv);
305
int ha_savepoint(Session *session, NamedSavepoint &sv);
306
int ha_release_savepoint(Session *session, NamedSavepoint &sv);
307
bool mysql_xa_recover(Session *session);
239
int rollbackToSavepoint(Session::reference session, NamedSavepoint &sv);
240
int setSavepoint(Session::reference session, NamedSavepoint &sv);
241
int releaseSavepoint(Session::reference session, NamedSavepoint &sv);
310
244
* Marks a storage engine as participating in a statement
376
310
* time when this method is called except from the
377
311
* TransactionServices::registerResourceForStatement method.
379
void registerResourceForTransaction(Session *session,
313
void registerResourceForTransaction(Session::reference session,
380
314
plugin::MonitoredInTransaction *monitored,
381
315
plugin::TransactionalStorageEngine *engine);
382
void registerResourceForTransaction(Session *session,
317
void registerResourceForTransaction(Session::reference session,
383
318
plugin::MonitoredInTransaction *monitored,
384
319
plugin::TransactionalStorageEngine *engine,
385
320
plugin::XaResourceManager *resource_manager);
322
void allocateNewTransactionId();
329
* Send server startup event.
331
* @param session Session object
333
* @retval true Success
334
* @retval false Failure
336
bool sendStartupEvent(Session::reference session);
339
* Send server shutdown event.
341
* @param session Session object
343
* @retval true Success
344
* @retval false Failure
346
bool sendShutdownEvent(Session::reference session);
351
* Method which returns the active Transaction message
352
* for the supplied Session. If one is not found, a new Transaction
353
* message is allocated, initialized, and returned. It is possible that
354
* we may want to NOT increment the transaction id for a new Transaction
355
* object (e.g., splitting up Transactions into smaller chunks). The
356
* should_inc_trx_id flag controls if we do this.
358
* @param session The Session object processing the transaction
359
* @param should_inc_trx_id If true, increments the transaction id for a new trx
361
message::Transaction *getActiveTransactionMessage(Session::reference session,
362
bool should_inc_trx_id= true);
365
* Method which attaches a transaction context
366
* the supplied transaction based on the supplied Session's
367
* transaction information. This method also ensure the
368
* transaction message is attached properly to the Session object
370
* @param transaction The transaction message to initialize
371
* @param session The Session object processing this transaction
372
* @param should_inc_trx_id If true, increments the transaction id for a new trx
374
void initTransactionMessage(message::Transaction &transaction,
375
Session::reference session,
376
bool should_inc_trx_id);
379
* Helper method which initializes a Statement message
381
* @param statement The statement to initialize
382
* @param type The type of the statement
383
* @param session The Session object processing this statement
385
void initStatementMessage(message::Statement &statement,
386
message::Statement::Type type,
387
Session::const_reference session);
390
* Helper method which finalizes data members for the
391
* supplied transaction's context.
393
* @param transaction The transaction message to finalize
394
* @param session The Session object processing this transaction
396
void finalizeTransactionMessage(message::Transaction &transaction,
397
Session::const_reference session);
400
* Helper method which deletes transaction memory and
401
* unsets Session's transaction and statement messages.
403
void cleanupTransactionMessage(message::Transaction *transaction,
404
Session::reference session);
406
/** Helper method which returns an initialized Statement message for methods
407
* doing insertion of data.
409
* @param[in] session Session object doing the processing
410
* @param[in] table Table object being inserted into
411
* @param[out] next_segment_id The next Statement segment id to be used
413
message::Statement &getInsertStatement(Session::reference session,
415
uint32_t *next_segment_id);
418
* Helper method which initializes the header message for
421
* @param[in,out] statement Statement message container to modify
422
* @param[in] session Session object doing the processing
423
* @param[in] table Table object being inserted into
425
void setInsertHeader(message::Statement &statement,
426
Session::const_reference session,
429
* Helper method which returns an initialized Statement
430
* message for methods doing updates of data.
432
* @param[in] session Session object doing the processing
433
* @param[in] table Table object being updated
434
* @param[in] old_record Pointer to the old data in the record
435
* @param[in] new_record Pointer to the new data in the record
436
* @param[out] next_segment_id The next Statement segment id to be used
438
message::Statement &getUpdateStatement(Session::reference session,
440
const unsigned char *old_record,
441
const unsigned char *new_record,
442
uint32_t *next_segment_id);
444
* Helper method which initializes the header message for
447
* @param[in,out] statement Statement message container to modify
448
* @param[in] session Session object doing the processing
449
* @param[in] table Table object being updated
450
* @param[in] old_record Pointer to the old data in the record
451
* @param[in] new_record Pointer to the new data in the record
453
void setUpdateHeader(message::Statement &statement,
454
Session::const_reference session,
456
const unsigned char *old_record,
457
const unsigned char *new_record);
460
* Helper method which returns an initialized Statement
461
* message for methods doing deletion of data.
463
* @param[in] session Session object doing the processing
464
* @param[in] table Table object being deleted from
465
* @param[out] next_segment_id The next Statement segment id to be used
467
message::Statement &getDeleteStatement(Session::reference session,
469
uint32_t *next_segment_id);
472
* Helper method which initializes the header message for
475
* @param[in,out] statement Statement message container to modify
476
* @param[in] session Session object doing the processing
477
* @param[in] table Table object being deleted from
479
void setDeleteHeader(message::Statement &statement,
480
Session::const_reference session,
484
* Commits a normal transaction (see above) and pushes the transaction
485
* message out to the replicators.
487
* @param session Session object committing the transaction
489
int commitTransactionMessage(Session::reference session);
492
* Marks the current active transaction message as being rolled back and
493
* pushes the transaction message out to replicators.
495
* @param session Session object committing the transaction
497
void rollbackTransactionMessage(Session::reference session);
500
* Rolls back the current statement, deleting the last Statement out of
501
* the current Transaction message.
503
* @param session Session object committing the transaction
505
* @note This depends on having clear statement boundaries (i.e., one
506
* Statement message per actual SQL statement).
508
void rollbackStatementMessage(Session::reference session);
511
* Checks if a field has been updated
513
* @param current_field Pointer to the field to check if it is updated
514
* @param table Table object containing update information
515
* @param old_record Pointer to the raw bytes representing the old record/row
516
* @param new_record Pointer to the raw bytes representing the new record/row
518
bool isFieldUpdated(Field *current_field,
520
const unsigned char *old_record,
521
const unsigned char *new_record);
524
* Create a Transaction that contains event information and send it off.
526
* This differs from other uses of Transaction in that we don't use the
527
* message associated with Session. We create a totally new message and
530
* @param session Session object
531
* @param event Event message to send
533
* @note Used by the public Events API.
535
* @returns Non-zero on error
537
int sendEvent(Session::reference session, const message::Event &event);
540
* Makes a given Transaction message segmented.
542
* The given Transaction message will have its segment information set
543
* appropriately and a new Transaction message, containing the same
544
* transaction ID as the supplied Transaction, and is created.
546
* @param session Session object
547
* @param transaction Transaction message to segment.
549
* @returns Returns a pointer to a new Transaction message ready for use.
551
message::Transaction *segmentTransactionMessage(Session::reference session,
552
message::Transaction *transaction);
554
int commitPhaseOne(Session::reference session, bool all);
556
uint64_t getCurrentTransactionId(Session::reference session);
558
plugin::XaStorageEngine *xa_storage_engine;
388
561
} /* namespace drizzled */