25
25
#ifndef DRIZZLED_TRANSACTION_SERVICES_H
26
26
#define DRIZZLED_TRANSACTION_SERVICES_H
28
#include <drizzled/atomics.h>
29
#include <drizzled/message/transaction.pb.h>
30
#include <drizzled/identifier/table.h>
31
#include <drizzled/identifier/schema.h>
32
#include <drizzled/message/schema.h>
33
#include <drizzled/session.h>
35
#include <drizzled/visibility.h>
28
#include "drizzled/atomics.h"
29
#include "drizzled/message/transaction.pb.h"
30
#include "drizzled/identifier/table.h"
31
#include "drizzled/message/schema.h"
84
80
* @param statement The statement to initialize
85
* @param session The Session object processing this statement
81
* @param in_session The session processing this statement
87
83
void finalizeStatementMessage(message::Statement &statement,
88
Session::reference session);
91
87
* 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
90
* @param in_session Pointer to the Session which has inserted a record
91
* @param in_table Pointer to the Table containing insert information
97
93
* Grr, returning "true" here on error because of the cursor
98
94
* reversed bool return crap...fix that.
100
bool insertRecord(Session::reference session, Table &in_table);
96
bool insertRecord(Session *in_session, Table *in_table);
103
99
* 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
102
* @param in_session Pointer to the Session which has updated a record
103
* @param in_table Pointer to the Table containing update information
108
104
* @param old_record Pointer to the raw bytes representing the old record/row
109
105
* @param new_record Pointer to the raw bytes representing the new record/row
111
void updateRecord(Session::reference session,
107
void updateRecord(Session *in_session,
113
109
const unsigned char *old_record,
114
110
const unsigned char *new_record);
117
113
* 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
116
* @param in_session Pointer to the Session which has deleted a record
117
* @param in_table Pointer to the Table containing delete information
122
118
* @param use_update_record If true, uses the values from the update row instead
124
void deleteRecord(Session::reference session,
126
bool use_update_record= false);
120
void deleteRecord(Session *in_session, Table *in_table, bool use_update_record= false);
129
123
* Creates a CreateSchema Statement GPB message and adds it
130
124
* to the Session's active Transaction GPB message for pushing
131
125
* out to the replicator streams.
133
* @param[in] session Session object which issued the statement
127
* @param[in] in_session Pointer to the Session which issued the statement
134
128
* @param[in] schema message::Schema message describing new schema
136
void createSchema(Session::reference session, const message::Schema &schema);
130
void createSchema(Session *in_session, const message::Schema &schema);
139
133
* Creates a DropSchema Statement GPB message and adds it
140
134
* to the Session's active Transaction GPB message for pushing
141
135
* out to the replicator streams.
143
* @param[in] session Session object which issued the statement
137
* @param[in] in_session Pointer to the Session which issued the statement
144
138
* @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);
140
void dropSchema(Session *in_session, identifier::Schema::const_reference identifier);
151
143
* Creates an AlterSchema Statement GPB message and adds it
152
144
* to the Session's active Transaction GPB message for pushing
153
145
* out to the replicator streams.
155
* @param[in] session Session object which issued the statement
147
* @param[in] in_session Pointer to the Session which issued the statement
156
148
* @param[in] old_schema Original schema definition
157
149
* @param[in] new_schema New schema definition
159
void alterSchema(Session::reference session,
160
const message::Schema &old_schema,
151
void alterSchema(Session *in_session,
152
const message::schema::shared_ptr &old_schema,
161
153
const message::Schema &new_schema);
165
157
* to the Session's active Transaction GPB message for pushing
166
158
* out to the replicator streams.
168
* @param[in] session Session object which issued the statement
160
* @param[in] in_session Pointer to the Session which issued the statement
169
161
* @param[in] table message::Table message describing new schema
171
void createTable(Session::reference session, const message::Table &table);
163
void createTable(Session *in_session, const message::Table &table);
174
166
* Creates a DropTable Statement GPB message and adds it
175
167
* to the Session's active Transaction GPB message for pushing
176
168
* out to the replicator streams.
178
* @param[in] session Session object which issued the statement
170
* @param[in] in_session Pointer to the Session which issued the statement
179
171
* @param[in] table Identifier for the table being dropped
180
172
* @param[in] if_exists 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,
174
void dropTable(Session *in_session,
175
const identifier::Table &table,
189
180
* to the Session's active Transaction GPB message for pushing
190
181
* out to the replicator streams.
192
* @param[in] session Session object which issued the statement
193
* @param[in] table The Table being truncated
183
* @param[in] in_session Pointer to the Session which issued the statement
184
* @param[in] in_table The Table being truncated
195
void truncateTable(Session::reference session, Table &table);
186
void truncateTable(Session *in_session, Table *in_table);
198
189
* Creates a new RawSql GPB message and pushes it to
203
194
* on the I_S, etc. Not sure what to do with administrative
204
195
* commands like CHECK TABLE, though..
206
* @param session Session object which issued the statement
197
* @param in_session Pointer to the Session which issued the statement
207
198
* @param query Query string
209
void rawStatement(Session::reference session, const std::string &query);
200
void rawStatement(Session *in_session, const std::string &query);
211
202
/* 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);
203
int rollbackTransaction(Session *session, bool all);
205
/* transactions: these functions never call plugin::StorageEngine functions directly */
206
int commitTransaction(Session *session, bool all);
207
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);
210
int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
211
int setSavepoint(Session *session, NamedSavepoint &sv);
212
int releaseSavepoint(Session *session, NamedSavepoint &sv);
248
215
* Marks a storage engine as participating in a statement
258
225
* per statement, and therefore should not need to be idempotent.
259
226
* Put in assert()s to test this.
261
* @param[in] session Session object
228
* @param[in] session Session pointer
262
229
* @param[in] monitored Descriptor for the resource which will be participating
263
230
* @param[in] engine Pointer to the TransactionalStorageEngine resource
265
void registerResourceForStatement(Session::reference session,
232
void registerResourceForStatement(Session *session,
266
233
plugin::MonitoredInTransaction *monitored,
267
234
plugin::TransactionalStorageEngine *engine);
280
247
* per statement, and therefore should not need to be idempotent.
281
248
* Put in assert()s to test this.
283
* @param[in] session Session object
250
* @param[in] session Session pointer
284
251
* @param[in] monitored Descriptor for the resource which will be participating
285
252
* @param[in] engine Pointer to the TransactionalStorageEngine resource
286
253
* @param[in] resource_manager Pointer to the XaResourceManager resource manager
288
void registerResourceForStatement(Session::reference session,
255
void registerResourceForStatement(Session *session,
289
256
plugin::MonitoredInTransaction *monitored,
290
257
plugin::TransactionalStorageEngine *engine,
291
258
plugin::XaResourceManager *resource_manager);
314
281
* time when this method is called except from the
315
282
* TransactionServices::registerResourceForStatement method.
317
void registerResourceForTransaction(Session::reference session,
284
void registerResourceForTransaction(Session *session,
318
285
plugin::MonitoredInTransaction *monitored,
319
286
plugin::TransactionalStorageEngine *engine);
321
void registerResourceForTransaction(Session::reference session,
288
void registerResourceForTransaction(Session *session,
322
289
plugin::MonitoredInTransaction *monitored,
323
290
plugin::TransactionalStorageEngine *engine,
324
291
plugin::XaResourceManager *resource_manager);
333
300
* Send server startup event.
335
* @param session Session object
302
* @param session Session pointer
337
304
* @retval true Success
338
305
* @retval false Failure
340
bool sendStartupEvent(Session::reference session);
307
bool sendStartupEvent(Session *session);
343
310
* Send server shutdown event.
345
* @param session Session object
312
* @param session Session pointer
347
314
* @retval true Success
348
315
* @retval false Failure
350
bool sendShutdownEvent(Session::reference session);
317
bool sendShutdownEvent(Session *session);
359
326
* object (e.g., splitting up Transactions into smaller chunks). The
360
327
* should_inc_trx_id flag controls if we do this.
362
* @param session The Session object processing the transaction
329
* @param in_session The session processing the transaction
363
330
* @param should_inc_trx_id If true, increments the transaction id for a new trx
365
message::Transaction *getActiveTransactionMessage(Session::reference session,
332
message::Transaction *getActiveTransactionMessage(Session *in_session,
366
333
bool should_inc_trx_id= true);
371
338
* transaction information. This method also ensure the
372
339
* 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
341
* @param in_transaction The transaction message to initialize
342
* @param in_session The Session processing this transaction
376
343
* @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,
345
void initTransactionMessage(message::Transaction &in_transaction,
380
347
bool should_inc_trx_id);
383
350
* Helper method which initializes a Statement message
385
352
* @param statement The statement to initialize
386
* @param type The type of the statement
387
* @param session The Session object processing this statement
353
* @param in_type The type of the statement
354
* @param in_session The session processing this statement
389
356
void initStatementMessage(message::Statement &statement,
390
message::Statement::Type type,
391
Session::const_reference session);
357
message::Statement::Type in_type,
358
Session *in_session);
394
361
* Helper method which finalizes data members for the
395
362
* supplied transaction's context.
397
* @param transaction The transaction message to finalize
398
* @param session The Session object processing this transaction
364
* @param in_transaction The transaction message to finalize
365
* @param in_session The Session processing this transaction
400
void finalizeTransactionMessage(message::Transaction &transaction,
401
Session::const_reference session);
367
void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
404
370
* Helper method which deletes transaction memory and
405
371
* unsets Session's transaction and statement messages.
407
void cleanupTransactionMessage(message::Transaction *transaction,
408
Session::reference session);
373
void cleanupTransactionMessage(message::Transaction *in_transaction,
374
Session *in_session);
410
376
/** Helper method which returns an initialized Statement message for methods
411
377
* doing insertion of data.
413
* @param[in] session Session object doing the processing
414
* @param[in] table Table object being inserted into
379
* @param[in] in_session Pointer to the Session doing the processing
380
* @param[in] in_table Pointer to the Table object being inserted into
415
381
* @param[out] next_segment_id The next Statement segment id to be used
417
message::Statement &getInsertStatement(Session::reference session,
383
message::Statement &getInsertStatement(Session *in_session,
419
385
uint32_t *next_segment_id);
423
389
* insert operations.
425
391
* @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
392
* @param[in] in_session Pointer to the Session doing the processing
393
* @param[in] in_table Pointer to the Table being inserted into
429
395
void setInsertHeader(message::Statement &statement,
430
Session::const_reference session,
433
399
* Helper method which returns an initialized Statement
434
400
* message for methods doing updates of data.
436
* @param[in] session Session object doing the processing
437
* @param[in] table Table object being updated
402
* @param[in] in_session Pointer to the Session doing the processing
403
* @param[in] in_table Pointer to the Table object being updated
438
404
* @param[in] old_record Pointer to the old data in the record
439
405
* @param[in] new_record Pointer to the new data in the record
440
406
* @param[out] next_segment_id The next Statement segment id to be used
442
message::Statement &getUpdateStatement(Session::reference session,
408
message::Statement &getUpdateStatement(Session *in_session,
444
410
const unsigned char *old_record,
445
411
const unsigned char *new_record,
446
412
uint32_t *next_segment_id);
449
415
* update operations.
451
417
* @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
418
* @param[in] in_session Pointer to the Session doing the processing
419
* @param[in] in_table Pointer to the Table being updated
454
420
* @param[in] old_record Pointer to the old data in the record
455
421
* @param[in] new_record Pointer to the new data in the record
457
423
void setUpdateHeader(message::Statement &statement,
458
Session::const_reference session,
460
426
const unsigned char *old_record,
461
427
const unsigned char *new_record);
464
430
* Helper method which returns an initialized Statement
465
431
* 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
433
* @param[in] in_session Pointer to the Session doing the processing
434
* @param[in] in_table Pointer to the Table object being deleted from
469
435
* @param[out] next_segment_id The next Statement segment id to be used
471
message::Statement &getDeleteStatement(Session::reference session,
437
message::Statement &getDeleteStatement(Session *in_session,
473
439
uint32_t *next_segment_id);
477
443
* insert operations.
479
445
* @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
446
* @param[in] in_session Pointer to the Session doing the processing
447
* @param[in] in_table Pointer to the Table being deleted from
483
449
void setDeleteHeader(message::Statement &statement,
484
Session::const_reference session,
488
454
* Commits a normal transaction (see above) and pushes the transaction
489
455
* message out to the replicators.
491
* @param session Session object committing the transaction
457
* @param in_session Pointer to the Session committing the transaction
493
int commitTransactionMessage(Session::reference session);
459
int commitTransactionMessage(Session *in_session);
496
462
* Marks the current active transaction message as being rolled back and
497
463
* pushes the transaction message out to replicators.
499
* @param session Session object committing the transaction
465
* @param in_session Pointer to the Session committing the transaction
501
void rollbackTransactionMessage(Session::reference session);
467
void rollbackTransactionMessage(Session *in_session);
504
470
* Rolls back the current statement, deleting the last Statement out of
505
471
* the current Transaction message.
507
* @param session Session object committing the transaction
509
473
* @note This depends on having clear statement boundaries (i.e., one
510
* Statement message per actual SQL statement).
474
* Statement message per actual SQL statement.
512
void rollbackStatementMessage(Session::reference session);
476
void rollbackStatementMessage(Session *in_session);
515
479
* Checks if a field has been updated
517
481
* @param current_field Pointer to the field to check if it is updated
518
* @param table Table object containing update information
482
* @param in_table Pointer to the Table containing update information
519
483
* @param old_record Pointer to the raw bytes representing the old record/row
520
484
* @param new_record Pointer to the raw bytes representing the new record/row
522
486
bool isFieldUpdated(Field *current_field,
524
488
const unsigned char *old_record,
525
489
const unsigned char *new_record);
531
495
* message associated with Session. We create a totally new message and
534
* @param session Session object
498
* @param session Session pointer
535
499
* @param event Event message to send
537
501
* @note Used by the public Events API.
539
503
* @returns Non-zero on error
541
int sendEvent(Session::reference session, const message::Event &event);
505
int sendEvent(Session *session, const message::Event &event);
544
508
* Makes a given Transaction message segmented.
547
511
* appropriately and a new Transaction message, containing the same
548
512
* transaction ID as the supplied Transaction, and is created.
550
* @param session Session object
551
* @param transaction Transaction message to segment.
514
* @param in_session Session pointer
515
* @param transaction Pointer to the Transaction message to segment.
553
517
* @returns Returns a pointer to a new Transaction message ready for use.
555
message::Transaction *segmentTransactionMessage(Session::reference session,
519
message::Transaction *segmentTransactionMessage(Session *in_session,
556
520
message::Transaction *transaction);
558
int commitPhaseOne(Session::reference session, bool all);
522
int commitPhaseOne(Session *session, bool all);
560
uint64_t getCurrentTransactionId(Session::reference session);
524
uint64_t getCurrentTransactionId(Session *session);
562
526
plugin::XaStorageEngine *xa_storage_engine;