~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;
1856.2.6 by Joseph Daly
merge trunk
39
  class XaStorageEngine;
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
40
  class TransactionalStorageEngine;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
41
}
42
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
43
class Session;
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
44
class NamedSavepoint;
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
45
class Field;
1856.2.1 by Joseph Daly
use transaction_id in innodb for transaction log
46
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
47
/**
48
 * This is a class which manages the XA transaction processing
49
 * in the server
50
 */
51
class TransactionServices
52
{
53
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.
54
  static const size_t DEFAULT_RECORD_SIZE= 100;
1856.2.6 by Joseph Daly
merge trunk
55
  
56
  TransactionServices();
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
57
58
  /**
59
   * Singleton method
60
   * Returns the singleton instance of TransactionServices
61
   */
62
  static inline TransactionServices &singleton()
63
  {
64
    static TransactionServices transaction_services;
65
    return transaction_services;
66
  }
1405.3.6 by Jay Pipes
Here, we do two main things:
67
68
  /**
69
   * Returns true if the transaction manager should construct
70
   * Transaction and Statement messages, false otherwise.
71
   */
72
  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.
73
  /**
74
   * Method which returns the active Transaction message
75
   * 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.
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.
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.
80
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
83
   */
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
84
  message::Transaction *getActiveTransactionMessage(Session *in_session,
85
                                                    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.
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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
95
   */
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
96
  void initTransactionMessage(message::Transaction &in_transaction,
97
                              Session *in_session,
98
                              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.
99
  /** 
100
   * Helper method which finalizes data members for the 
101
   * supplied transaction's context.
102
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
103
   * @param in_transaction The transaction message to finalize 
104
   * @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.
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);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
113
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.
114
  /**
115
   * Helper method which initializes a Statement message
116
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
120
   */
121
  void initStatementMessage(message::Statement &statement,
122
                            message::Statement::Type in_type,
123
                            Session *in_session);
124
  /**
125
   * Finalizes a Statement message and sets the Session's statement
126
   * message to NULL.
127
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
128
   * @param statement The statement to initialize
129
   * @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.
130
   */
131
  void finalizeStatementMessage(message::Statement &statement,
132
                                Session *in_session);
133
  /** Helper method which returns an initialized Statement message for methods
134
   * doing insertion of data.
135
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
139
   */
140
  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.
141
                                         Table *in_table,
142
                                         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.
143
144
  /**
145
   * Helper method which initializes the header message for
146
   * insert operations.
147
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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
  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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
164
   */
165
  message::Statement &getUpdateStatement(Session *in_session,
166
                                         Table *in_table,
167
                                         const unsigned char *old_record, 
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
168
                                         const unsigned char *new_record,
169
                                         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.
170
  /**
171
   * Helper method which initializes the header message for
172
   * update operations.
173
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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.
192
   */
193
  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.
194
                                         Table *in_table,
195
                                         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.
196
197
  /**
198
   * Helper method which initializes the header message for
199
   * insert operations.
200
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
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
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
  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
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
212
   * @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.
213
   */
1405.3.6 by Jay Pipes
Here, we do two main things:
214
  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.
215
  /** 
216
   * Marks the current active transaction message as being rolled back and
217
   * pushes the transaction message out to replicators.
218
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
219
   * @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.
220
   */
221
  void rollbackTransactionMessage(Session *in_session);
222
  /**
223
   * Creates a new InsertRecord GPB message and pushes it to
224
   * replicators.
225
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
226
   * @param in_session Pointer to the Session which has inserted a record
227
   * @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.
228
   *
229
   * Grr, returning "true" here on error because of the cursor
230
   * reversed bool return crap...fix that.
231
   */
232
  bool insertRecord(Session *in_session, Table *in_table);
233
  /**
234
   * Creates a new UpdateRecord GPB message and pushes it to
235
   * replicators.
236
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
237
   * @param in_session Pointer to the Session which has updated a record
238
   * @param in_table Pointer to the Table containing update information
239
   * @param old_record Pointer to the raw bytes representing the old record/row
240
   * @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.
241
   */
242
  void updateRecord(Session *in_session, 
243
                    Table *in_table, 
244
                    const unsigned char *old_record, 
245
                    const unsigned char *new_record);
246
  /**
247
   * Creates a new DeleteRecord GPB message and pushes it to
248
   * replicators.
249
   *
1730.5.1 by David Shrewsbury
Use the update record, not insert record, when record DELETE operations during REPLACE.
250
   * @param in_session Pointer to the Session which has deleted a record
251
   * @param in_table Pointer to the Table containing delete information
252
   * @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.
253
   */
1730.5.1 by David Shrewsbury
Use the update record, not insert record, when record DELETE operations during REPLACE.
254
  void deleteRecord(Session *in_session, Table *in_table, bool use_update_record= false);
1861.6.3 by David Shrewsbury
Move GPB manipulation code out of Session and into TransactionServices.
255
256
  /**
257
   * Used to undo effects of a failed statement.
258
   *
259
   * An SQL statement, like an UPDATE, that affects multiple rows could
260
   * potentially fail mid-way through processing the rows. In such a case,
261
   * the successfully modified rows that preceeded the failing row would
262
   * have been added to the Statement message. This method is used for
263
   * rolling back that change.
264
   *
265
   * @note
266
   * This particular failure is seen on column constraint violations
267
   * during a multi-row UPDATE and a multi-row INSERT..SELECT.
268
   *
269
   * @param in_session Pointer to the Session containing the Statement
270
   * @param count The number of records to remove from Statement.
271
   *
272
   * @retval true Successfully removed 'count' records
273
   * @retval false Failure
274
   */
275
  bool removeStatementRecords(Session *in_session, uint32_t count);
276
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.
277
  /**
278
   * Creates a CreateSchema Statement GPB message and adds it
279
   * to the Session's active Transaction GPB message for pushing
280
   * out to the replicator streams.
281
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
282
   * @param[in] in_session Pointer to the Session which issued the statement
283
   * @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.
284
   */
285
  void createSchema(Session *in_session, const message::Schema &schema);
286
  /**
287
   * Creates a DropSchema Statement GPB message and adds it
288
   * to the Session's active Transaction GPB message for pushing
289
   * out to the replicator streams.
290
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
291
   * @param[in] in_session Pointer to the Session which issued the statement
292
   * @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.
293
   */
294
  void dropSchema(Session *in_session, const std::string &schema_name);
295
  /**
296
   * Creates a CreateTable Statement GPB message and adds it
297
   * to the Session's active Transaction GPB message for pushing
298
   * out to the replicator streams.
299
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
300
   * @param[in] in_session Pointer to the Session which issued the statement
301
   * @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.
302
   */
303
  void createTable(Session *in_session, const message::Table &table);
304
  /**
305
   * Creates a DropTable 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] schema_name The schema of the table being dropped
311
   * @param[in] table_name The table name of the table being dropped
312
   * @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.
313
   */
314
  void dropTable(Session *in_session,
315
                     const std::string &schema_name,
316
                     const std::string &table_name,
317
                     bool if_exists);
318
  /**
319
   * Creates a TruncateTable Statement GPB message and adds it
320
   * to the Session's active Transaction GPB message for pushing
321
   * out to the replicator streams.
322
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
323
   * @param[in] in_session Pointer to the Session which issued the statement
324
   * @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.
325
   */
326
  void truncateTable(Session *in_session, Table *in_table);
327
  /**
328
   * Creates a new RawSql GPB message and pushes it to 
329
   * replicators.
330
   *
331
   * @TODO With a real data dictionary, this really shouldn't
332
   * be needed.  CREATE TABLE would map to insertRecord call
333
   * on the I_S, etc.  Not sure what to do with administrative
334
   * commands like CHECK TABLE, though..
335
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
336
   * @param in_session Pointer to the Session which issued the statement
337
   * @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.
338
   */
339
  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,
340
  /* transactions: interface to plugin::StorageEngine functions */
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
341
  int commitPhaseOne(Session *session, bool all);
342
  int rollbackTransaction(Session *session, bool all);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
343
344
  /* transactions: these functions never call plugin::StorageEngine functions directly */
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
345
  int commitTransaction(Session *session, bool all);
346
  int autocommitOrRollback(Session *session, int error);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
347
348
  /* savepoints */
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
349
  int rollbackToSavepoint(Session *session, NamedSavepoint &sv);
350
  int setSavepoint(Session *session, NamedSavepoint &sv);
351
  int releaseSavepoint(Session *session, NamedSavepoint &sv);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
352
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/
353
  /**
354
   * Marks a storage engine as participating in a statement
355
   * transaction.
356
   *
357
   * @note
358
   * 
359
   * This method is idempotent
360
   *
361
   * @todo
362
   *
363
   * This method should not be called more than once per resource
364
   * per statement, and therefore should not need to be idempotent.
365
   * Put in assert()s to test this.
366
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
367
   * @param[in] session Session pointer
368
   * @param[in] monitored Descriptor for the resource which will be participating
369
   * @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/
370
   */
371
  void registerResourceForStatement(Session *session,
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
372
                                    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/
373
                                    plugin::TransactionalStorageEngine *engine);
374
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
375
  /**
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
376
   * Marks an XA storage engine as participating in a statement
377
   * transaction.
378
   *
379
   * @note
380
   * 
381
   * This method is idempotent
382
   *
383
   * @todo
384
   *
385
   * This method should not be called more than once per resource
386
   * per statement, and therefore should not need to be idempotent.
387
   * Put in assert()s to test this.
388
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
389
   * @param[in] session Session pointer
390
   * @param[in] monitored Descriptor for the resource which will be participating
391
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
392
   * @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
393
   */
394
  void registerResourceForStatement(Session *session,
395
                                    plugin::MonitoredInTransaction *monitored,
396
                                    plugin::TransactionalStorageEngine *engine,
397
                                    plugin::XaResourceManager *resource_manager);
398
399
  /**
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
400
   * Registers a resource manager in the "normal" transaction.
401
   *
402
   * @note
403
   *
404
   * This method is idempotent and must be idempotent
405
   * because it can be called both by the above 
406
   * TransactionServices::registerResourceForStatement(),
407
   * which occurs at the beginning of each SQL statement,
408
   * and also manually when a BEGIN WORK/START TRANSACTION
409
   * statement is executed. If the latter case (BEGIN WORK)
410
   * is called, then subsequent contained statement transactions
411
   * will call this method as well.
412
   *
413
   * @note
414
   *
415
   * This method checks to see if the supplied resource
416
   * is also registered in the statement transaction, and
417
   * if not, registers the resource in the statement
418
   * transaction.  This happens ONLY when the user has
419
   * called BEGIN WORK/START TRANSACTION, which is the only
420
   * time when this method is called except from the
421
   * TransactionServices::registerResourceForStatement method.
422
   */
423
  void registerResourceForTransaction(Session *session,
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
424
                                      plugin::MonitoredInTransaction *monitored,
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
425
                                      plugin::TransactionalStorageEngine *engine);
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
426
  void registerResourceForTransaction(Session *session,
427
                                      plugin::MonitoredInTransaction *monitored,
428
                                      plugin::TransactionalStorageEngine *engine,
429
                                      plugin::XaResourceManager *resource_manager);
1856.2.1 by Joseph Daly
use transaction_id in innodb for transaction log
430
431
  uint64_t getCurrentTransactionId(Session *session);
1856.2.7 by Joseph Daly
create schema changes
432
1856.2.8 by Joseph Daly
working alter, drop, create schema
433
  void allocateNewTransactionId();
1856.2.1 by Joseph Daly
use transaction_id in innodb for transaction log
434
 
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
435
  /**************
436
   * Events API
437
   **************/
438
439
  /**
440
   * Send server startup event.
441
   *
442
   * @param session Session pointer
443
   *
444
   * @retval true Success
445
   * @retval false Failure
446
   */
447
  bool sendStartupEvent(Session *session);
448
449
  /**
450
   * Send server shutdown event.
451
   *
452
   * @param session Session pointer
453
   *
454
   * @retval true Success
455
   * @retval false Failure
456
   */
457
  bool sendShutdownEvent(Session *session);
458
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
459
private:
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
460
461
  /**
462
   * Checks if a field has been updated 
463
   *
464
   * @param current_field Pointer to the field to check if it is updated 
465
   * @in_table Pointer to the Table containing update information
466
   * @param old_record Pointer to the raw bytes representing the old record/row
467
   * @param new_record Pointer to the raw bytes representing the new record/row
468
   */
469
  bool isFieldUpdated(Field *current_field,
470
                      Table *in_table,
471
                      const unsigned char *old_record,
472
                      const unsigned char *new_record);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
473
474
  /**
475
   * Create a Transaction that contains event information and send it off.
476
   *
477
   * This differs from other uses of Transaction in that we don't use the
478
   * message associated with Session. We create a totally new message and
479
   * use it.
480
   *
481
   * @param session Session pointer
482
   * @param event Event message to send
483
   *
484
   * @note Used by the public Events API.
485
   *
486
   * @returns Non-zero on error
487
   */
488
  int sendEvent(Session *session, const message::Event &event);
489
1819.4.4 by David Shrewsbury
Merge from trunk and resolve conflicts
490
  /**
1821.2.1 by Joseph Daly
fix 655352
491
   * Helper method which checks the UpdateHeader to determine 
492
   * if it needs to be finalized.  
493
   *
494
   * @param[in] statement Statement message container to check 
495
   * @param[in] in_table Pointer to the Table being updated
496
   * @param[in] old_record Pointer to the old data in the record
497
   * @param[in] new_record Pointer to the new data in the record
498
   */
499
  bool useExistingUpdateHeader(message::Statement &statement,
500
                               Table *in_table,
501
                               const unsigned char *old_record,
502
                               const unsigned char *new_record);
1856.2.4 by Joseph Daly
add global_resource_manager for non innodb engines
503
1856.2.6 by Joseph Daly
merge trunk
504
  plugin::XaStorageEngine *xa_storage_engine;
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
505
};
506
507
} /* namespace drizzled */
508
1273.1.7 by Jay Pipes
Another lint cleanup.
509
#endif /* DRIZZLED_TRANSACTION_SERVICES_H */