~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Lee Bieber
  • Date: 2010-10-27 18:28:56 UTC
  • mfrom: (1883.1.3 build)
  • Revision ID: kalebral@gmail.com-20101027182856-q3wqtbv1t4egkjsk
Merge Andrew - fix bug 667360: --defaults-file not processed before paths read           
Merge Andrew - fix bug 656577: Importing SQL script results in silent failure    
Merge Andrew - fix bug 667053: drizzledump minor output cleanup needed

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