~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Brian Aker
  • Date: 2010-12-18 10:14:05 UTC
  • mfrom: (2008.1.3 clean)
  • Revision ID: brian@tangent.org-20101218101405-qjbse29shi9coklg
Merge of user identifier work

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
{
54
48
 * This is a class which manages the XA transaction processing
55
49
 * in the server
56
50
 */
57
 
class DRIZZLED_API TransactionServices
 
51
class TransactionServices
58
52
{
59
53
public:
60
54
  static const size_t DEFAULT_RECORD_SIZE= 100;
76
70
   * Transaction and Statement messages, false otherwise.
77
71
   */
78
72
  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);
79
113
 
80
114
  /**
 
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
  /**
81
125
   * Finalizes a Statement message and sets the Session's statement
82
126
   * message to NULL.
83
127
   *
84
128
   * @param statement The statement to initialize
85
 
   * @param session The Session object processing this statement
 
129
   * @param in_session The session processing this statement
86
130
   */
87
131
  void finalizeStatementMessage(message::Statement &statement,
88
 
                                Session::reference session);
89
 
 
 
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);
90
230
  /**
91
231
   * Creates a new InsertRecord GPB message and pushes it to
92
232
   * replicators.
93
233
   *
94
 
   * @param session Session object which has inserted a record
95
 
   * @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
96
236
   *
97
237
   * Grr, returning "true" here on error because of the cursor
98
238
   * reversed bool return crap...fix that.
99
239
   */
100
 
  bool insertRecord(Session::reference session, Table &in_table);
101
 
 
 
240
  bool insertRecord(Session *in_session, Table *in_table);
102
241
  /**
103
242
   * Creates a new UpdateRecord GPB message and pushes it to
104
243
   * replicators.
105
244
   *
106
 
   * @param session Session object which has updated a record
107
 
   * @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
108
247
   * @param old_record Pointer to the raw bytes representing the old record/row
109
248
   * @param new_record Pointer to the raw bytes representing the new record/row 
110
249
   */
