~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

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