~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Lee Bieber
  • Date: 2011-01-19 01:50:26 UTC
  • mfrom: (2095.1.5 build)
  • Revision ID: kalebral@gmail.com-20110119015026-j1ukv30cz662e51e
Merge Shrews - Refactor the TransactionServices public interface
Merge Monty - fix bug 583375: support configure option to specify static/dynamic build for a plugin
Merge Shrews - fix bug 702505: transaction_reader utility does not check for errors from statement transformation
Merge Vijay - Convert structs to classes
Merge Joe - 702529: PRINT_TRANSACTION_MESSAGE udf does not output UUID

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
   * Transaction and Statement messages, false otherwise.
73
73
   */
74
74
  bool shouldConstructMessages();
75
 
  /**
76
 
   * Method which returns the active Transaction message
77
 
   * for the supplied Session.  If one is not found, a new Transaction
78
 
   * message is allocated, initialized, and returned. It is possible that
79
 
   * we may want to NOT increment the transaction id for a new Transaction
80
 
   * object (e.g., splitting up Transactions into smaller chunks). The
81
 
   * should_inc_trx_id flag controls if we do this.
82
 
   *
83
 
   * @param in_session The session processing the transaction
84
 
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
85
 
   */
86
 
  message::Transaction *getActiveTransactionMessage(Session *in_session,
87
 
                                                    bool should_inc_trx_id= true);
88
 
  /** 
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
93
 
   *
94
 
   * @param in_transaction The transaction message to initialize
95
 
   * @param in_session The Session processing this transaction
96
 
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
97
 
   */
98
 
  void initTransactionMessage(message::Transaction &in_transaction,
99
 
                              Session *in_session,
100
 
                              bool should_inc_trx_id);
101
 
  /** 
102
 
   * Helper method which finalizes data members for the 
103
 
   * supplied transaction's context.
104
 
   *
105
 
   * @param in_transaction The transaction message to finalize 
106
 
   * @param in_session The Session processing this transaction
107
 
   */
108
 
  void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
109
 
  /**
110
 
   * Helper method which deletes transaction memory and
111
 
   * unsets Session's transaction and statement messages.
112
 
   */
113
 
  void cleanupTransactionMessage(message::Transaction *in_transaction,
114
 
                                 Session *in_session);
115
75
 
116
76
  /**
117
 
   * Helper method which initializes a Statement message
118
 
   *
119
 
   * @param statement The statement to initialize
120
 
   * @param in_type The type of the statement
121
 
   * @param in_session The session processing this statement
122
 
   */
123
 
  void initStatementMessage(message::Statement &statement,
124
 
                            message::Statement::Type in_type,
125
 
                            Session *in_session);
126
 
  /**
127
77
   * Finalizes a Statement message and sets the Session's statement
128
78
   * message to NULL.
129
79
   *
132
82
   */
133
83
  void finalizeStatementMessage(message::Statement &statement,
134
84
                                Session *in_session);
135
 
  /** Helper method which returns an initialized Statement message for methods
136
 
   * doing insertion of data.
137
 
   *
138
 
   * @param[in] in_session Pointer to the Session doing the processing
139
 
   * @param[in] in_table Pointer to the Table object being inserted into
140
 
   * @param[out] next_segment_id The next Statement segment id to be used
141
 
   */
142
 
  message::Statement &getInsertStatement(Session *in_session,
143
 
                                         Table *in_table,
144
 
                                         uint32_t *next_segment_id);
145
 
 
146
 
  /**
147
 
   * Helper method which initializes the header message for
148
 
   * insert operations.
149
 
   *
150
 
   * @param[in,out] statement Statement message container to modify
151
 
   * @param[in] in_session Pointer to the Session doing the processing
152
 
   * @param[in] in_table Pointer to the Table being inserted into
153
 
   */
154
 
  void setInsertHeader(message::Statement &statement,
155
 
                       Session *in_session,
156
 
                       Table *in_table);
157
 
  /**
158
 
   * Helper method which returns an initialized Statement
159
 
   * message for methods doing updates of data.
160
 
   *
161
 
   * @param[in] in_session Pointer to the Session doing the processing
162
 
   * @param[in] in_table Pointer to the Table object being updated
163
 
   * @param[in] old_record Pointer to the old data in the record
164
 
   * @param[in] new_record Pointer to the new data in the record
165
 
   * @param[out] next_segment_id The next Statement segment id to be used
166
 
   */
167
 
  message::Statement &getUpdateStatement(Session *in_session,
168
 
                                         Table *in_table,
169
 
                                         const unsigned char *old_record, 
170
 
                                         const unsigned char *new_record,
171
 
                                         uint32_t *next_segment_id);
