69
57
static TransactionServices transaction_services;
70
58
return transaction_services;
74
* Returns true if the transaction manager should construct
75
* Transaction and Statement messages, false otherwise.
77
bool shouldConstructMessages();
80
* Finalizes a Statement message and sets the Session's statement
83
* @param statement The statement to initialize
84
* @param session The Session object processing this statement
86
void finalizeStatementMessage(message::Statement &statement,
87
Session::reference session);
90
* Creates a new InsertRecord GPB message and pushes it to
93
* @param session Session object which has inserted a record
94
* @param table Table object containing insert information
96
* Grr, returning "true" here on error because of the cursor
97
* reversed bool return crap...fix that.
99
bool insertRecord(Session::reference session, Table &in_table);
102
* Creates a new UpdateRecord GPB message and pushes it to
105
* @param session Session object which has updated a record
106
* @param table Table object containing update information
107
* @param old_record Pointer to the raw bytes representing the old record/row
108
* @param new_record Pointer to the raw bytes representing the new record/row
110
void updateRecord(Session::reference session,
112
const unsigned char *old_record,
113
const unsigned char *new_record);
116
* Creates a new DeleteRecord GPB message and pushes it to
119
* @param session Session object which has deleted a record
120
* @param table Table object containing delete information
121
* @param use_update_record If true, uses the values from the update row instead
123
void deleteRecord(Session::reference session,
125
bool use_update_record= false);
128
* Creates a CreateSchema Statement GPB message and adds it
129
* to the Session's active Transaction GPB message for pushing
130
* out to the replicator streams.
132
* @param[in] session Session object which issued the statement
133
* @param[in] schema message::Schema message describing new schema
135
void createSchema(Session::reference session, const message::Schema &schema);
138
* Creates a DropSchema Statement GPB message and adds it
139
* to the Session's active Transaction GPB message for pushing
140
* out to the replicator streams.
142
* @param[in] session Session object which issued the statement
143
* @param[in] identifier Identifier for the schema to drop
145
void dropSchema(Session::reference session,
146
identifier::Schema::const_reference identifier);
149
* Creates an AlterSchema Statement GPB message and adds it
150
* to the Session's active Transaction GPB message for pushing
151
* out to the replicator streams.
153
* @param[in] session Session object which issued the statement
154
* @param[in] old_schema Original schema definition
155
* @param[in] new_schema New schema definition
157
void alterSchema(Session::reference session,
158
const message::schema::shared_ptr &old_schema,
159
const message::Schema &new_schema);
162
* Creates a CreateTable Statement GPB message and adds it
163
* to the Session's active Transaction GPB message for pushing
164
* out to the replicator streams.
166
* @param[in] session Session object which issued the statement
167
* @param[in] table message::Table message describing new schema
169
void createTable(Session::reference session, const message::Table &table);
172
* Creates a DropTable Statement GPB message and adds it
173
* to the Session's active Transaction GPB message for pushing
174
* out to the replicator streams.
176
* @param[in] session Session object which issued the statement
177
* @param[in] table Identifier for the table being dropped
178
* @param[in] if_exists Did the user specify an IF EXISTS clause?
180
void dropTable(Session::reference session,
181
const identifier::Table &table,
185
* Creates a TruncateTable Statement GPB message and adds it
186
* to the Session's active Transaction GPB message for pushing
187
* out to the replicator streams.
189
* @param[in] session Session object which issued the statement
190
* @param[in] table The Table being truncated
192
void truncateTable(Session::reference session, Table &table);
195
* Creates a new RawSql GPB message and pushes it to
198
* @TODO With a real data dictionary, this really shouldn't
199
* be needed. CREATE TABLE would map to insertRecord call
200
* on the I_S, etc. Not sure what to do with administrative
201
* commands like CHECK TABLE, though..
203
* @param session Session object which issued the statement
204
* @param query Query string
206
void rawStatement(Session::reference session, const std::string &query);
208
60
/* transactions: interface to plugin::StorageEngine functions */
209
int rollbackTransaction(Session::reference session, bool all);
212
* Commit the current transaction.
215
* @retval 1 transaction was rolled back
216
* @retval 2 error during commit, data may be inconsistent
219
* Since we don't support nested statement transactions in 5.0,
220
* we can't commit or rollback stmt transactions while we are inside
221
* stored functions or triggers. So we simply do nothing now.
222
* This should be fixed in later ( >= 5.1) releases.
224
int commitTransaction(Session::reference session, bool all);
227
* This is used to commit or rollback a single statement depending on
228
* the value of error.
231
* Note that if the autocommit is on, then the following call inside
232
* InnoDB will commit or rollback the whole transaction (= the statement). The
233
* autocommit mechanism built into InnoDB is based on counting locks, but if
234
* the user has used LOCK TABLES then that mechanism does not know to do the
237
int autocommitOrRollback(Session::reference session, int error);
61
int ha_commit_one_phase(Session *session, bool all);
62
int ha_rollback_trans(Session *session, bool all);
64
/* transactions: these functions never call plugin::StorageEngine functions directly */
65
int ha_commit_trans(Session *session, bool all);
66
int ha_autocommit_or_rollback(Session *session, int error);
240
int rollbackToSavepoint(Session::reference session, NamedSavepoint &sv);
241
int setSavepoint(Session::reference session, NamedSavepoint &sv);
242
int releaseSavepoint(Session::reference session, NamedSavepoint &sv);
245
* Marks a storage engine as participating in a statement
250
* This method is idempotent
254
* This method should not be called more than once per resource
255
* per statement, and therefore should not need to be idempotent.
256
* Put in assert()s to test this.
258
* @param[in] session Session object
259
* @param[in] monitored Descriptor for the resource which will be participating
260
* @param[in] engine Pointer to the TransactionalStorageEngine resource
262
void registerResourceForStatement(Session::reference session,
263
plugin::MonitoredInTransaction *monitored,
264
plugin::TransactionalStorageEngine *engine);
267
* Marks an XA storage engine as participating in a statement
272
* This method is idempotent
276
* This method should not be called more than once per resource
277
* per statement, and therefore should not need to be idempotent.
278
* Put in assert()s to test this.
280
* @param[in] session Session object
281
* @param[in] monitored Descriptor for the resource which will be participating
282
* @param[in] engine Pointer to the TransactionalStorageEngine resource
283
* @param[in] resource_manager Pointer to the XaResourceManager resource manager
285
void registerResourceForStatement(Session::reference session,
286
plugin::MonitoredInTransaction *monitored,
287
plugin::TransactionalStorageEngine *engine,
288
plugin::XaResourceManager *resource_manager);
291
* Registers a resource manager in the "normal" transaction.
295
* This method is idempotent and must be idempotent
296
* because it can be called both by the above
297
* TransactionServices::registerResourceForStatement(),
298
* which occurs at the beginning of each SQL statement,
299
* and also manually when a BEGIN WORK/START TRANSACTION
300
* statement is executed. If the latter case (BEGIN WORK)
301
* is called, then subsequent contained statement transactions
302
* will call this method as well.
306
* This method checks to see if the supplied resource
307
* is also registered in the statement transaction, and
308
* if not, registers the resource in the statement
309
* transaction. This happens ONLY when the user has
310
* called BEGIN WORK/START TRANSACTION, which is the only
311
* time when this method is called except from the
312
* TransactionServices::registerResourceForStatement method.
314
void registerResourceForTransaction(Session::reference session,
315
plugin::MonitoredInTransaction *monitored,
316
plugin::TransactionalStorageEngine *engine);
318
void registerResourceForTransaction(Session::reference session,
319
plugin::MonitoredInTransaction *monitored,
320
plugin::TransactionalStorageEngine *engine,
321
plugin::XaResourceManager *resource_manager);
323
void allocateNewTransactionId();
330
* Send server startup event.
332
* @param session Session object
334
* @retval true Success
335
* @retval false Failure
337
bool sendStartupEvent(Session::reference session);
340
* Send server shutdown event.
342
* @param session Session object
344
* @retval true Success
345
* @retval false Failure
347
bool sendShutdownEvent(Session::reference session);
352
* Method which returns the active Transaction message
353
* for the supplied Session. If one is not found, a new Transaction
354
* message is allocated, initialized, and returned. It is possible that
355
* we may want to NOT increment the transaction id for a new Transaction
356
* object (e.g., splitting up Transactions into smaller chunks). The
357
* should_inc_trx_id flag controls if we do this.
359
* @param session The Session object processing the transaction
360
* @param should_inc_trx_id If true, increments the transaction id for a new trx
362
message::Transaction *getActiveTransactionMessage(Session::reference session,
363
bool should_inc_trx_id= true);
366
* Method which attaches a transaction context
367
* the supplied transaction based on the supplied Session's
368
* transaction information. This method also ensure the
369
* transaction message is attached properly to the Session object
371
* @param transaction The transaction message to initialize
372
* @param session The Session object processing this transaction
373
* @param should_inc_trx_id If true, increments the transaction id for a new trx
375
void initTransactionMessage(message::Transaction &transaction,
376
Session::reference session,
377
bool should_inc_trx_id);
380
* Helper method which initializes a Statement message
382
* @param statement The statement to initialize
383
* @param type The type of the statement
384
* @param session The Session object processing this statement
386
void initStatementMessage(message::Statement &statement,
387
message::Statement::Type type,
388
Session::const_reference session);
391
* Helper method which finalizes data members for the
392
* supplied transaction's context.
394
* @param transaction The transaction message to finalize
395
* @param session The Session object processing this transaction
397
void finalizeTransactionMessage(message::Transaction &transaction,
398
Session::const_reference session);
401
* Helper method which deletes transaction memory and
402
* unsets Session's transaction and statement messages.
404
void cleanupTransactionMessage(message::Transaction *transaction,
405
Session::reference session);
407
/** Helper method which returns an initialized Statement message for methods
408
* doing insertion of data.
410
* @param[in] session Session object doing the processing
411
* @param[in] table Table object being inserted into
412
* @param[out] next_segment_id The next Statement segment id to be used
414
message::Statement &getInsertStatement(Session::reference session,
416
uint32_t *next_segment_id);
419
* Helper method which initializes the header message for
422
* @param[in,out] statement Statement message container to modify
423
* @param[in] session Session object doing the processing
424
* @param[in] table Table object being inserted into
426
void setInsertHeader(message::Statement &statement,
427
Session::const_reference session,
430
* Helper method which returns an initialized Statement
431
* message for methods doing updates of data.
433
* @param[in] session Session object doing the processing
434
* @param[in] table Table object being updated
435
* @param[in] old_record Pointer to the old data in the record
436
* @param[in] new_record Pointer to the new data in the record
437
* @param[out] next_segment_id The next Statement segment id to be used
439
message::Statement &getUpdateStatement(Session::reference session,
441
const unsigned char *old_record,
442
const unsigned char *new_record,
443
uint32_t *next_segment_id);
445
* Helper method which initializes the header message for
448
* @param[in,out] statement Statement message container to modify
449
* @param[in] session Session object doing the processing
450
* @param[in] table Table object being updated
451
* @param[in] old_record Pointer to the old data in the record
452
* @param[in] new_record Pointer to the new data in the record
454
void setUpdateHeader(message::Statement &statement,
455
Session::const_reference session,
457
const unsigned char *old_record,
458
const unsigned char *new_record);
461
* Helper method which returns an initialized Statement
462
* message for methods doing deletion of data.
464
* @param[in] session Session object doing the processing
465
* @param[in] table Table object being deleted from
466
* @param[out] next_segment_id The next Statement segment id to be used
468
message::Statement &getDeleteStatement(Session::reference session,
470
uint32_t *next_segment_id);
473
* Helper method which initializes the header message for
476
* @param[in,out] statement Statement message container to modify
477
* @param[in] session Session object doing the processing
478
* @param[in] table Table object being deleted from
480
void setDeleteHeader(message::Statement &statement,
481
Session::const_reference session,
485
* Commits a normal transaction (see above) and pushes the transaction
486
* message out to the replicators.
488
* @param session Session object committing the transaction
490
int commitTransactionMessage(Session::reference session);
493
* Marks the current active transaction message as being rolled back and
494
* pushes the transaction message out to replicators.
496
* @param session Session object committing the transaction
498
void rollbackTransactionMessage(Session::reference session);
501
* Rolls back the current statement, deleting the last Statement out of
502
* the current Transaction message.
504
* @param session Session object committing the transaction
506
* @note This depends on having clear statement boundaries (i.e., one
507
* Statement message per actual SQL statement).
509
void rollbackStatementMessage(Session::reference session);
512
* Checks if a field has been updated
514
* @param current_field Pointer to the field to check if it is updated
515
* @param table Table object containing update information
516
* @param old_record Pointer to the raw bytes representing the old record/row
517
* @param new_record Pointer to the raw bytes representing the new record/row
519
bool isFieldUpdated(Field *current_field,
521
const unsigned char *old_record,
522
const unsigned char *new_record);
525
* Create a Transaction that contains event information and send it off.
527
* This differs from other uses of Transaction in that we don't use the
528
* message associated with Session. We create a totally new message and
531
* @param session Session object
532
* @param event Event message to send
534
* @note Used by the public Events API.
536
* @returns Non-zero on error
538
int sendEvent(Session::reference session, const message::Event &event);
541
* Makes a given Transaction message segmented.
543
* The given Transaction message will have its segment information set
544
* appropriately and a new Transaction message, containing the same
545
* transaction ID as the supplied Transaction, and is created.
547
* @param session Session object
548
* @param transaction Transaction message to segment.
550
* @returns Returns a pointer to a new Transaction message ready for use.
552
message::Transaction *segmentTransactionMessage(Session::reference session,
553
message::Transaction *transaction);
555
int commitPhaseOne(Session::reference session, bool all);
557
uint64_t getCurrentTransactionId(Session::reference session);
559
plugin::XaStorageEngine *xa_storage_engine;
69
int ha_rollback_to_savepoint(Session *session, NamedSavepoint &sv);
70
int ha_savepoint(Session *session, NamedSavepoint &sv);
71
int ha_release_savepoint(Session *session, NamedSavepoint &sv);
72
bool mysql_xa_recover(Session *session);
74
/* these are called by storage engines */
75
void trans_register_ha(Session *session, bool all, plugin::TransactionalStorageEngine *engine);
562
78
} /* namespace drizzled */