~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#ifndef DRIZZLED_TRANSACTION_SERVICES_H
26
26
#define DRIZZLED_TRANSACTION_SERVICES_H
27
27
 
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>
34
 
 
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"
36
32
 
37
33
namespace drizzled
38
34
{
54
50
 * This is a class which manages the XA transaction processing
55
51
 * in the server
56
52
 */
57
 
class DRIZZLED_API TransactionServices
 
53
class TransactionServices
58
54
{
59
55
public:
60
56
  static const size_t DEFAULT_RECORD_SIZE= 100;
82
78
   * message to NULL.
83
79
   *
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
86
82
   */
87
83
  void finalizeStatementMessage(message::Statement &statement,
88
 
                                Session::reference session);
 
84
                                Session *in_session);
89
85
 
90
86
  /**
91
87
   * Creates a new InsertRecord GPB message and pushes it to
92
88
   * replicators.
93
89
   *
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
96
92
   *
97
93
   * Grr, returning "true" here on error because of the cursor
98
94
   * reversed bool return crap...fix that.
99
95
   */
100
 
  bool insertRecord(Session::reference session, Table &in_table);
 
96
  bool insertRecord(Session *in_session, Table *in_table);
101
97
 
102
98
  /**
103
99
   * Creates a new UpdateRecord GPB message and pushes it to
104
100
   * replicators.
105
101
   *
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 
110
106
   */
111
 
  void updateRecord(Session::reference session, 
112
 
                    Table &table, 
 
107
  void updateRecord(Session *in_session, 
 
108
                    Table *in_table, 
113
109
                    const unsigned char *old_record, 
114
110
                    const unsigned char *new_record);
115
111
 
117
113
   * Creates a new DeleteRecord GPB message and pushes it to
118
114
   * replicators.
119
115
   *
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
123
119
   */
124
 
  void deleteRecord(Session::reference session,
125
 
                    Table &table,
126
 
                    bool use_update_record= false);
 
120
  void deleteRecord(Session *in_session, Table *in_table, bool use_update_record= false);
127
121
 
128
122
  /**
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.
132
126
   *
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
135
129
   */
136
 
  void createSchema(Session::reference session, const message::Schema &schema);
 
130
  void createSchema(Session *in_session, const message::Schema &schema);
137
131
 
138
132
  /**
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.
142
136
   *
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
145
139
   */
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);
149
141
 
150
142
  /**
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.
154
146
   *
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
158
150
   */
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);
162
154
 
163
155
  /**
165
157
   * to the Session's active Transaction GPB message for pushing
166
158
   * out to the replicator streams.
167
159
   *
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
170
162
   */
171
 
  void createTable(Session::reference session, const message::Table &table);
 
163
  void createTable(Session *in_session, const message::Table &table);
172
164
 
173
165
  /**
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.
177
169
   *
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?
181
173
   */
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,
185
176
                 bool if_exists);
186
177
 
187
178
  /**
189
180
   * to the Session's active Transaction GPB message for pushing
190
181
   * out to the replicator streams.
191
182
   *
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
194
185
   */
195
 
  void truncateTable(Session::reference session, Table &table);
 
186
  void truncateTable(Session *in_session, Table *in_table);
196
187
 
197
188
  /**
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..
205
196
   *
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
208
199
   */
209
 
  void rawStatement(Session::reference session, const std::string &query);
 
200
  void rawStatement(Session *in_session, const std::string &query);
210
201
 
211
202
  /* transactions: interface to plugin::StorageEngine functions */
212
 
  int rollbackTransaction(Session::reference session, bool all);
213
 
 
214
 
  /**
215
 
   * Commit the current transaction.
216
 
   *
217
 
   * @retval 0 ok
218
 
   * @retval 1 transaction was rolled back
219
 
   * @retval 2 error during commit, data may be inconsistent
220
 
   *
221
 
   * @todo
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.
226
 
   */
227
 
  int commitTransaction(Session::reference session, bool all);
228
 
 
229
 
  /**
230
 
   * This is used to commit or rollback a single statement depending on
231
 
   * the value of error.
232
 
   *
233
 
   * @note
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
238
 
   * commit.
239
 
   */
240
 
  int autocommitOrRollback(Session::reference session, int error);
 
203
  int rollbackTransaction(Session *session, bool all);
 