172
 
  /**
173
 
   * Helper method which initializes the header message for
174
 
   * update operations.
175
 
   *
176
 
   * @param[in,out] statement Statement message container to modify
177
 
   * @param[in] in_session Pointer to the Session doing the processing
178
 
   * @param[in] in_table Pointer to the Table being updated
179
 
   * @param[in] old_record Pointer to the old data in the record
180
 
   * @param[in] new_record Pointer to the new data in the record
181
 
   */
182
 
  void setUpdateHeader(message::Statement &statement,
183
 
                       Session *in_session,
184
 
                       Table *in_table,
185
 
                       const unsigned char *old_record, 
186
 
                       const unsigned char *new_record);
187
 
  /**
188
 
   * Helper method which returns an initialized Statement
189
 
   * message for methods doing deletion of data.
190
 
   *
191
 
   * @param[in] in_session Pointer to the Session doing the processing
192
 
   * @param[in] in_table Pointer to the Table object being deleted from
193
 
   * @param[out] next_segment_id The next Statement segment id to be used
194
 
   */
195
 
  message::Statement &getDeleteStatement(Session *in_session,
196
 
                                         Table *in_table,
197
 
                                         uint32_t *next_segment_id);
198
 
 
199
 
  /**
200
 
   * Helper method which initializes the header message for
201
 
   * insert operations.
202
 
   *
203
 
   * @param[in,out] statement Statement message container to modify
204
 
   * @param[in] in_session Pointer to the Session doing the processing
205
 
   * @param[in] in_table Pointer to the Table being deleted from
206
 
   */
207
 
  void setDeleteHeader(message::Statement &statement,
208
 
                       Session *in_session,
209
 
                       Table *in_table);
210
 
  /** 
211
 
   * Commits a normal transaction (see above) and pushes the transaction
212
 
   * message out to the replicators.
213
 
   *
214
 
   * @param in_session Pointer to the Session committing the transaction
215
 
   */
216
 
  int commitTransactionMessage(Session *in_session);
217
 
  /** 
218
 
   * Marks the current active transaction message as being rolled back and
219
 
   * pushes the transaction message out to replicators.
220
 
   *
221
 
   * @param in_session Pointer to the Session committing the transaction
222
 
   */
223
 
  void rollbackTransactionMessage(Session *in_session);
224
 
  /**
225
 
   * Rolls back the current statement, deleting the last Statement out of
226
 
   * the current Transaction message.
227
 
   *
228
 
   * @note This depends on having clear statement boundaries (i.e., one
229
 
   * Statement message per actual SQL statement.
230
 
   */
231
 
  void rollbackStatementMessage(Session *in_session);
 
85
 
232
86
  /**
233
87
   * Creates a new InsertRecord GPB message and pushes it to
234
88
   * replicators.
240
94
   * reversed bool return crap...fix that.
241
95
   */
242
96
  bool insertRecord(Session *in_session, Table *in_table);
 
97
 
243
98
  /**
244
99
   * Creates a new UpdateRecord GPB message and pushes it to
245
100
   * replicators.
253
108
                    Table *in_table, 
254
109
                    const unsigned char *old_record, 
255
110
                    const unsigned char *new_record);
 
111
 
256
112
  /**
257
113
   * Creates a new DeleteRecord GPB message and pushes it to
258
114
   * replicators.
264
120
  void deleteRecord(Session *in_session, Table *in_table, bool use_update_record= false);
265
121
 
266
122
  /**
267
 
   * Used to undo effects of a failed statement.
268
 
   *
269
 
   * An SQL statement, like an UPDATE, that affects multiple rows could
270
 
   * potentially fail mid-way through processing the rows. In such a case,
271
 
   * the successfully modified rows that preceeded the failing row would
272
 
   * have been added to the Statement message. This method is used for
273
 
   * rolling back that change.
274
 
   *
275
 
   * @note
276
 
   * This particular failure is seen on column constraint violations
277
 
   * during a multi-row UPDATE and a multi-row INSERT..SELECT.
278
 
   *
279
 
   * @param in_session Pointer to the Session containing the Statement
280
 
   * @param count The number of records to remove from Statement.
281
 
   *
282
 
   * @retval true Successfully removed 'count' records
283
 
   * @retval false Failure
284
 
   */
285
 
  bool removeStatementRecords(Session *in_session, uint32_t count);
286
 
 
287
 
  /**
288
123
   * Creates a CreateSchema Statement GPB message and adds it
289
124
   * to the Session's active Transaction GPB message for pushing
290
125
   * out to the replicator streams.
300
135
   * out to the replicator streams.
301
136
   *
302
137
   * @param[in] in_session Pointer to the Session which issued the statement
303
 
   * @param[in] schema_name message::Schema message describing new schema
 
138
   * @param[in] identifier Identifier for the schema to drop
304
139
   */
