76
77
* Transaction and Statement messages, false otherwise.
78
79
bool shouldConstructMessages();
81
* Method which returns the active Transaction message
82
* for the supplied Session. If one is not found, a new Transaction
83
* message is allocated, initialized, and returned.
85
* @param The session processing the transaction
87
message::Transaction *getActiveTransactionMessage(Session *in_session);
89
* Method which attaches a transaction context
90
* the supplied transaction based on the supplied Session's
91
* transaction information. This method also ensure the
92
* transaction message is attached properly to the Session object
94
* @param The transaction message to initialize
95
* @param The Session processing this transaction
97
void initTransactionMessage(message::Transaction &in_transaction, Session *in_session);
99
* Helper method which finalizes data members for the
100
* supplied transaction's context.
102
* @param The transaction message to finalize
103
* @param The Session processing this transaction
105
void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
107
* Helper method which deletes transaction memory and
108
* unsets Session's transaction and statement messages.
110
void cleanupTransactionMessage(message::Transaction *in_transaction,
111
Session *in_session);
113
* Helper method which initializes a Statement message
115
* @param The statement to initialize
116
* @param The type of the statement
117
* @param The session processing this statement
119
void initStatementMessage(message::Statement &statement,
120
message::Statement::Type in_type,
121
Session *in_session);
81
123
* Finalizes a Statement message and sets the Session's statement
82
124
* message to NULL.
84
* @param statement The statement to initialize
85
* @param session The Session object processing this statement
126
* @param The statement to initialize
127
* @param The session processing this statement
87
129
void finalizeStatementMessage(message::Statement &statement,
88
Session::reference session);
130
Session *in_session);
131
/** Helper method which returns an initialized Statement message for methods
132
* doing insertion of data.
134
* @param[in] Pointer to the Session doing the processing
135
* @param[in] Pointer to the Table object being inserted into
137
message::Statement &getInsertStatement(Session *in_session,
141
* Helper method which initializes the header message for
144
* @param[inout] Statement message container to modify
145
* @param[in] Pointer to the Session doing the processing
146
* @param[in] Pointer to the Table being inserted into
148
void setInsertHeader(message::Statement &statement,
152
* Helper method which returns an initialized Statement
153
* message for methods doing updates of data.
155
* @param[in] Pointer to the Session doing the processing
156
* @param[in] Pointer to the Table object 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
message::Statement &getUpdateStatement(Session *in_session,
162
const unsigned char *old_record,
163
const unsigned char *new_record);
165
* Helper method which initializes the header message for
168
* @param[inout] Statement message container to modify
169
* @param[in] Pointer to the Session doing the processing
170
* @param[in] Pointer to the Table being updated
171
* @param[in] Pointer to the old data in the record
172
* @param[in] Pointer to the new data in the record
174
void setUpdateHeader(message::Statement &statement,
177
const unsigned char *old_record,
178
const unsigned char *new_record);
180
* Helper method which returns an initialized Statement
181
* message for methods doing deletion of data.
183
* @param[in] Pointer to the Session doing the processing
184
* @param[in] Pointer to the Table object being deleted from
186
message::Statement &getDeleteStatement(Session *in_session,
190
* Helper method which initializes the header message for
193
* @param[inout] Statement message container to modify
194
* @param[in] Pointer to the Session doing the processing
195
* @param[in] Pointer to the Table being deleted from
197
void setDeleteHeader(message::Statement &statement,
201
* Commits a normal transaction (see above) and pushes the transaction
202
* message out to the replicators.
204
* @param Pointer to the Session committing the transaction
206
int commitTransactionMessage(Session *in_session);
208
* Marks the current active transaction message as being rolled back and
209
* pushes the transaction message out to replicators.
211
* @param Pointer to the Session committing the transaction
213
void rollbackTransactionMessage(Session *in_session);
91
215
* Creates a new InsertRecord GPB message and pushes it to
94
* @param session Session object which has inserted a record
95
* @param table Table object containing insert information
218
* @param Pointer to the Session which has inserted a record
219
* @param Pointer to the Table containing insert information
97
221
* Grr, returning "true" here on error because of the cursor
98
222
* reversed bool return crap...fix that.
100
bool insertRecord(Session::reference session, Table &in_table);
224
bool insertRecord(Session *in_session, Table *in_table);
103
226
* Creates a new UpdateRecord GPB message and pushes it to
106
* @param session Session object which has updated a record
107
* @param table Table object containing update information
108
* @param old_record Pointer to the raw bytes representing the old record/row
109
* @param new_record Pointer to the raw bytes representing the new record/row
229
* @param Pointer to the Session which has updated a record
230
* @param Pointer to the Table containing update information
231
* @param Pointer to the raw bytes representing the old record/row
232
* @param Pointer to the raw bytes representing the new record/row
111
void updateRecord(Session::reference session,
234
void updateRecord(Session *in_session,
113
236
const unsigned char *old_record,
114
237
const unsigned char *new_record);
117
239
* Creates a new DeleteRecord GPB message and pushes it to
120
* @param session Session object which has deleted a record
121
* @param table Table object containing delete information
122
* @param use_update_record If true, uses the values from the update row instead
242
* @param Pointer to the Session which has deleted a record
243
* @param Pointer to the Table containing delete information
124
void deleteRecord(Session::reference session,
126
bool use_update_record= false);
245
void deleteRecord(Session *in_session, Table *in_table);
129
247
* Creates a CreateSchema Statement GPB message and adds it
130
248
* to the Session's active Transaction GPB message for pushing
131
249
* out to the replicator streams.
133
* @param[in] session Session object which issued the statement
134
* @param[in] schema message::Schema message describing new schema
251
* @param[in] Pointer to the Session which issued the statement
252
* @param[in] message::Schema message describing new schema
136
void createSchema(Session::reference session, const message::Schema &schema);
254
void createSchema(Session *in_session, const message::Schema &schema);
139
256
* Creates a DropSchema Statement GPB message and adds it
140
257
* to the Session's active Transaction GPB message for pushing
141
258
* out to the replicator streams.
143
* @param[in] session Session object which issued the statement
144
* @param[in] identifier Identifier for the schema to drop
146
void dropSchema(Session::reference session,
147
identifier::Schema::const_reference identifier,
148
message::schema::const_reference schema);
151
* Creates an AlterSchema Statement GPB message and adds it
152
* to the Session's active Transaction GPB message for pushing
153
* out to the replicator streams.
155
* @param[in] session Session object which issued the statement
156
* @param[in] old_schema Original schema definition
157
* @param[in] new_schema New schema definition
159
void alterSchema(Session::reference session,
160
const message::Schema &old_schema,
161
const message::Schema &new_schema);
260
* @param[in] Pointer to the Session which issued the statement
261
* @param[in] message::Schema message describing new schema
263
void dropSchema(Session *in_session, const std::string &schema_name);
164
265
* Creates a CreateTable Statement GPB message and adds it
165
266
* to the Session's active Transaction GPB message for pushing
166
267
* out to the replicator streams.
168
* @param[in] session Session object which issued the statement
169
* @param[in] table message::Table message describing new schema
269
* @param[in] Pointer to the Session which issued the statement
270
* @param[in] message::Table message describing new schema
171
void createTable(Session::reference session, const message::Table &table);
272
void createTable(Session *in_session, const message::Table &table);
174
274
* Creates a DropTable Statement GPB message and adds it
175
275
* to the Session's active Transaction GPB message for pushing
176
276
* out to the replicator streams.
178
* @param[in] session Session object which issued the statement
179
* @param[in] table Identifier for the table being dropped
180
* @param[in] if_exists Did the user specify an IF EXISTS clause?
278
* @param[in] Pointer to the Session which issued the statement
279
* @param[in] The schema of the table being dropped
280
* @param[in] The table name of the table being dropped
281
* @param[in] Did the user specify an IF EXISTS clause?
182
void dropTable(Session::reference session,
183
identifier::Table::const_reference identifier,
184
message::table::const_reference table,
283
void dropTable(Session *in_session,
284
const std::string &schema_name,
285
const std::string &table_name,
188
288
* Creates a TruncateTable Statement GPB message and adds it
189
289
* to the Session's active Transaction GPB message for pushing
190
290
* out to the replicator streams.
192
* @param[in] session Session object which issued the statement
193
* @param[in] table The Table being truncated
292
* @param[in] Pointer to the Session which issued the statement
293
* @param[in] The Table being truncated
195
void truncateTable(Session::reference session, Table &table);
295
void truncateTable(Session *in_session, Table *in_table);
198
297
* Creates a new RawSql GPB message and pushes it to
203
302
* on the I_S, etc. Not sure what to do with administrative
204
303
* commands like CHECK TABLE, though..
206
* @param session Session object which issued the statement
207
* @param query Query string
305
* @param Pointer to the Session which issued the statement
306
* @param Query string
209
void rawStatement(Session::reference session, const std::string &query);
308
void rawStatement(Session *in_session, const std::string &query);
211
309
/* transactions: interface to plugin::StorageEngine functions */
212
int rollbackTransaction(Session::reference session, bool all);
215
* Commit the current transaction.
218
* @retval 1 transaction was rolled back
219
* @retval 2 error during commit, data may be inconsistent
222
* Since we don't support nested statement transactions in 5.0,
223
* we can't commit or rollback stmt transactions while we are inside
224
* stored functions or triggers. So we simply do nothing now.
225
* This should be fixed in later ( >= 5.1) releases.
227
int commitTransaction(Session::reference session, bool all);
230
* This is used to commit or rollback a single statement depending on
231
* the value of error.
234
* Note that if the autocommit is on, then the following call inside
235
* InnoDB will commit or rollback the whole transaction (= the statement). The
236
* autocommit mechanism built into InnoDB is based on counting locks, but if
237
* the user has used LOCK TABLES then that mechanism does not know to do the
240
int autocommitOrRollback(Session::reference session, int error);
310
int commitPhaseOne(Session *session, bool all);
311
int rollbackTransaction(Session *session, bool all);
313
/* transactions: these functions never call plugin::StorageEngine functions directly */
314
int commitTransaction(Session *session, bool all);
315
int autocommitOrRollback(Session *session, int error);
243
int rollbackToSavepoint(Session::reference session, NamedSavepoint &sv);
244
int setSavepoint(Session::reference session, NamedSavepoint &sv);
245
int releaseSavepoint(Session::reference session, NamedSavepoint &sv);
318
int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
319
int setSavepoint(Session *session, NamedSavepoint &sv);
320
int releaseSavepoint(Session *session, NamedSavepoint &sv);
248
323
* Marks a storage engine as participating in a statement
314
389
* time when this method is called except from the
315
390
* TransactionServices::registerResourceForStatement method.
317
void registerResourceForTransaction(Session::reference session,
392
void registerResourceForTransaction(Session *session,
318
393
plugin::MonitoredInTransaction *monitored,
319
394
plugin::TransactionalStorageEngine *engine);
321
void registerResourceForTransaction(Session::reference session,
395
void registerResourceForTransaction(Session *session,
322
396
plugin::MonitoredInTransaction *monitored,
323
397
plugin::TransactionalStorageEngine *engine,
324
398
plugin::XaResourceManager *resource_manager);
326
void allocateNewTransactionId();
333
* Send server startup event.
335
* @param session Session object
337
* @retval true Success
338
* @retval false Failure
340
bool sendStartupEvent(Session::reference session);
343
* Send server shutdown event.
345
* @param session Session object
347
* @retval true Success
348
* @retval false Failure
350
bool sendShutdownEvent(Session::reference session);
399
TransactionId getNextTransactionId()
401
return current_transaction_id.increment();
403
TransactionId getCurrentTransactionId()
405
return current_transaction_id;
408
* DEBUG ONLY. See plugin::TransactionLog::truncate()
410
void resetTransactionId()
412
current_transaction_id= 0;
355
* Method which returns the active Transaction message
356
* for the supplied Session. If one is not found, a new Transaction
357
* message is allocated, initialized, and returned. It is possible that
358
* we may want to NOT increment the transaction id for a new Transaction
359
* object (e.g., splitting up Transactions into smaller chunks). The
360
* should_inc_trx_id flag controls if we do this.
362
* @param session The Session object processing the transaction
363
* @param should_inc_trx_id If true, increments the transaction id for a new trx
365
message::Transaction *getActiveTransactionMessage(Session::reference session,
366
bool should_inc_trx_id= true);
369
* Method which attaches a transaction context
370
* the supplied transaction based on the supplied Session's
371
* transaction information. This method also ensure the
372
* transaction message is attached properly to the Session object
374
* @param transaction The transaction message to initialize
375
* @param session The Session object processing this transaction
376
* @param should_inc_trx_id If true, increments the transaction id for a new trx
378
void initTransactionMessage(message::Transaction &transaction,
379
Session::reference session,
380
bool should_inc_trx_id);
383
* Helper method which initializes a Statement message
385
* @param statement The statement to initialize
386
* @param type The type of the statement
387
* @param session The Session object processing this statement
389
void initStatementMessage(message::Statement &statement,
390
message::Statement::Type type,
391
Session::const_reference session);
394
* Helper method which finalizes data members for the
395
* supplied transaction's context.
397
* @param transaction The transaction message to finalize
398
* @param session The Session object processing this transaction
400
void finalizeTransactionMessage(message::Transaction &transaction,
401
Session::const_reference session);
404
* Helper method which deletes transaction memory and
405
* unsets Session's transaction and statement messages.
407
void cleanupTransactionMessage(message::Transaction *transaction,
408
Session::reference session);
410
/** Helper method which returns an initialized Statement message for methods
411
* doing insertion of data.
413
* @param[in] session Session object doing the processing
414
* @param[in] table Table object being inserted into
415
* @param[out] next_segment_id The next Statement segment id to be used
417
message::Statement &getInsertStatement(Session::reference session,
419
uint32_t *next_segment_id);
422
* Helper method which initializes the header message for
425
* @param[in,out] statement Statement message container to modify
426
* @param[in] session Session object doing the processing
427
* @param[in] table Table object being inserted into
429
void setInsertHeader(message::Statement &statement,
430
Session::const_reference session,
433
* Helper method which returns an initialized Statement
434
* message for methods doing updates of data.
436
* @param[in] session Session object doing the processing
437
* @param[in] table Table object being updated
438
* @param[in] old_record Pointer to the old data in the record
439
* @param[in] new_record Pointer to the new data in the record
440
* @param[out] next_segment_id The next Statement segment id to be used
442
message::Statement &getUpdateStatement(Session::reference session,
444
const unsigned char *old_record,
445
const unsigned char *new_record,
446
uint32_t *next_segment_id);
448
* Helper method which initializes the header message for
451
* @param[in,out] statement Statement message container to modify
452
* @param[in] session Session object doing the processing
453
* @param[in] table Table object being updated
454
* @param[in] old_record Pointer to the old data in the record
455
* @param[in] new_record Pointer to the new data in the record
457
void setUpdateHeader(message::Statement &statement,
458
Session::const_reference session,
460
const unsigned char *old_record,
461
const unsigned char *new_record);
464
* Helper method which returns an initialized Statement
465
* message for methods doing deletion of data.
467
* @param[in] session Session object doing the processing
468
* @param[in] table Table object being deleted from
469
* @param[out] next_segment_id The next Statement segment id to be used
471
message::Statement &getDeleteStatement(Session::reference session,
473
uint32_t *next_segment_id);
476
* Helper method which initializes the header message for
479
* @param[in,out] statement Statement message container to modify
480
* @param[in] session Session object doing the processing
481
* @param[in] table Table object being deleted from
483
void setDeleteHeader(message::Statement &statement,
484
Session::const_reference session,
488
* Commits a normal transaction (see above) and pushes the transaction
489
* message out to the replicators.
491
* @param session Session object committing the transaction
493
int commitTransactionMessage(Session::reference session);
496
* Marks the current active transaction message as being rolled back and
497
* pushes the transaction message out to replicators.
499
* @param session Session object committing the transaction
501
void rollbackTransactionMessage(Session::reference session);
504
* Rolls back the current statement, deleting the last Statement out of
505
* the current Transaction message.
507
* @param session Session object committing the transaction
509
* @note This depends on having clear statement boundaries (i.e., one
510
* Statement message per actual SQL statement).
512
void rollbackStatementMessage(Session::reference session);
515
* Checks if a field has been updated
517
* @param current_field Pointer to the field to check if it is updated
518
* @param table Table object containing update information
519
* @param old_record Pointer to the raw bytes representing the old record/row
520
* @param new_record Pointer to the raw bytes representing the new record/row
522
bool isFieldUpdated(Field *current_field,
524
const unsigned char *old_record,
525
const unsigned char *new_record);
528
* Create a Transaction that contains event information and send it off.
530
* This differs from other uses of Transaction in that we don't use the
531
* message associated with Session. We create a totally new message and
534
* @param session Session object
535
* @param event Event message to send
537
* @note Used by the public Events API.
539
* @returns Non-zero on error
541
int sendEvent(Session::reference session, const message::Event &event);
544
* Makes a given Transaction message segmented.
546
* The given Transaction message will have its segment information set
547
* appropriately and a new Transaction message, containing the same
548
* transaction ID as the supplied Transaction, and is created.
550
* @param session Session object
551
* @param transaction Transaction message to segment.
553
* @returns Returns a pointer to a new Transaction message ready for use.
555
message::Transaction *segmentTransactionMessage(Session::reference session,
556
message::Transaction *transaction);
558
int commitPhaseOne(Session::reference session, bool all);
560
uint64_t getCurrentTransactionId(Session::reference session);
562
plugin::XaStorageEngine *xa_storage_engine;
415
atomic<TransactionId> current_transaction_id;
565
418
} /* namespace drizzled */