204
 
 
205
  /* transactions: these functions never call plugin::StorageEngine functions directly */
 
206
  int commitTransaction(Session *session, bool all);
 
207
  int autocommitOrRollback(Session *session, int error);
241
208
 
242
209
  /* savepoints */
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);
246
213
 
247
214
  /**
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.
260
227
   *
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
264
231
   */
265
 
  void registerResourceForStatement(Session::reference session,
 
232
  void registerResourceForStatement(Session *session,
266
233
                                    plugin::MonitoredInTransaction *monitored,
267
234
                                    plugin::TransactionalStorageEngine *engine);
268
235
 
280
247
   * per statement, and therefore should not need to be idempotent.
281
248
   * Put in assert()s to test this.
282
249
   *
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
287
254
   */
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.
316
283
   */
317
 
  void registerResourceForTransaction(Session::reference session,
 
284
  void registerResourceForTransaction(Session *session,
318
285
                                      plugin::MonitoredInTransaction *monitored,
319
286
                                      plugin::TransactionalStorageEngine *engine);
320
287
 
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);
332
299
  /**
333
300
   * Send server startup event.
334
301
   *
335
 
   * @param session Session object
 
302
   * @param session Session pointer
336
303
   *
337
304
   * @retval true Success
338
305
   * @retval false Failure
339
306
   */
340
 
  bool sendStartupEvent(Session::reference session);
 
307
  bool sendStartupEvent(Session *session);
341
308
 
342
309
  /**
343
310
   * Send server shutdown event.
344
311
   *
345
 
   * @param session Session object
 
312
   * @param session Session pointer
346
313
   *
347
314
   * @retval true Success
348
315
   * @retval false Failure
349
316
   */
350
 
  bool sendShutdownEvent(Session::reference session);
 
317
  bool sendShutdownEvent(Session *session);
351
318
 
352
319
private:
353
320
 
359
326
   * object (e.g., splitting up Transactions into smaller chunks). The
360
327
   * should_inc_trx_id flag controls if we do this.
361
328
   *
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
364
331
   */
365
 
  message::Transaction *getActiveTransactionMessage(Session::reference session,
 
332
  message::Transaction *getActiveTransactionMessage(Session *in_session,
366
333
                                                    bool should_inc_trx_id= true);
367
334
 
368
335
  /** 
371
338
   * transaction information.  This method also ensure the
372
339
   * transaction message is attached properly to the Session object
373
340
   *
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
377
344
   */
378
 
  void initTransactionMessage(message::Transaction &transaction,
379
 
                              Session::reference session,
 
345
  void initTransactionMessage(message::Transaction &in_transaction,
 
346
                              Session *in_session,
380
347
                              bool should_inc_trx_id);
381
348
  
382
349
  /**
383
350
   * Helper method which initializes a Statement message
384
351
   *
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
388
355
   */
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);
392
359
 
393
360
  /** 
394
361
   * Helper method which finalizes data members for the 
395
362
   * supplied transaction's context.
396
363
   *
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
399
366
   */
400
 
  void finalizeTransactionMessage(message::Transaction &transaction,
401
 
                                  Session::const_reference session);
 
367
  void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
402
368
 
403
369
  /**
404
370
   * Helper method which deletes transaction memory and
405
371
   * unsets Session's transaction and statement messages.
406
372
   */
407
 
  void cleanupTransactionMessage(message::Transaction *transaction,
408
 
                                 Session::reference session);
 
373
  void cleanupTransactionMessage(message::Transaction *in_transaction,
 
374
                                 Session *in_session);
409
375
  
410
376
  /** Helper method which returns an initialized Statement message for methods
411
377
   * doing insertion of data.
412
378
   *
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
416
382
   */
417
 
  message::Statement &getInsertStatement(Session::reference session,
418
 
                                         Table &table,
 
383
  message::Statement &getInsertStatement(Session *in_session,
 
384
                                         Table *in_table,
419
385
                                         uint32_t *next_segment_id);
420
386
  
421
387
  /**
423
389
   * insert operations.
424
390
   *
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
428
394
   */
429
395
  void setInsertHeader(message::Statement &statement,
430
 
                       Session::const_reference session,
431
 
                       Table &table);
 
396
                       Session *in_session,
 
397
                       Table *in_table);
432
398
  /**
433
399
   * Helper method which returns an initialized Statement
434
400
   * message for methods doing updates of data.
435
401
   *
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
441
407
   */
442
 
  message::Statement &getUpdateStatement(Session::reference session,
443
 
                                         Table &table,
 
408
  message::Statement &getUpdateStatement(Session *in_session,
 
409
                                         Table *in_table,
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.
450
416
   *
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
456
422
   */
457
423
  void setUpdateHeader(message::Statement &statement,
458
 
                       Session::const_reference session,
459
 
                       Table &table,
 
424
                       Session *in_session,
 
425
                       Table *in_table,
460
426
                       const unsigned char *old_record, 
461
427
                       const unsigned char *new_record);
462
428
 
464
430
   * Helper method which returns an initialized Statement
465
431
   * message for methods doing deletion of data.
466
432
   *
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
470
436
   */
471
 
  message::Statement &getDeleteStatement(Session::reference session,
472
 
                                         Table &table,
 
437
  message::Statement &getDeleteStatement(Session *in_session,
 
438
                                         Table *in_table,
473
439
                                         uint32_t *next_segment_id);
474
440
  
475
441
  /**
477
443
   * insert operations.
478
444
   *
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
482
448
   */
483
449
  void setDeleteHeader(message::Statement &statement,
484
 
                       Session::const_reference session,
485
 
                       Table &table);
 
450
                       Session *in_session,
 
451
                       Table *in_table);
486
452
 
487
453
  /** 
488
454
   * Commits a normal transaction (see above) and pushes the transaction
489
455
   * message out to the replicators.
490
456
   *
491
 
   * @param session Session object committing the transaction
 
457
   * @param in_session Pointer to the Session committing the transaction
492
458
   */
493
 
  int commitTransactionMessage(Session::reference session);
 
459
  int commitTransactionMessage(Session *in_session);
494
460
 
495
461
  /** 
496
462
   * Marks the current active transaction message as being rolled back and
497
463
   * pushes the transaction message out to replicators.
498
464
   *
499
 
   * @param session Session object committing the transaction
 
465
   * @param in_session Pointer to the Session committing the transaction
500
466
   */
501
 
  void rollbackTransactionMessage(Session::reference session);
 
467
  void rollbackTransactionMessage(Session *in_session);
502
468
 
503
469
  /**
504
470
   * Rolls back the current statement, deleting the last Statement out of
505
471
   * the current Transaction message.
506
472
   *
507
 
   * @param session Session object committing the transaction
508
 
   *
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.
511
475
   */
512
 
  void rollbackStatementMessage(Session::reference session);
 
476
  void rollbackStatementMessage(Session *in_session);
513
477
 
514
478
  /**
515
479
   * Checks if a field has been updated 
516
480
   *
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
521
485
   */
522
486
  bool isFieldUpdated(Field *current_field,
523
 
                      Table &table,
 
487
                      Table *in_table,
524
488
                      const unsigned char *old_record,
525
489
                      const unsigned char *new_record);
526
490
 
531
495
   * message associated with Session. We create a totally new message and
532
496
   * use it.
533
497
   *
534
 
   * @param session Session object
 
498
   * @param session Session pointer
535
499
   * @param event Event message to send
536
500
   *
537
501
   * @note Used by the public Events API.
538
502
   *
539
503
   * @returns Non-zero on error
540
504
   */
541
 
  int sendEvent(Session::reference session, const message::Event &event);
 
505
  int sendEvent(Session *session, const message::Event &event);
542
506
 
543
507
  /**
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.
549
513
   *
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.
552
516
   *
553
517
   * @returns Returns a pointer to a new Transaction message ready for use.
554
518
   */
555
 
  message::Transaction *segmentTransactionMessage(Session::reference session,
 
519
  message::Transaction *segmentTransactionMessage(Session *in_session,
556
520
                                                  message::Transaction *transaction);
557
521
 
558
 
  int commitPhaseOne(Session::reference session, bool all);
 
522
  int commitPhaseOne(Session *session, bool all);
559
523
 
560
 
  uint64_t getCurrentTransactionId(Session::reference session);
 
524
  uint64_t getCurrentTransactionId(Session *session);
561
525
 
562
526
  plugin::XaStorageEngine *xa_storage_engine;
563
527
};