305
140
  void dropSchema(Session *in_session, identifier::Schema::const_reference identifier);
306
141
 
326
161
   * @param[in] table message::Table message describing new schema
327
162
   */
328
163
  void createTable(Session *in_session, const message::Table &table);
 
164
 
329
165
  /**
330
166
   * Creates a DropTable Statement GPB message and adds it
331
167
   * to the Session's active Transaction GPB message for pushing
338
174
  void dropTable(Session *in_session,
339
175
                 const identifier::Table &table,
340
176
                 bool if_exists);
 
177
 
341
178
  /**
342
179
   * Creates a TruncateTable Statement GPB message and adds it
343
180
   * to the Session's active Transaction GPB message for pushing
347
184
   * @param[in] in_table The Table being truncated
348
185
   */
349
186
  void truncateTable(Session *in_session, Table *in_table);
 
187
 
350
188
  /**
351
189
   * Creates a new RawSql GPB message and pushes it to 
352
190
   * replicators.
360
198
   * @param query Query string
361
199
   */
362
200
  void rawStatement(Session *in_session, const std::string &query);
 
201
 
363
202
  /* transactions: interface to plugin::StorageEngine functions */
364
 
  int commitPhaseOne(Session *session, bool all);
365
203
  int rollbackTransaction(Session *session, bool all);
366
204
 
367
205
  /* transactions: these functions never call plugin::StorageEngine functions directly */
446
284
  void registerResourceForTransaction(Session *session,
447
285
                                      plugin::MonitoredInTransaction *monitored,
448
286
                                      plugin::TransactionalStorageEngine *engine);
 
287
 
449
288
  void registerResourceForTransaction(Session *session,
450
289
                                      plugin::MonitoredInTransaction *monitored,
451
290
                                      plugin::TransactionalStorageEngine *engine,
452
291
                                      plugin::XaResourceManager *resource_manager);
453
292
 
454
 
  uint64_t getCurrentTransactionId(Session *session);
455
 
 
456
293
  void allocateNewTransactionId();
457
294
 
458
295
  /**************
482
319
private:
483
320
 
484
321
  /**
 
322
   * Method which returns the active Transaction message
 
323
   * for the supplied Session.  If one is not found, a new Transaction
 
324
   * message is allocated, initialized, and returned. It is possible that
 
325
   * we may want to NOT increment the transaction id for a new Transaction
 
326
   * object (e.g., splitting up Transactions into smaller chunks). The
 
327
   * should_inc_trx_id flag controls if we do this.
 
328
   *
 
329
   * @param in_session The session processing the transaction
 
330
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
 
331
   */
 
332
  message::Transaction *getActiveTransactionMessage(Session *in_session,
 
333
                                                    bool should_inc_trx_id= true);
 
334
 
 
335
  /** 
 
336
   * Method which attaches a transaction context
 
337
   * the supplied transaction based on the supplied Session's
 
338
   * transaction information.  This method also ensure the
 
339
   * transaction message is attached properly to the Session object
 
340
   *
 
341
   * @param in_transaction The transaction message to initialize
 
342
   * @param in_session The Session processing this transaction
 
343
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
 
344
   */
 
345
  void initTransactionMessage(message::Transaction &in_transaction,
 
346
                              Session *in_session,
 
347
                              bool should_inc_trx_id);
 
348
  
 
349
  /**
 
350
   * Helper method which initializes a Statement message
 
351
   *
 
352
   * @param statement The statement to initialize
 
353
   * @param in_type The type of the statement
 
354
   * @param in_session The session processing this statement
 
355
   */
 
356
  void initStatementMessage(message::Statement &statement,
 
357
                            message::Statement::Type in_type,
 
358
                            Session *in_session);
 
359
 
 
360
  /** 
 
361
   * Helper method which finalizes data members for the 
 
362
   * supplied transaction's context.
 
363
   *
 
364
   * @param in_transaction The transaction message to finalize 
 
365
   * @param in_session The Session processing this transaction
 
366
   */
 
367
  void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
 
368
 
 
369
  /**
 
370
   * Helper method which deletes transaction memory and
 
371
   * unsets Session's transaction and statement messages.
 
372
   */
 
373
  void cleanupTransactionMessage(message::Transaction *in_transaction,
 
374
                                 Session *in_session);
 
375
  
 
376
  /** Helper method which returns an initialized Statement message for methods
 
377
   * doing insertion of data.
 
378
   *
 
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
 
381
   * @param[out] next_segment_id The next Statement segment id to be used
 
382
   */
 
383
  message::Statement &getInsertStatement(Session *in_session,
 
384
                                         Table *in_table,
 
385
                                         uint32_t *next_segment_id);
 
