~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Olaf van der Spek
  • Date: 2011-03-29 12:04:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110329120436-vozkuer8vqgh027p
Always call assert()

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * @file Transaction processing code
23
23
 */
24
24
 
25
 
#ifndef DRIZZLED_TRANSACTION_SERVICES_H
26
 
#define DRIZZLED_TRANSACTION_SERVICES_H
27
 
 
28
 
#include "drizzled/atomics.h"
29
 
#include "drizzled/message/transaction.pb.h"
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
/* some forward declarations needed */
35
 
namespace plugin
36
 
{
37
 
  class MonitoredInTransaction;
38
 
  class XaResourceManager;
39
 
  class XaStorageEngine;
40
 
  class TransactionalStorageEngine;
41
 
}
42
 
 
43
 
class Session;
44
 
class NamedSavepoint;
45
 
class Field;
 
25
#pragma once
 
26
 
 
27
#include <drizzled/atomics.h>
 
28
#include <drizzled/message/transaction.pb.h>
 
29
#include <drizzled/identifier.h>
 
30
#include <drizzled/message/schema.h>
 
31
#include <drizzled/message/table.h>
 
32
#include <drizzled/session.h>
 
33
 
 
34
#include <drizzled/visibility.h>
 
35
 
 
36
namespace drizzled {
46
37
 
47
38
/**
48
39
 * This is a class which manages the XA transaction processing
49
40
 * in the server
50
41
 */
51
 
class TransactionServices
 
42
class DRIZZLED_API TransactionServices
52
43
{
53
44
public:
54
45
  static const size_t DEFAULT_RECORD_SIZE= 100;
70
61
   * Transaction and Statement messages, false otherwise.
71
62
   */
72
63
  bool shouldConstructMessages();
73
 
  /**
74
 
   * Method which returns the active Transaction message
75
 
   * for the supplied Session.  If one is not found, a new Transaction
76
 
   * message is allocated, initialized, and returned. It is possible that
77
 
   * we may want to NOT increment the transaction id for a new Transaction
78
 
   * object (e.g., splitting up Transactions into smaller chunks). The
79
 
   * should_inc_trx_id flag controls if we do this.
80
 
   *
81
 
   * @param in_session The session processing the transaction
82
 
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
83
 
   */
84
 
  message::Transaction *getActiveTransactionMessage(Session *in_session,
85
 
                                                    bool should_inc_trx_id= true);
86
 
  /** 
87
 
   * Method which attaches a transaction context
88
 
   * the supplied transaction based on the supplied Session's
89
 
   * transaction information.  This method also ensure the
90
 
   * transaction message is attached properly to the Session object
91
 
   *
92
 
   * @param in_transaction The transaction message to initialize
93
 
   * @param in_session The Session processing this transaction
94
 
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
95
 
   */
96
 
  void initTransactionMessage(message::Transaction &in_transaction,
97
 
                              Session *in_session,
98
 
                              bool should_inc_trx_id);
99
 
  /** 
100
 
   * Helper method which finalizes data members for the 
101
 
   * supplied transaction's context.
102
 
   *
103
 
   * @param in_transaction The transaction message to finalize 
104
 
   * @param in_session The Session processing this transaction
105
 
   */
106
 
  void finalizeTransactionMessage(message::Transaction &in_transaction, Session *in_session);
107
 
  /**
108
 
   * Helper method which deletes transaction memory and
109
 
   * unsets Session's transaction and statement messages.
110
 
   */
111
 
  void cleanupTransactionMessage(message::Transaction *in_transaction,
112
 
                                 Session *in_session);
113
64
 
114
65
  /**
115
 
   * Helper method which initializes a Statement message
116
 
   *
117
 
   * @param statement The statement to initialize
118
 
   * @param in_type The type of the statement
119
 
   * @param in_session The session processing this statement
120
 
   */
121
 
  void initStatementMessage(message::Statement &statement,
122
 
                            message::Statement::Type in_type,
123
 
                            Session *in_session);
124
 
  /**
125
66
   * Finalizes a Statement message and sets the Session's statement
126
67
   * message to NULL.
127
68
   *
128
69
   * @param statement The statement to initialize
129
 
   * @param in_session The session processing this statement
 
70
   * @param session The Session object processing this statement
130
71
   */
131
72
  void finalizeStatementMessage(message::Statement &statement,
132
 
                                Session *in_session);
133
 
  /** Helper method which returns an initialized Statement message for methods
134
 
   * doing insertion of data.
135
 
   *
136
 
   * @param[in] in_session Pointer to the Session doing the processing
137
 
   * @param[in] in_table Pointer to the Table object being inserted into
138
 
   * @param[out] next_segment_id The next Statement segment id to be used
139
 
   */
140
 
  message::Statement &getInsertStatement(Session *in_session,
141
 
                                         Table *in_table,
142
 
                                         uint32_t *next_segment_id);
143
 
 
144
 
  /**
145
 
   * Helper method which initializes the header message for
146
 
   * insert operations.
147
 
   *
148
 
   * @param[in,out] statement Statement message container to modify
149
 
   * @param[in] in_session Pointer to the Session doing the processing
150
 
   * @param[in] in_table Pointer to the Table being inserted into
151
 
   */
152
 
  void setInsertHeader(message::Statement &statement,
153
 
                       Session *in_session,
154
 
                       Table *in_table);
155
 
  /**
156
 
   * Helper method which returns an initialized Statement
157
 
   * message for methods doing updates of data.
158
 
   *
159
 
   * @param[in] in_session Pointer to the Session doing the processing
160
 
   * @param[in] in_table Pointer to the Table object being updated
161
 
   * @param[in] old_record Pointer to the old data in the record
162
 
   * @param[in] new_record Pointer to the new data in the record
163
 
   * @param[out] next_segment_id The next Statement segment id to be used
164
 
   */
165
 
  message::Statement &getUpdateStatement(Session *in_session,
166
 
                                         Table *in_table,
167
 
                                         const unsigned char *old_record, 
168
 
                                         const unsigned char *new_record,
169
 
                                         uint32_t *next_segment_id);
170
 
  /**
171
 
   * Helper method which initializes the header message for
172
 
   * update operations.
173
 
   *
174
 
   * @param[in,out] statement Statement message container to modify
175
 
   * @param[in] in_session Pointer to the Session doing the processing
176
 
   * @param[in] in_table Pointer to the Table being updated
177
 
   * @param[in] old_record Pointer to the old data in the record
178
 
   * @param[in] new_record Pointer to the new data in the record
179
 
   */
180
 
  void setUpdateHeader(message::Statement &statement,
181
 
                       Session *in_session,
182
 
                       Table *in_table,
183
 
                       const unsigned char *old_record, 
184
 
                       const unsigned char *new_record);
185
 
  /**
186
 
   * Helper method which returns an initialized Statement
187
 
   * message for methods doing deletion of data.
188
 
   *
189
 
   * @param[in] in_session Pointer to the Session doing the processing
190
 
   * @param[in] in_table Pointer to the Table object being deleted from
191
 
   * @param[out] next_segment_id The next Statement segment id to be used
192
 
   */
193
 
  message::Statement &getDeleteStatement(Session *in_session,
194
 
                                         Table *in_table,
195
 
                                         uint32_t *next_segment_id);
196
 
 
197
 
  /**
198
 
   * Helper method which initializes the header message for
199
 
   * insert operations.
200
 
   *
201
 
   * @param[in,out] statement Statement message container to modify
202
 
   * @param[in] in_session Pointer to the Session doing the processing
203
 
   * @param[in] in_table Pointer to the Table being deleted from
204
 
   */
205
 
  void setDeleteHeader(message::Statement &statement,
206
 
                       Session *in_session,
207
 
                       Table *in_table);
208
 
  /** 
209
 
   * Commits a normal transaction (see above) and pushes the transaction
210
 
   * message out to the replicators.
211
 
   *
212
 
   * @param in_session Pointer to the Session committing the transaction
213
 
   */
214
 
  int commitTransactionMessage(Session *in_session);
215
 
  /** 
216
 
   * Marks the current active transaction message as being rolled back and
217
 
   * pushes the transaction message out to replicators.
218
 
   *
219
 
   * @param in_session Pointer to the Session committing the transaction
220
 
   */
221
 
  void rollbackTransactionMessage(Session *in_session);
222
 
  /**
223
 
   * Rolls back the current statement, deleting the last Statement out of
224
 
   * the current Transaction message.
225
 
   *
226
 
   * @note This depends on having clear statement boundaries (i.e., one
227
 
   * Statement message per actual SQL statement.
228
 
   */
229
 
  void rollbackStatementMessage(Session *in_session);
 
73
                                Session& session);
 
74
 
230
75
  /**
231
76
   * Creates a new InsertRecord GPB message and pushes it to
232
77
   * replicators.
233
78
   *
234
 
   * @param in_session Pointer to the Session which has inserted a record
235
 
   * @param in_table Pointer to the Table containing insert information
 
79
   * @param session Session object which has inserted a record
 
80
   * @param table Table object containing insert information
236
81
   *
237
82
   * Grr, returning "true" here on error because of the cursor
238
83
   * reversed bool return crap...fix that.
239
84
   */
240
 