111
 
  void updateRecord(Session::reference session, 
112
 
                    Table &table, 
 
250
  void updateRecord(Session *in_session, 
 
251
                    Table *in_table, 
113
252
                    const unsigned char *old_record, 
114
253
                    const unsigned char *new_record);
115
 
 
116
254
  /**
117
255
   * Creates a new DeleteRecord GPB message and pushes it to
118
256
   * replicators.
119
257
   *
120
 
   * @param session Session object which has deleted a record
121
 
   * @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
122
260
   * @param use_update_record If true, uses the values from the update row instead
123
261
   */
124
 
  void deleteRecord(Session::reference session,
125
 
                    Table &table,
126
 
                    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);
127
284
 
128
285
  /**
129
286
   * Creates a CreateSchema Statement GPB message and adds it
130
287
   * to the Session's active Transaction GPB message for pushing
131
288
   * out to the replicator streams.
132
289
   *
133
 
   * @param[in] session Session object which issued the statement
 
290
   * @param[in] in_session Pointer to the Session which issued the statement
134
291
   * @param[in] schema message::Schema message describing new schema
135
292
   */
136
 
  void createSchema(Session::reference session, const message::Schema &schema);
137
 
 
 
293
  void createSchema(Session *in_session, const message::Schema &schema);
138
294
  /**
139
295
   * Creates a DropSchema Statement GPB message and adds it
140
296
   * to the Session's active Transaction GPB message for pushing
141
297
   * out to the replicator streams.
142
298
   *
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
 
 
 
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);
163
303
  /**
164
304
   * Creates a CreateTable Statement GPB message and adds it
165
305
   * to the Session's active Transaction GPB message for pushing
166
306
   * out to the replicator streams.
167
307
   *
168
 
   * @param[in] session Session object which issued the statement
 
308
   * @param[in] in_session Pointer to the Session which issued the statement
169
309
   * @param[in] table message::Table message describing new schema
170
310
   */
171
 
  void createTable(Session::reference session, const message::Table &table);
172
 
 
 
311
  void createTable(Session *in_session, const message::Table &table);
173
312
  /**
174
313
   * Creates a DropTable Statement GPB message and adds it
175
314
   * to the Session's active Transaction GPB message for pushing
176
315
   * out to the replicator streams.
177
316
   *
178
 
   * @param[in] session Session object which issued the statement
179
 
   * @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
180
320
   * @param[in] if_exists Did the user specify an IF EXISTS clause?
181
321
   */
182
 
  void dropTable(Session::reference session,
183
 
                 identifier::Table::const_reference identifier,
184
 
                 message::table::const_reference table,
185
 
                 bool if_exists);
186
 
 
 
322
  void dropTable(Session *in_session,
 
323
                     const std::string &schema_name,
 
324
                     const std::string &table_name,
 
325
                     bool if_exists);
187
326
  /**
188
327
   * Creates a TruncateTable Statement GPB message and adds it
189
328
   * to the Session's active Transaction GPB message for pushing
190
329
   * out to the replicator streams.
191
330
   *
192
 
   * @param[in] session Session object which issued the statement
193
 
   * @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
194
333
   */
195
 
  void truncateTable(Session::reference session, Table &table);
196
 
 
 
334
  void truncateTable(Session *in_session, Table *in_table);
197
335
  /**
198
336
   * Creates a new RawSql GPB message and pushes it to 
199
337
   * replicators.
203
341
   * on the I_S, etc.  Not sure what to do with administrative
204
342
   * commands like CHECK TABLE, though..
205
343
   *
206
 
   * @param session Session object which issued the statement
 
344
   * @param in_session Pointer to the Session which issued the statement
207
345
   * @param query Query string
208
346
   */
209
 
  void rawStatement(Session::reference session, const std::string &query);
210
 
 
 
347
  void rawStatement(Session *in_session, const std::string &query);
211
348
  /* 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);
 
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);
241
355
 
242
356
  /* 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);
 
357
  int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
 
358
  int setSavepoint(Session *session, NamedSavepoint &sv);
 
359
  int releaseSavepoint(Session *session, NamedSavepoint &sv);
246
360
 
247
361
  /**
248
362
   * Marks a storage engine as participating in a statement
258
372
   * per statement, and therefore should not need to be idempotent.
259
373
   * Put in assert()s to test this.
260
374
   *
261
 
   * @param[in] session Session object
 
375
   * @param[in] session Session pointer
262
376
   * @param[in] monitored Descriptor for the resource which will be participating
263
377
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
264
378
   */
265
 
  void registerResourceForStatement(Session::reference session,
 
379
  void registerResourceForStatement(Session *session,
266
380
                                    plugin::MonitoredInTransaction *monitored,
267
381
                                    plugin::TransactionalStorageEngine *engine);
268
382
 
280
394
   * per statement, and therefore should not need to be idempotent.
281
395
   * Put in assert()s to test this.
282
396
   *
283
 
   * @param[in] session Session object
 
397
   * @param[in] session Session pointer
284
398
   * @param[in] monitored Descriptor for the resource which will be participating
285
399
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
286
400
   * @param[in] resource_manager Pointer to the XaResourceManager resource manager
287
401
   */
288
 
  void registerResourceForStatement(Session::reference session,
 
402
  void registerResourceForStatement(Session *session,
289
403
                                    plugin::MonitoredInTransaction *monitored,
290
404
                                    plugin::TransactionalStorageEngine *engine,
291
405
                                    plugin::XaResourceManager *resource_manager);
314
428
   * time when this method is called except from the
315
429
   * TransactionServices::registerResourceForStatement method.
316
430
   */
317
 
  void registerResourceForTransaction(Session::reference session,
 
431
  void registerResourceForTransaction(Session *session,
318
432
                                      plugin::MonitoredInTransaction *monitored,
319
433
                                      plugin::TransactionalStorageEngine *engine);
320
 
 
321
 
  void registerResourceForTransaction(Session::reference session,
 
434
  void registerResourceForTransaction(Session *session,
322
435
                                      plugin::MonitoredInTransaction *monitored,
323
436
                                      plugin::TransactionalStorageEngine *engine,
324
437
                                      plugin::XaResourceManager *resource_manager);
325
438
 
 
439
  uint64_t getCurrentTransactionId(Session *session);
 
440
 
326
441
  void allocateNewTransactionId();
327
442
 
328
443
  /**************
332
447
  /**
333
448
   * Send server startup event.
334
449
   *
335
 
   * @param session Session object
 
450
   * @param session Session pointer
336
451
   *
337
452
   * @retval true Success
338
453
   * @retval false Failure
339
454
   */
340
 
  bool sendStartupEvent(Session::reference session);
 
455
  bool sendStartupEvent(Session *session);
341
456
 
342
457
  /**
343
458
   * Send server shutdown event.
344
459
   *
345
 
   * @param session Session object
 
460
   * @param session Session pointer
346
461
   *
347
462
   * @retval true Success
348
463
   * @retval false Failure
349
464
   */
350
 
  bool sendShutdownEvent(Session::reference session);
 
465
  bool sendShutdownEvent(Session *session);
351
466
 
352
467
private:
353
468
 
354
469
  /**
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);
513
 
 
514
 
  /**
515
470
   * Checks if a field has been updated 
516
471
   *
517
472
   * @param current_field Pointer to the field to check if it is updated 
518
 
   * @param table Table object containing update information
 
473
   * @in_table Pointer to the Table containing update information
519
474
   * @param old_record Pointer to the raw bytes representing the old record/row
520
475
   * @param new_record Pointer to the raw bytes representing the new record/row
521
476
   */
522
477
  bool isFieldUpdated(Field *current_field,
523
 
                      Table &table,
 
478
                      Table *in_table,
524
479
                      const unsigned char *old_record,
525
480
                      const unsigned char *new_record);
526
481
 
531
486
   * message associated with Session. We create a totally new message and
532
487
   * use it.
533
488
   *
534
 
   * @param session Session object
 
489
   * @param session Session pointer
535
490
   * @param event Event message to send
536
491
   *
537
492
   * @note Used by the public Events API.
538
493
   *
539
494
   * @returns Non-zero on error
540
495
   */
541
 
  int sendEvent(Session::reference session, const message::Event &event);
 
496
  int sendEvent(Session *session, const message::Event &event);
542
497
 
543
498
  /**
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.
 
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
554
506
   */
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);
 
507
  bool useExistingUpdateHeader(message::Statement &statement,
 
508
                               Table *in_table,
 
509
                               const unsigned char *old_record,
 
510
                               const unsigned char *new_record);
561
511
 
562
512
  plugin::XaStorageEngine *xa_storage_engine;
563
513
};