386
  
 
387
  /**
 
388
   * Helper method which initializes the header message for
 
389
   * insert operations.
 
390
   *
 
391
   * @param[in,out] statement Statement message container to modify
 
392
   * @param[in] in_session Pointer to the Session doing the processing
 
393
   * @param[in] in_table Pointer to the Table being inserted into
 
394
   */
 
395
  void setInsertHeader(message::Statement &statement,
 
396
                       Session *in_session,
 
397
                       Table *in_table);
 
398
  /**
 
399
   * Helper method which returns an initialized Statement
 
400
   * message for methods doing updates of data.
 
401
   *
 
402
   * @param[in] in_session Pointer to the Session doing the processing
 
403
   * @param[in] in_table Pointer to the Table object being updated
 
404
   * @param[in] old_record Pointer to the old data in the record
 
405
   * @param[in] new_record Pointer to the new data in the record
 
406
   * @param[out] next_segment_id The next Statement segment id to be used
 
407
   */
 
408
  message::Statement &getUpdateStatement(Session *in_session,
 
409
                                         Table *in_table,
 
410
                                         const unsigned char *old_record, 
 
411
                                         const unsigned char *new_record,
 
412
                                         uint32_t *next_segment_id);
 
413
  /**
 
414
   * Helper method which initializes the header message for
 
415
   * update operations.
 
416
   *
 
417
   * @param[in,out] statement Statement message container to modify
 
418
   * @param[in] in_session Pointer to the Session doing the processing
 
419
   * @param[in] in_table Pointer to the Table being updated
 
420
   * @param[in] old_record Pointer to the old data in the record
 
421
   * @param[in] new_record Pointer to the new data in the record
 
422
   */
 
423
  void setUpdateHeader(message::Statement &statement,
 
424
                       Session *in_session,
 
425
                       Table *in_table,
 
426
                       const unsigned char *old_record, 
 
427
                       const unsigned char *new_record);
 
428
 
 
429
  /**
 
430
   * Helper method which returns an initialized Statement
 
431
   * message for methods doing deletion of data.
 
432
   *
 
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
 
435
   * @param[out] next_segment_id The next Statement segment id to be used
 
436
   */
 
437
  message::Statement &getDeleteStatement(Session *in_session,
 
438
                                         Table *in_table,
 
439
                                         uint32_t *next_segment_id);
 
440
  
 
441
  /**
 
442
   * Helper method which initializes the header message for
 
443
   * insert operations.
 
444
   *
 
445
   * @param[in,out] statement Statement message container to modify
 
446
   * @param[in] in_session Pointer to the Session doing the processing
 
447
   * @param[in] in_table Pointer to the Table being deleted from
 
448
   */
 
449
  void setDeleteHeader(message::Statement &statement,
 
450
                       Session *in_session,
 
451
                       Table *in_table);
 
452
 
 
453
  /** 
 
454
   * Commits a normal transaction (see above) and pushes the transaction
 
455
   * message out to the replicators.
 
456
   *
 
457
   * @param in_session Pointer to the Session committing the transaction
 
458
   */
 
459
  int commitTransactionMessage(Session *in_session);
 
460
 
 
461
  /** 
 
462
   * Marks the current active transaction message as being rolled back and
 
463
   * pushes the transaction message out to replicators.
 
464
   *
 
465
   * @param in_session Pointer to the Session committing the transaction
 
466
   */
 
467
  void rollbackTransactionMessage(Session *in_session);
 
468
 
 
469
  /**
 
470
   * Rolls back the current statement, deleting the last Statement out of
 
471
   * the current Transaction message.
 
472
   *
 
473
   * @note This depends on having clear statement boundaries (i.e., one
 
474
   * Statement message per actual SQL statement.
 
475
   */
 
476
  void rollbackStatementMessage(Session *in_session);
 
477
 
 
478
  /**
485
479
   * Checks if a field has been updated 
486
480
   *
487
481
   * @param current_field Pointer to the field to check if it is updated 
488
 
   * @in_table Pointer to the Table containing update information
 
482
   * @param in_table Pointer to the Table containing update information
489
483
   * @param old_record Pointer to the raw bytes representing the old record/row
490
484
   * @param new_record Pointer to the raw bytes representing the new record/row
491
485
   */
525
519
  message::Transaction *segmentTransactionMessage(Session *in_session,
526
520
                                                  message::Transaction *transaction);
527
521
 
 
522
  int commitPhaseOne(Session *session, bool all);
 
523
 
 
524
  uint64_t getCurrentTransactionId(Session *session);
 
525
 
528
526
  plugin::XaStorageEngine *xa_storage_engine;
529
527
};
530
528