  bool insertRecord(Session *in_session, Table *in_table);
 
85
  bool insertRecord(Session& session, Table &in_table);
 
86
 
241
87
  /**
242
88
   * Creates a new UpdateRecord GPB message and pushes it to
243
89
   * replicators.
244
90
   *
245
 
   * @param in_session Pointer to the Session which has updated a record
246
 
   * @param in_table Pointer to the Table containing update information
 
91
   * @param session Session object which has updated a record
 
92
   * @param table Table object containing update information
247
93
   * @param old_record Pointer to the raw bytes representing the old record/row
248
94
   * @param new_record Pointer to the raw bytes representing the new record/row 
249
95
   */
250
 
  void updateRecord(Session *in_session, 
251
 
                    Table *in_table, 
 
96
  void updateRecord(Session& session, 
 
97
                    Table &table, 
252
98
                    const unsigned char *old_record, 
253
99
                    const unsigned char *new_record);
 
100
 
254
101
  /**
255
102
   * Creates a new DeleteRecord GPB message and pushes it to
256
103
   * replicators.
257
104
   *
258
 
   * @param in_session Pointer to the Session which has deleted a record
259
 
   * @param in_table Pointer to the Table containing delete information
 
105
   * @param session Session object which has deleted a record
 
106
   * @param table Table object containing delete information
260
107
   * @param use_update_record If true, uses the values from the update row instead
261
108
   */
262
 
  void deleteRecord(Session *in_session, Table *in_table, bool use_update_record= false);
263
 
 
264
 
  /**
265
 
   * Used to undo effects of a failed statement.
266
 
   *
267
 
   * An SQL statement, like an UPDATE, that affects multiple rows could
268
 
   * potentially fail mid-way through processing the rows. In such a case,
269
 
   * the successfully modified rows that preceeded the failing row would
270
 
   * have been added to the Statement message. This method is used for
271
 
   * rolling back that change.
272
 
   *
273
 
   * @note
274
 
   * This particular failure is seen on column constraint violations
275
 
   * during a multi-row UPDATE and a multi-row INSERT..SELECT.
276
 
   *
277
 
   * @param in_session Pointer to the Session containing the Statement
278
 
   * @param count The number of records to remove from Statement.
279
 
   *
280
 
   * @retval true Successfully removed 'count' records
281
 
   * @retval false Failure
282
 
   */
283
 
  bool removeStatementRecords(Session *in_session, uint32_t count);
 
109
  void deleteRecord(Session& session,
 
110
                    Table &table,
 
111
                    bool use_update_record= false);
284
112
 
285
113
  /**
286
114
   * Creates a CreateSchema Statement GPB message and adds it
287
115
   * to the Session's active Transaction GPB message for pushing
288
116
   * out to the replicator streams.
289
117
   *
290
 
   * @param[in] in_session Pointer to the Session which issued the statement
 
118
   * @param[in] session Session object which issued the statement
291
119
   * @param[in] schema message::Schema message describing new schema
292
120
   */
293
 
  void createSchema(Session *in_session, const message::Schema &schema);
 
121
  void createSchema(Session& session, const message::Schema &schema);
 
122
 
294
123
  /**
295
124
   * Creates a DropSchema Statement GPB message and adds it
296
125
   * to the Session's active Transaction GPB message for pushing
297
126
   * out to the replicator streams.
298
127
   *
299
 
   * @param[in] in_session Pointer to the Session which issued the statement
300
 
   * @param[in] schema_name message::Schema message describing new schema
301
 
   */
302
 
  void dropSchema(Session *in_session, const std::string &schema_name);
 
128
   * @param[in] session Session object which issued the statement
 
129
   * @param[in] identifier Identifier for the schema to drop
 
130
   */
 
131
  void dropSchema(Session& session,
 
132
                  const identifier::Schema& identifier,
 
133
                  message::schema::const_reference schema);
 
134
 
 
135
  /**
 
136
   * Creates an AlterSchema Statement GPB message and adds it
 
137
   * to the Session's active Transaction GPB message for pushing
 
138
   * out to the replicator streams.
 
139
   *
 
140
   * @param[in] session Session object which issued the statement
 
141
   * @param[in] old_schema Original schema definition
 
142
   * @param[in] new_schema New schema definition
 
143
   */
 
144
  void alterSchema(Session& session,
 
145
                   const message::Schema &old_schema,
 
146
                   const message::Schema &new_schema);
 
147
 
303
148
  /**
304
149
   * Creates a CreateTable Statement GPB message and adds it
305
150
   * to the Session's active Transaction GPB message for pushing
306
151
   * out to the replicator streams.
307
152
   *
308
 
   * @param[in] in_session Pointer to the Session which issued the statement
 
153
   * @param[in] session Session object which issued the statement
309
154
   * @param[in] table message::Table message describing new schema
310
155
   */
311
 
  void createTable(Session *in_session, const message::Table &table);
 
156
  void createTable(Session& session, const message::Table &table);
 
157
 
312
158
  /**
313
159
   * Creates a DropTable Statement GPB message and adds it
314
160
   * to the Session's active Transaction GPB message for pushing
315
161
   * out to the replicator streams.
316
162
   *
317
 
   * @param[in] in_session Pointer to the Session which issued the statement
318
 
   * @param[in] schema_name The schema of the table being dropped
319
 
   * @param[in] table_name The table name of the table being dropped
 
163
   * @param[in] session Session object which issued the statement
 
164
   * @param[in] table Identifier for the table being dropped
320
165
   * @param[in] if_exists Did the user specify an IF EXISTS clause?
321
166
   */
322
 
  void dropTable(Session *in_session,
323
 
                     const std::string &schema_name,
324
 
                     const std::string &table_name,
325
 
                     bool if_exists);
 
167
  void dropTable(Session& session,
 
168
                 const identifier::Table& identifier,
 
169
                 message::table::const_reference table,
 
170
                 bool if_exists);
 
171
 
326
172
  /**
327
173
   * Creates a TruncateTable Statement GPB message and adds it
328
174
   * to the Session's active Transaction GPB message for pushing
329
175
   * out to the replicator streams.
330
176
   *
331
 
   * @param[in] in_session Pointer to the Session which issued the statement
332
 
   * @param[in] in_table The Table being truncated
 
177
   * @param[in] session Session object which issued the statement
 
178
   * @param[in] table The Table being truncated
333
179
   */
334
 
  void truncateTable(Session *in_session, Table *in_table);
 
180
  void truncateTable(Session& session, Table &table);
 
181
 
335
182
  /**
336
183
   * Creates a new RawSql GPB message and pushes it to 
337
184
   * replicators.
341
188
   * on the I_S, etc.  Not sure what to do with administrative
342
189
   * commands like CHECK TABLE, though..
343
190
   *
344
 
   * @param in_session Pointer to the Session which issued the statement
 
191
   * @param session Session object which issued the statement
345
192
   * @param query Query string
 
193
   * @param schema Schema for the table affected by the raw SQL.
346
194
   */
347
 
  void rawStatement(Session *in_session, const std::string &query);
 
195
  void rawStatement(Session& session,
 
196
                    const std::string &query,
 
197
                    const std::string &schema);
 
198
 
 
199
  void rawStatement(Session& session, const std::string &query)
 
200
  {
 
201
    rawStatement(session, query, "");
 
202
  }
 
203
 
348
204
  /* transactions: interface to plugin::StorageEngine functions */
349
 
  int commitPhaseOne(Session *session, bool all);
350
 
  int rollbackTransaction(Session *session, bool all);
351
 
 
352
 
  /* transactions: these functions never call plugin::StorageEngine functions directly */
353
 
  int commitTransaction(Session *session, bool all);
354
 
  int autocommitOrRollback(Session *session, int error);
 
205
  int rollbackTransaction(Session& session, bool all);
 
206
 
 
207
  /**
 
208
   * Commit the current transaction.
 
209
   *
 
210
   * @retval 0 ok
 
211
   * @retval 1 transaction was rolled back
 
212
   * @retval 2 error during commit, data may be inconsistent
 
213
   *
 
214
   * @todo
 
215
   * Since we don't support nested statement transactions in 5.0,
 
216
   * we can't commit or rollback stmt transactions while we are inside
 
217
   * stored functions or triggers. So we simply do nothing now.
 
218
   * This should be fixed in later ( >= 5.1) releases.
 
219
   */
 
220
  int commitTransaction(Session& session, bool all);
 
221
 
 
222
  /**
 
223
   * This is used to commit or rollback a single statement depending on
 
224
   * the value of error.
 
225
   *
 
226
   * @note
 
227
   * Note that if the autocommit is on, then the following call inside
 
228
   * InnoDB will commit or rollback the whole transaction (= the statement). The
 
229
   * autocommit mechanism built into InnoDB is based on counting locks, but if
 
230
   * the user has used LOCK TABLES then that mechanism does not know to do the
 
231
   * commit.
 
232
   */
 
233
  int autocommitOrRollback(Session& session, int error);
355
234
 
356
235
  /* savepoints */
357
 
  int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
358
 
  int setSavepoint(Session *session, NamedSavepoint &sv);
359
 
  int releaseSavepoint(Session *session, NamedSavepoint &sv);
 
236
  int rollbackToSavepoint(Session& session, NamedSavepoint &sv);
 
237
  int setSavepoint(Session& session, NamedSavepoint &sv);
 
238
  int releaseSavepoint(Session& session, NamedSavepoint &sv);
360
239
 
361
240
  /**
362
241
   * Marks a storage engine as participating in a statement
372
251
   * per statement, and therefore should not need to be idempotent.
373
252
   * Put in assert()s to test this.
374
253
   *
375
 
   * @param[in] session Session pointer
 
254
   * @param[in] session Session object
376
255
   * @param[in] monitored Descriptor for the resource which will be participating
377
256
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
378
257
   */
379
 
  void registerResourceForStatement(Session *session,
 
258
  void registerResourceForStatement(Session& session,
380
259
                                    plugin::MonitoredInTransaction *monitored,
381
260
                                    plugin::TransactionalStorageEngine *engine);
382
261
 
394
273
   * per statement, and therefore should not need to be idempotent.
395
274
   * Put in assert()s to test this.
396
275
   *
397
 
   * @param[in] session Session pointer
 
276
   * @param[in] session Session object
398
277
   * @param[in] monitored Descriptor for the resource which will be participating
399
278
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
400
279
   * @param[in] resource_manager Pointer to the XaResourceManager resource manager
401
280
   */
402
 
  void registerResourceForStatement(Session *session,
 
281
  void registerResourceForStatement(Session& session,
403
282
                                    plugin::MonitoredInTransaction *monitored,
404
283
                                    plugin::TransactionalStorageEngine *engine,
405
284
                                    plugin::XaResourceManager *resource_manager);
428
307
   * time when this method is called except from the
429
308
   * TransactionServices::registerResourceForStatement method.
430
309
   */
431
 
  void registerResourceForTransaction(Session *session,
 
310
  void registerResourceForTransaction(Session& session,
432
311
                                      plugin::MonitoredInTransaction *monitored,
433
312
                                      plugin::TransactionalStorageEngine *engine);
434
 
  void registerResourceForTransaction(Session *session,
 
313
 
 
314
  void registerResourceForTransaction(Session& session,
435
315
                                      plugin::MonitoredInTransaction *monitored,
436
316
                                      plugin::TransactionalStorageEngine *engine,
437
317
                                      plugin::XaResourceManager *resource_manager);
438
318
 
439
 
  uint64_t getCurrentTransactionId(Session *session);
440
 
 
441
319
  void allocateNewTransactionId();
442
320
 
443
321
  /**************
447
325
  /**
448
326
   * Send server startup event.
449
327
   *
450
 
   * @param session Session pointer
 
328
   * @param session Session object
451
329
   *
452
330
   * @retval true Success
453
331
   * @retval false Failure
454
332
   */
455
 
  bool sendStartupEvent(Session *session);
 
333
  bool sendStartupEvent(Session& session);
456
334
 
457
335
  /**
458
336
   * Send server shutdown event.
459
337
   *
460
 
   * @param session Session pointer
 
338
   * @param session Session object
461
339
   *
462
340
   * @retval true Success
463
341
   * @retval false Failure
464
342
   */
465
 
  bool sendShutdownEvent(Session *session);
 
343
  bool sendShutdownEvent(Session& session);
466
344
 
467
345
private:
468
346
 
469
347
  /**
 
348
   * Method which returns the active Transaction message
 
349
   * for the supplied Session.  If one is not found, a new Transaction
 
350
   * message is allocated, initialized, and returned. It is possible that
 
351
   * we may want to NOT increment the transaction id for a new Transaction
 
352
   * object (e.g., splitting up Transactions into smaller chunks). The
 
353
   * should_inc_trx_id flag controls if we do this.
 
354
   *
 
355
   * @param session The Session object processing the transaction
 
356
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
 
357
   */
 
358
  message::Transaction *getActiveTransactionMessage(Session& session,
 
359
                                                    bool should_inc_trx_id= true);
 
360
 
 
361
  /** 
 
362
   * Method which attaches a transaction context
 
363
   * the supplied transaction based on the supplied Session's
 
364
   * transaction information.  This method also ensure the
 
365
   * transaction message is attached properly to the Session object
 
366
   *
 
367
   * @param transaction The transaction message to initialize
 
368
   * @param session The Session object processing this transaction
 
369
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
 
370
   */
 
371
  void initTransactionMessage(message::Transaction &transaction,
 
372
                              Session& session,
 
373
                              bool should_inc_trx_id);
 
374
  
 
375
  /**
 
376
   * Helper method which initializes a Statement message
 
377
   *
 
378
   * @param statement The statement to initialize
 
379
   * @param type The type of the statement
 
380
   * @param session The Session object processing this statement
 
381
   */
 
382
  void initStatementMessage(message::Statement &statement,
 
383
                            message::Statement::Type type,
 
384
                            const Session& session);
 
385
 
 
386
  /** 
 
387
   * Helper method which finalizes data members for the 
 
388
   * supplied transaction's context.
 
389
   *
 
390
   * @param transaction The transaction message to finalize 
 
391
   * @param session The Session object processing this transaction
 
392
   */
 
393
  void finalizeTransactionMessage(message::Transaction &transaction,
 
394
                                  const Session& session);
 
395
 
 
396
  /**
 
397
   * Helper method which deletes transaction memory and
 
398
   * unsets Session's transaction and statement messages.
 
399
   */
 
400
  void cleanupTransactionMessage(message::Transaction *transaction,
 
401
                                 Session& session);
 
402
  
 
403
  /** Helper method which returns an initialized Statement message for methods
 
404
   * doing insertion of data.
 
405
   *
 
406
   * @param[in] session Session object doing the processing
 
407
   * @param[in] table Table object being inserted into
 
408
   * @param[out] next_segment_id The next Statement segment id to be used
 
409
   */
 
410
  message::Statement &getInsertStatement(Session& session,
 
411
                                         Table &table,
 
412
                                         uint32_t *next_segment_id);
 
413
  
 
414
  /**
 
415
   * Helper method which initializes the header message for
 
416
   * insert operations.
 
417
   *
 
418
   * @param[in,out] statement Statement message container to modify
 
419
   * @param[in] session Session object doing the processing
 
420
   * @param[in] table Table object being inserted into
 
421
   */
 
422
  void setInsertHeader(message::Statement &statement,
 
423
                       const Session& session,
 
424
                       Table &table);
 
425
  /**
 
426
   * Helper method which returns an initialized Statement
 
427
   * message for methods doing updates of data.
 
428
   *
 
429
   * @param[in] session Session object doing the processing
 
430
   * @param[in] table Table object being updated
 
431
   * @param[in] old_record Pointer to the old data in the record
 
432
   * @param[in] new_record Pointer to the new data in the record
 
433
   * @param[out] next_segment_id The next Statement segment id to be used
 
434
   */
 
435
  message::Statement &getUpdateStatement(Session& session,
 
436
                                         Table &table,
 
437
                                         const unsigned char *old_record, 
 
438
                                         const unsigned char *new_record,
 
439
                                         uint32_t *next_segment_id);
 
440
  /**
 
441
   * Helper method which initializes the header message for
 
442
   * update operations.
 
443
   *
 
444
   * @param[in,out] statement Statement message container to modify
 
445
   * @param[in] session Session object doing the processing
 
446
   * @param[in] table Table object being updated
 
447
   * @param[in] old_record Pointer to the old data in the record
 
448
   * @param[in] new_record Pointer to the new data in the record
 
449
   */
 
450
  void setUpdateHeader(message::Statement &statement,
 
451
                       const Session& session,
 
452
                       Table &table,
 
453
                       const unsigned char *old_record, 
 
454
                       const unsigned char *new_record);
 
455
 
 
456
  /**
 
457
   * Helper method which returns an initialized Statement
 
458
   * message for methods doing deletion of data.
 
459
   *
 
460
   * @param[in] session Session object doing the processing
 
461
   * @param[in] table Table object being deleted from
 
462
   * @param[out] next_segment_id The next Statement segment id to be used
 
463
   */
 
464
  message::Statement &getDeleteStatement(Session& session,
 
465
                                         Table &table,
 
466
                                         uint32_t *next_segment_id);
 
467
  
 
468
  /**
 
469
   * Helper method which initializes the header message for
 
470
   * insert operations.
 
471
   *
 
472
   * @param[in,out] statement Statement message container to modify
 
473
   * @param[in] session Session object doing the processing
 
474
   * @param[in] table Table object being deleted from
 
475
   */
 
476
  void setDeleteHeader(message::Statement &statement,
 
477
                       const Session& session,
 
478
                       Table &table);
 
479
 
 
480
  /** 
 
481
   * Commits a normal transaction (see above) and pushes the transaction
 
482
   * message out to the replicators.
 
483
   *
 
484
   * @param session Session object committing the transaction
 
485
   */
 
486
  int commitTransactionMessage(Session& session);
 
487
 
 
488
  /** 
 
489
   * Marks the current active transaction message as being rolled back and
 
490
   * pushes the transaction message out to replicators.
 
491
   *
 
492
   * @param session Session object committing the transaction
 
493
   */
 
494
  void rollbackTransactionMessage(Session& session);
 
495
 
 
496
  /**
 
497
   * Rolls back the current statement, deleting the last Statement out of
 
498
   * the current Transaction message.
 
499
   *
 
500
   * @param session Session object committing the transaction
 
501
   *
 
502
   * @note This depends on having clear statement boundaries (i.e., one
 
503
   * Statement message per actual SQL statement).
 
504
   */
 
505
  void rollbackStatementMessage(Session& session);
 
506
 
 
507
  /**
470
508
   * Checks if a field has been updated 
471
509
   *
472
510
   * @param current_field Pointer to the field to check if it is updated 
473
 
   * @in_table Pointer to the Table containing update information
 
511
   * @param table Table object containing update information
474
512
   * @param old_record Pointer to the raw bytes representing the old record/row
475
513
   * @param new_record Pointer to the raw bytes representing the new record/row
476
514
   */
477
515
  bool isFieldUpdated(Field *current_field,
478
 
                      Table *in_table,
 
516
                      Table &table,
479
517
                      const unsigned char *old_record,
480
518
                      const unsigned char *new_record);
481
519
 
486
524
   * message associated with Session. We create a totally new message and
487
525
   * use it.
488
526
   *
489
 
   * @param session Session pointer
 
527
   * @param session Session object
490
528
   * @param event Event message to send
491
529
   *
492
530
   * @note Used by the public Events API.
493
531
   *
494
532
   * @returns Non-zero on error
495
533
   */
496
 
  int sendEvent(Session *session, const message::Event &event);
 
534
  int sendEvent(Session& session, const message::Event &event);
497
535
 
498
536
  /**
499
 
   * Helper method which checks the UpdateHeader to determine 
500
 
   * if it needs to be finalized.  
501
 
   *
502
 
   * @param[in] statement Statement message container to check 
503
 
   * @param[in] in_table Pointer to the Table being updated
504
 
   * @param[in] old_record Pointer to the old data in the record
505
 
   * @param[in] new_record Pointer to the new data in the record
 
537
   * Makes a given Transaction message segmented.
 
538
   *
 
539
   * The given Transaction message will have its segment information set
 
540
   * appropriately and a new Transaction message, containing the same
 
541
   * transaction ID as the supplied Transaction, and is created.
 
542
   *
 
543
   * @param session Session object
 
544
   * @param transaction Transaction message to segment.
 
545
   *
 
546
   * @returns Returns a pointer to a new Transaction message ready for use.
506
547
   */
507
 
  bool useExistingUpdateHeader(message::Statement &statement,
508
 
                               Table *in_table,
509
 
                               const unsigned char *old_record,
510
 
                               const unsigned char *new_record);
 
548
  message::Transaction *segmentTransactionMessage(Session& session,
 
549
                                                  message::Transaction *transaction);
 
550
 
 
551
  int commitPhaseOne(Session& session, bool all);
 
552
 
 
553
  uint64_t getCurrentTransactionId(Session& session);
511
554
 
512
555
  plugin::XaStorageEngine *xa_storage_engine;
513
556
};
514
557
 
515
558
} /* namespace drizzled */
516
559
 
517
 
#endif /* DRIZZLED_TRANSACTION_SERVICES_H */