~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Brian Aker
  • Date: 2010-10-09 17:44:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1853.
  • Revision ID: brian@tangent.org-20101009174413-4cs0q58kw0fjd45y
First pass through adding back user_locks.

Show diffs side-by-side

added added

removed removed

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