~drizzle-trunk/drizzle/development

1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
5
 *  Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; version 2 of the License.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
/**
22
 * @file Transaction processing code
23
 */
24
1273.1.7 by Jay Pipes
Another lint cleanup.
25
#ifndef DRIZZLED_TRANSACTION_SERVICES_H
26
#define DRIZZLED_TRANSACTION_SERVICES_H
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
27
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
28
#include "drizzled/atomics.h"
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
29
#include "drizzled/message/transaction.pb.h"
30
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
31
namespace drizzled
32
{
33
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
34
/* some forward declarations needed */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
35
namespace plugin
36
{
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
37
  class MonitoredInTransaction;
38
  class XaResourceManager;
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
39
  class TransactionalStorageEngine;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
40
}
41
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
42
class Session;
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
43
class NamedSavepoint;
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
44
class Field;
45
 
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
46
/**
47
 * This is a class which manages the XA transaction processing
48
 * in the server
49
 */
50
class TransactionServices
51
{
52
public:
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
53
  static const size_t DEFAULT_RECORD_SIZE= 100;
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
54
  typedef uint64_t TransactionId;
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
55
  /**
56
   * Constructor
57
   */
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
58
  TransactionServices()
59
  {
60
    /**
61
     * @todo set transaction ID to the last one from an applier...
62
     */
63
    current_transaction_id= 0;
64
  }
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
65
66
  /**
67
   * Singleton method
68
   * Returns the singleton instance of TransactionServices
69
   */
70
  static inline TransactionServices &singleton()
71
  {
72
    static TransactionServices transaction_services;
73
    return transaction_services;
74
  }
1405.3.6 by Jay Pipes
Here, we do two main things:
75
76
  /**
77
   * Returns true if the transaction manager should construct
78
   * Transaction and Statement messages, false otherwise.
79
   */
80
  bool shouldConstructMessages();
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
81
  /**
82
   * Method which returns the active Transaction message
83
   * for the supplied Session.  If one is not found, a new Transaction
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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.
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
88
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
91
   */
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
92
  message::Transaction *getActiveTransactionMessage(Session *in_session,
93
                                                    bool should_inc_trx_id= true);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
103
   */
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
104
  void initTransactionMessage(message::Transaction &in_transaction,
105
                              Session *in_session,
106
                              bool should_inc_trx_id);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
107
  /** 
108
   * Helper method which finalizes data members for the 
109
   * supplied transaction's context.
110
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
111
   * @param in_transaction The transaction message to finalize 
112
   * @param in_session The Session processing this transaction
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
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);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
121
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
122
  /**
123
   * Helper method which initializes a Statement message
124
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
128
   */
129
  void initStatementMessage(message::Statement &statement,
130
                            message::Statement::Type in_type,
131
                            Session *in_session);
132
  /**
133
   * Finalizes a Statement message and sets the Session's statement
134
   * message to NULL.
135
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
136
   * @param statement The statement to initialize
137
   * @param in_session The session processing this statement
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
138
   */
139
  void finalizeStatementMessage(message::Statement &statement,
140
                                Session *in_session);
141
  /** Helper method which returns an initialized Statement message for methods
142
   * doing insertion of data.
143
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
147
   */
148
  message::Statement &getInsertStatement(Session *in_session,
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
149
                                         Table *in_table,
150
                                         uint32_t *next_segment_id);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
151
152
  /**
153
   * Helper method which initializes the header message for
154
   * insert operations.
155
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
172
   */
173
  message::Statement &getUpdateStatement(Session *in_session,
174
                                         Table *in_table,
175
                                         const unsigned char *old_record, 
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
176
                                         const unsigned char *new_record,
177
                                         uint32_t *next_segment_id);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
178
  /**
179
   * Helper method which initializes the header message for
180
   * update operations.
181
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
200
   */
201
  message::Statement &getDeleteStatement(Session *in_session,
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
202
                                         Table *in_table,
203
                                         uint32_t *next_segment_id);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
204
205
  /**
206
   * Helper method which initializes the header message for
207
   * insert operations.
208
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
220
   * @param in_session Pointer to the Session committing the transaction
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
221
   */
1405.3.6 by Jay Pipes
Here, we do two main things:
222
  int commitTransactionMessage(Session *in_session);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
223
  /** 
224
   * Marks the current active transaction message as being rolled back and
225
   * pushes the transaction message out to replicators.
226
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
227
   * @param in_session Pointer to the Session committing the transaction
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
228
   */
229
  void rollbackTransactionMessage(Session *in_session);
230
  /**
231
   * Creates a new InsertRecord GPB message and pushes it to
232
   * replicators.
233
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
234
   * @param in_session Pointer to the Session which has inserted a record
235
   * @param in_table Pointer to the Table containing insert information
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
236
   *
237
   * Grr, returning "true" here on error because of the cursor
238
   * reversed bool return crap...fix that.
239
   */
240
  bool insertRecord(Session *in_session, Table *in_table);
241
  /**
242
   * Creates a new UpdateRecord GPB message and pushes it to
243
   * replicators.
244
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
245
   * @param in_session Pointer to the Session which has updated a record
246
   * @param in_table Pointer to the Table containing update information
247
   * @param old_record Pointer to the raw bytes representing the old record/row
248
   * @param new_record Pointer to the raw bytes representing the new record/row 
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
249
   */
250
  void updateRecord(Session *in_session, 
251
                    Table *in_table, 
252
                    const unsigned char *old_record, 
253
                    const unsigned char *new_record);
254
  /**
255
   * Creates a new DeleteRecord GPB message and pushes it to
256
   * replicators.
257
   *
1730.5.1 by David Shrewsbury
Use the update record, not insert record, when record DELETE operations during REPLACE.
258
   * @param in_session Pointer to the Session which has deleted a record
259
   * @param in_table Pointer to the Table containing delete information
260
   * @param use_update_record If true, uses the values from the update row instead
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
261
   */
1730.5.1 by David Shrewsbury
Use the update record, not insert record, when record DELETE operations during REPLACE.
262
  void deleteRecord(Session *in_session, Table *in_table, bool use_update_record= false);
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
263
  /**
264
   * Creates a CreateSchema Statement GPB message and adds it
265
   * to the Session's active Transaction GPB message for pushing
266
   * out to the replicator streams.
267
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
268
   * @param[in] in_session Pointer to the Session which issued the statement
269
   * @param[in] schema message::Schema message describing new schema
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
270
   */
271
  void createSchema(Session *in_session, const message::Schema &schema);
272
  /**
273
   * Creates a DropSchema Statement GPB message and adds it
274
   * to the Session's active Transaction GPB message for pushing
275
   * out to the replicator streams.
276
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
277
   * @param[in] in_session Pointer to the Session which issued the statement
278
   * @param[in] schema_name message::Schema message describing new schema
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
279
   */
280
  void dropSchema(Session *in_session, const std::string &schema_name);
281
  /**
282
   * Creates a CreateTable Statement GPB message and adds it
283
   * to the Session's active Transaction GPB message for pushing
284
   * out to the replicator streams.
285
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
286
   * @param[in] in_session Pointer to the Session which issued the statement
287
   * @param[in] table message::Table message describing new schema
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
288
   */
289
  void createTable(Session *in_session, const message::Table &table);
290
  /**
291
   * Creates a DropTable Statement GPB message and adds it
292
   * to the Session's active Transaction GPB message for pushing
293
   * out to the replicator streams.
294
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
295
   * @param[in] in_session Pointer to the Session which issued the statement
296
   * @param[in] schema_name The schema of the table being dropped
297
   * @param[in] table_name The table name of the table being dropped
298
   * @param[in] if_exists Did the user specify an IF EXISTS clause?
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
299
   */
300
  void dropTable(Session *in_session,
301
                     const std::string &schema_name,
302
                     const std::string &table_name,
303
                     bool if_exists);
304
  /**
305
   * Creates a TruncateTable Statement GPB message and adds it
306
   * to the Session's active Transaction GPB message for pushing
307
   * out to the replicator streams.
308
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
309
   * @param[in] in_session Pointer to the Session which issued the statement
310
   * @param[in] in_table The Table being truncated
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
311
   */
312
  void truncateTable(Session *in_session, Table *in_table);
313
  /**
314
   * Creates a new RawSql GPB message and pushes it to 
315
   * replicators.
316
   *
317
   * @TODO With a real data dictionary, this really shouldn't
318
   * be needed.  CREATE TABLE would map to insertRecord call
319
   * on the I_S, etc.  Not sure what to do with administrative
320
   * commands like CHECK TABLE, though..
321
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
322
   * @param in_session Pointer to the Session which issued the statement
323
   * @param query Query string
1336.2.2 by Jay Pipes
NO CODE CHANGES - Simply moves pieces of ReplicationServices to TransactionServices. Preparation for making the ReplicationServices component only responsible for communication between replicators, appliers, publishers, and subscribers.
324
   */
325
  void rawStatement(Session *in_session, const std::string &query);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
326
  /* transactions: interface to plugin::StorageEngine functions */
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
327
  int commitPhaseOne(Session *session, bool all);
328
  int rollbackTransaction(Session *session, bool all);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
329
330
  /* transactions: these functions never call plugin::StorageEngine functions directly */
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
331
  int commitTransaction(Session *session, bool all);
332
  int autocommitOrRollback(Session *session, int error);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
333
334
  /* savepoints */
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
335
  int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
336
  int setSavepoint(Session *session, NamedSavepoint &sv);
337
  int releaseSavepoint(Session *session, NamedSavepoint &sv);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
338
1273.1.22 by Jay Pipes
Automates registration of statement transaction resources. No more need for storage engines to call TransactionServices::trans_register_ha(session, false, engine). yeah \o/
339
  /**
340
   * Marks a storage engine as participating in a statement
341
   * transaction.
342
   *
343
   * @note
344
   * 
345
   * This method is idempotent
346
   *
347
   * @todo
348
   *
349
   * This method should not be called more than once per resource
350
   * per statement, and therefore should not need to be idempotent.
351
   * Put in assert()s to test this.
352
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
353
   * @param[in] session Session pointer
354
   * @param[in] monitored Descriptor for the resource which will be participating
355
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
1273.1.22 by Jay Pipes
Automates registration of statement transaction resources. No more need for storage engines to call TransactionServices::trans_register_ha(session, false, engine). yeah \o/
356
   */
357
  void registerResourceForStatement(Session *session,
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
358
                                    plugin::MonitoredInTransaction *monitored,
1273.1.22 by Jay Pipes
Automates registration of statement transaction resources. No more need for storage engines to call TransactionServices::trans_register_ha(session, false, engine). yeah \o/
359
                                    plugin::TransactionalStorageEngine *engine);
360
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
361
  /**
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
362
   * Marks an XA storage engine as participating in a statement
363
   * transaction.
364
   *
365
   * @note
366
   * 
367
   * This method is idempotent
368
   *
369
   * @todo
370
   *
371
   * This method should not be called more than once per resource
372
   * per statement, and therefore should not need to be idempotent.
373
   * Put in assert()s to test this.
374
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
375
   * @param[in] session Session pointer
376
   * @param[in] monitored Descriptor for the resource which will be participating
377
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
378
   * @param[in] resource_manager Pointer to the XaResourceManager resource manager
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
379
   */
380
  void registerResourceForStatement(Session *session,
381
                                    plugin::MonitoredInTransaction *monitored,
382
                                    plugin::TransactionalStorageEngine *engine,
383
                                    plugin::XaResourceManager *resource_manager);
384
385
  /**
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
386
   * Registers a resource manager in the "normal" transaction.
387
   *
388
   * @note
389
   *
390
   * This method is idempotent and must be idempotent
391
   * because it can be called both by the above 
392
   * TransactionServices::registerResourceForStatement(),
393
   * which occurs at the beginning of each SQL statement,
394
   * and also manually when a BEGIN WORK/START TRANSACTION
395
   * statement is executed. If the latter case (BEGIN WORK)
396
   * is called, then subsequent contained statement transactions
397
   * will call this method as well.
398
   *
399
   * @note
400
   *
401
   * This method checks to see if the supplied resource
402
   * is also registered in the statement transaction, and
403
   * if not, registers the resource in the statement
404
   * transaction.  This happens ONLY when the user has
405
   * called BEGIN WORK/START TRANSACTION, which is the only
406
   * time when this method is called except from the
407
   * TransactionServices::registerResourceForStatement method.
408
   */
409
  void registerResourceForTransaction(Session *session,
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
410
                                      plugin::MonitoredInTransaction *monitored,
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
411
                                      plugin::TransactionalStorageEngine *engine);
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
412
  void registerResourceForTransaction(Session *session,
413
                                      plugin::MonitoredInTransaction *monitored,
414
                                      plugin::TransactionalStorageEngine *engine,
415
                                      plugin::XaResourceManager *resource_manager);
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
416
  TransactionId getNextTransactionId()
417
  {
418
    return current_transaction_id.increment();
419
  }
420
  TransactionId getCurrentTransactionId()
421
  {
422
    return current_transaction_id;
423
  }
424
  /**
425
   * DEBUG ONLY.  See plugin::TransactionLog::truncate()
426
   */
427
  void resetTransactionId()
428
  {
429
    current_transaction_id= 0;
430
  }
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
431
432
  /**************
433
   * Events API
434
   **************/
435
436
  /**
437
   * Send server startup event.
438
   *
439
   * @param session Session pointer
440
   *
441
   * @retval true Success
442
   * @retval false Failure
443
   */
444
  bool sendStartupEvent(Session *session);
445
446
  /**
447
   * Send server shutdown event.
448
   *
449
   * @param session Session pointer
450
   *
451
   * @retval true Success
452
   * @retval false Failure
453
   */
454
  bool sendShutdownEvent(Session *session);
455
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
456
private:
457
  atomic<TransactionId> current_transaction_id;
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
458
459
  /**
460
   * Checks if a field has been updated 
461
   *
462
   * @param current_field Pointer to the field to check if it is updated 
463
   * @in_table Pointer to the Table containing update information
464
   * @param old_record Pointer to the raw bytes representing the old record/row
465
   * @param new_record Pointer to the raw bytes representing the new record/row
466
   */
467
  bool isFieldUpdated(Field *current_field,
468
                      Table *in_table,
469
                      const unsigned char *old_record,
470
                      const unsigned char *new_record);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
471
472
  /**
473
   * Create a Transaction that contains event information and send it off.
474
   *
475
   * This differs from other uses of Transaction in that we don't use the
476
   * message associated with Session. We create a totally new message and
477
   * use it.
478
   *
479
   * @param session Session pointer
480
   * @param event Event message to send
481
   *
482
   * @note Used by the public Events API.
483
   *
484
   * @returns Non-zero on error
485
   */
486
  int sendEvent(Session *session, const message::Event &event);
487
1819.4.4 by David Shrewsbury
Merge from trunk and resolve conflicts
488
  /**
1821.2.1 by Joseph Daly
fix 655352
489
   * Helper method which checks the UpdateHeader to determine 
490
   * if it needs to be finalized.  
491
   *
492
   * @param[in] statement Statement message container to check 
493
   * @param[in] in_table Pointer to the Table being updated
494
   * @param[in] old_record Pointer to the old data in the record
495
   * @param[in] new_record Pointer to the new data in the record
496
   */
497
  bool useExistingUpdateHeader(message::Statement &statement,
498
                               Table *in_table,
499
                               const unsigned char *old_record,
500
                               const unsigned char *new_record);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
501
};
502
503
} /* namespace drizzled */
504
1273.1.7 by Jay Pipes
Another lint cleanup.
505
#endif /* DRIZZLED_TRANSACTION_SERVICES_H */