~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
25
#pragma once
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
26
2154.2.8 by Brian Aker
Additional cleanup.
27
#include <drizzled/atomics.h>
28
#include <drizzled/message/transaction.pb.h>
2241.4.14 by Stewart Smith
remove some includes from my_sys.h and instead only include where needed. This helps reduce the number of files that have to be rebuilt when you change some of the more widely included header files (such as the drizzled::identifier ones)
29
#include <drizzled/identifier.h>
2154.2.8 by Brian Aker
Additional cleanup.
30
#include <drizzled/message/schema.h>
2241.2.14 by Olaf van der Spek
Refactor
31
#include <drizzled/message/table.h>
2154.2.8 by Brian Aker
Additional cleanup.
32
#include <drizzled/session.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.
33
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
34
#include <drizzled/visibility.h>
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
35
2241.2.14 by Olaf van der Spek
Refactor
36
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
37
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
38
/**
39
 * This is a class which manages the XA transaction processing
40
 * in the server
41
 */
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
42
class DRIZZLED_API TransactionServices
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
43
{
44
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.
45
  static const size_t DEFAULT_RECORD_SIZE= 100;
1856.2.6 by Joseph Daly
merge trunk
46
  
1405.3.6 by Jay Pipes
Here, we do two main things:
47
  /**
48
   * Returns true if the transaction manager should construct
49
   * Transaction and Statement messages, false otherwise.
50
   */
2318.6.61 by Olaf van der Spek
Refactor
51
  static bool shouldConstructMessages();
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
52
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
  /**
54
   * Finalizes a Statement message and sets the Session's statement
55
   * message to NULL.
56
   *
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
57
   * @param statement The statement to initialize
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
58
   * @param session The Session object 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.
59
   */
2318.6.61 by Olaf van der Spek
Refactor
60
  static void finalizeStatementMessage(message::Statement&, Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
61
1976.8.1 by David Shrewsbury
Add ability to rollback a statement, change to use 1 GPB Statement message per SQL statement. NOTE: segmented statements not handled yet.
62
  /**
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.
63
   * Creates a new InsertRecord GPB message and pushes it to
64
   * replicators.
65
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
66
   * @param session Session object which has inserted a record
67
   * @param table Table object 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.
68
   *
69
   * Grr, returning "true" here on error because of the cursor
70
   * reversed bool return crap...fix that.
71
   */
2318.6.61 by Olaf van der Spek
Refactor
72
  static bool insertRecord(Session&, Table &in_table);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
73
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.
74
  /**
75
   * Creates a new UpdateRecord GPB message and pushes it to
76
   * replicators.
77
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
78
   * @param session Session object which has updated a record
79
   * @param table Table object containing update information
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
80
   * @param old_record Pointer to the raw bytes representing the old record/row
81
   * @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.
82
   */
2318.6.61 by Olaf van der Spek
Refactor
83
  static void updateRecord(Session&, 
84
                    Table&, 
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.
85
                    const unsigned char *old_record, 
86
                    const unsigned char *new_record);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
87
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
  /**
89
   * Creates a new DeleteRecord GPB message and pushes it to
90
   * replicators.
91
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
92
   * @param session Session object which has deleted a record
93
   * @param table Table object containing delete information
1730.5.1 by David Shrewsbury
Use the update record, not insert record, when record DELETE operations during REPLACE.
94
   * @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.
95
   */
2318.6.61 by Olaf van der Spek
Refactor
96
  static void deleteRecord(Session&, Table&, bool use_update_record= false);
1861.6.3 by David Shrewsbury
Move GPB manipulation code out of Session and into TransactionServices.
97
98
  /**
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
   * Creates a CreateSchema Statement GPB message and adds it
100
   * to the Session's active Transaction GPB message for pushing
101
   * out to the replicator streams.
102
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
103
   * @param[in] session Session object which issued the statement
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
104
   * @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.
105
   */
2318.6.61 by Olaf van der Spek
Refactor
106
  static void createSchema(Session&, const message::Schema &schema);
2052 by Brian Aker
Fix additional member of trans services to handle identifier.
107
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.
108
  /**
109
   * Creates a DropSchema Statement GPB message and adds it
110
   * to the Session's active Transaction GPB message for pushing
111
   * out to the replicator streams.
112
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
113
   * @param[in] session Session object which issued the statement
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
114
   * @param[in] identifier Identifier for the schema to drop
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.
115
   */
2318.6.61 by Olaf van der Spek
Refactor
116
  static void dropSchema(Session&,
2246.4.9 by Olaf van der Spek
Remove const_reference and reference from identifier::Schema
117
                  const identifier::Schema& identifier,
2172.3.1 by Brian Aker
Merge in my patch for having some schema/table not replicated.
118
                  message::schema::const_reference schema);
2052 by Brian Aker
Fix additional member of trans services to handle identifier.
119
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
  /**
2078.1.1 by David Shrewsbury
Push ALTER SCHEMA through replication stream as proper GPB message instead of RAW_SQL.
121
   * Creates an AlterSchema Statement GPB message and adds it
122
   * to the Session's active Transaction GPB message for pushing
123
   * out to the replicator streams.
124
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
125
   * @param[in] session Session object which issued the statement
2078.1.1 by David Shrewsbury
Push ALTER SCHEMA through replication stream as proper GPB message instead of RAW_SQL.
126
   * @param[in] old_schema Original schema definition
127
   * @param[in] new_schema New schema definition
128
   */
2318.6.61 by Olaf van der Spek
Refactor
129
  static void alterSchema(Session&,
2159.2.6 by Brian Aker
Finalize interface for schema.
130
                   const message::Schema &old_schema,
2078.1.1 by David Shrewsbury
Push ALTER SCHEMA through replication stream as proper GPB message instead of RAW_SQL.
131
                   const message::Schema &new_schema);
132
133
  /**
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.
134
   * Creates a CreateTable Statement GPB message and adds it
135
   * to the Session's active Transaction GPB message for pushing
136
   * out to the replicator streams.
137
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
138
   * @param[in] session Session object which issued the statement
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
139
   * @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.
140
   */
2318.6.61 by Olaf van der Spek
Refactor
141
  static void createTable(Session&, const message::Table&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
142
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
   * Creates a DropTable Statement GPB message and adds it
145
   * to the Session's active Transaction GPB message for pushing
146
   * out to the replicator streams.
147
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
148
   * @param[in] session Session object which issued the statement
2048.1.2 by David Shrewsbury
Change TransactionServices::dropTable() to take a TableIdentifier rather than strings.
149
   * @param[in] table Identifier for the table being dropped
2048.1.1 by David Shrewsbury
Re-add IF EXISTS support back in to transaction log so we can drop tables on master that are not on the slave.
150
   * @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.
151
   */
2318.6.61 by Olaf van der Spek
Refactor
152
  static void dropTable(Session&,
2246.4.10 by Olaf van der Spek
Remove const_reference and reference from identifier::Table
153
                 const identifier::Table& identifier,
2168.3.2 by Brian Aker
CREATE TABLE/SCHEMA now allow you to add REPLICATION to the list of items
154
                 message::table::const_reference table,
2048.1.2 by David Shrewsbury
Change TransactionServices::dropTable() to take a TableIdentifier rather than strings.
155
                 bool if_exists);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
156
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.
157
  /**
158
   * Creates a TruncateTable Statement GPB message and adds it
159
   * to the Session's active Transaction GPB message for pushing
160
   * out to the replicator streams.
161
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
162
   * @param[in] session Session object which issued the statement
163
   * @param[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.
164
   */
2318.6.61 by Olaf van der Spek
Refactor
165
  static void truncateTable(Session&, Table&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
166
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.
167
  /**
168
   * Creates a new RawSql GPB message and pushes it to 
169
   * replicators.
170
   *
171
   * @TODO With a real data dictionary, this really shouldn't
172
   * be needed.  CREATE TABLE would map to insertRecord call
173
   * on the I_S, etc.  Not sure what to do with administrative
174
   * commands like CHECK TABLE, though..
175
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
176
   * @param session Session object which issued the statement
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
177
   * @param query Query string
2211.2.1 by David Shrewsbury
Add raw_sql_schema member to Statement protobuf definition and set it in ALTER TABLE code path to current value associated with Session executing it.
178
   * @param schema Schema for the table affected by the raw SQL.
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
   */
2318.6.62 by Olaf van der Spek
Refactor
180
  static void rawStatement(Session&, const std::string &query, const std::string &schema);
2211.2.1 by David Shrewsbury
Add raw_sql_schema member to Statement protobuf definition and set it in ALTER TABLE code path to current value associated with Session executing it.
181
2318.6.62 by Olaf van der Spek
Refactor
182
  static void rawStatement(Session& session, const std::string& query)
2211.2.1 by David Shrewsbury
Add raw_sql_schema member to Statement protobuf definition and set it in ALTER TABLE code path to current value associated with Session executing it.
183
  {
184
    rawStatement(session, query, "");
185
  }
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
186
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
187
  /* transactions: interface to plugin::StorageEngine functions */
2318.6.62 by Olaf van der Spek
Refactor
188
  static int rollbackTransaction(Session&, bool all);
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
189
190
  /**
191
   * Commit the current transaction.
192
   *
193
   * @retval 0 ok
194
   * @retval 1 transaction was rolled back
195
   * @retval 2 error during commit, data may be inconsistent
196
   *
197
   * @todo
198
   * Since we don't support nested statement transactions in 5.0,
199
   * we can't commit or rollback stmt transactions while we are inside
200
   * stored functions or triggers. So we simply do nothing now.
201
   * This should be fixed in later ( >= 5.1) releases.
202
   */
2318.6.62 by Olaf van der Spek
Refactor
203
  static int commitTransaction(Session&, bool all);
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
204
205
  /**
206
   * This is used to commit or rollback a single statement depending on
207
   * the value of error.
208
   *
209
   * @note
210
   * Note that if the autocommit is on, then the following call inside
211
   * InnoDB will commit or rollback the whole transaction (= the statement). The
212
   * autocommit mechanism built into InnoDB is based on counting locks, but if
213
   * the user has used LOCK TABLES then that mechanism does not know to do the
214
   * commit.
215
   */
2318.6.62 by Olaf van der Spek
Refactor
216
  static int autocommitOrRollback(Session&, int error);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
217
218
  /* savepoints */
2318.6.62 by Olaf van der Spek
Refactor
219
  static int rollbackToSavepoint(Session&, NamedSavepoint &sv);
220
  static int setSavepoint(Session&, NamedSavepoint &sv);
221
  static int releaseSavepoint(Session&, NamedSavepoint &sv);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
222
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/
223
  /**
224
   * Marks a storage engine as participating in a statement
225
   * transaction.
226
   *
227
   * @note
228
   * 
229
   * This method is idempotent
230
   *
231
   * @todo
232
   *
233
   * This method should not be called more than once per resource
234
   * per statement, and therefore should not need to be idempotent.
235
   * Put in assert()s to test this.
236
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
237
   * @param[in] session Session object
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
238
   * @param[in] monitored Descriptor for the resource which will be participating
239
   * @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/
240
   */
2318.6.62 by Olaf van der Spek
Refactor
241
  static void registerResourceForStatement(Session&, plugin::MonitoredInTransaction*, plugin::TransactionalStorageEngine*);
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/
242
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
243
  /**
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
244
   * Marks an XA storage engine as participating in a statement
245
   * transaction.
246
   *
247
   * @note
248
   * 
249
   * This method is idempotent
250
   *
251
   * @todo
252
   *
253
   * This method should not be called more than once per resource
254
   * per statement, and therefore should not need to be idempotent.
255
   * Put in assert()s to test this.
256
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
257
   * @param[in] session Session object
1719.3.1 by David Shrewsbury
Fix to capture INSERTs from a LOAD DATA command in the replication stream.
258
   * @param[in] monitored Descriptor for the resource which will be participating
259
   * @param[in] engine Pointer to the TransactionalStorageEngine resource
260
   * @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
261
   */
2318.6.62 by Olaf van der Spek
Refactor
262
  static void registerResourceForStatement(Session&,
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
263
                                    plugin::MonitoredInTransaction *monitored,
264
                                    plugin::TransactionalStorageEngine *engine,
265
                                    plugin::XaResourceManager *resource_manager);
266
267
  /**
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
268
   * Registers a resource manager in the "normal" transaction.
269
   *
270
   * @note
271
   *
272
   * This method is idempotent and must be idempotent
273
   * because it can be called both by the above 
274
   * TransactionServices::registerResourceForStatement(),
275
   * which occurs at the beginning of each SQL statement,
276
   * and also manually when a BEGIN WORK/START TRANSACTION
277
   * statement is executed. If the latter case (BEGIN WORK)
278
   * is called, then subsequent contained statement transactions
279
   * will call this method as well.
280
   *
281
   * @note
282
   *
283
   * This method checks to see if the supplied resource
284
   * is also registered in the statement transaction, and
285
   * if not, registers the resource in the statement
286
   * transaction.  This happens ONLY when the user has
287
   * called BEGIN WORK/START TRANSACTION, which is the only
288
   * time when this method is called except from the
289
   * TransactionServices::registerResourceForStatement method.
290
   */
2318.6.62 by Olaf van der Spek
Refactor
291
  static void registerResourceForTransaction(Session&, plugin::MonitoredInTransaction*, plugin::TransactionalStorageEngine*);
292
293
  static void registerResourceForTransaction(Session&, plugin::MonitoredInTransaction*, plugin::TransactionalStorageEngine*, plugin::XaResourceManager*);
294
295
  static void allocateNewTransactionId();
1856.2.1 by Joseph Daly
use transaction_id in innodb for transaction log
296
 
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
297
  /**************
298
   * Events API
299
   **************/
300
301
  /**
302
   * Send server startup event.
303
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
304
   * @param session Session object
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
305
   *
306
   * @retval true Success
307
   * @retval false Failure
308
   */
2318.6.62 by Olaf van der Spek
Refactor
309
  static bool sendStartupEvent(Session&);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
310
311
  /**
312
   * Send server shutdown event.
313
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
314
   * @param session Session object
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
315
   *
316
   * @retval true Success
317
   * @retval false Failure
318
   */
2318.6.62 by Olaf van der Spek
Refactor
319
  static bool sendShutdownEvent(Session&);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
320
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
321
private:
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
322
323
  /**
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
324
   * Method which returns the active Transaction message
325
   * for the supplied Session.  If one is not found, a new Transaction
326
   * message is allocated, initialized, and returned. It is possible that
327
   * we may want to NOT increment the transaction id for a new Transaction
328
   * object (e.g., splitting up Transactions into smaller chunks). The
329
   * should_inc_trx_id flag controls if we do this.
330
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
331
   * @param session The Session object processing the transaction
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
332
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
333
   */
2318.6.61 by Olaf van der Spek
Refactor
334
  static message::Transaction *getActiveTransactionMessage(Session&, bool should_inc_trx_id= true);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
335
336
  /** 
337
   * Method which attaches a transaction context
338
   * the supplied transaction based on the supplied Session's
339
   * transaction information.  This method also ensure the
340
   * transaction message is attached properly to the Session object
341
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
342
   * @param transaction The transaction message to initialize
343
   * @param session The Session object processing this transaction
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
344
   * @param should_inc_trx_id If true, increments the transaction id for a new trx
345
   */
2318.6.61 by Olaf van der Spek
Refactor
346
  static void initTransactionMessage(message::Transaction&, Session&, bool should_inc_trx_id);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
347
  
348
  /**
349
   * Helper method which initializes a Statement message
350
   *
351
   * @param statement The statement to initialize
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
352
   * @param type The type of the statement
353
   * @param session The Session object processing this statement
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
354
   */
2318.6.61 by Olaf van der Spek
Refactor
355
  static void initStatementMessage(message::Statement&, message::Statement::Type type, const Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
356
357
  /** 
358
   * Helper method which finalizes data members for the 
359
   * supplied transaction's context.
360
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
361
   * @param transaction The transaction message to finalize 
362
   * @param session The Session object processing this transaction
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
363
   */
2318.6.61 by Olaf van der Spek
Refactor
364
  static void finalizeTransactionMessage(message::Transaction&, const Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
365
366
  /**
367
   * Helper method which deletes transaction memory and
368
   * unsets Session's transaction and statement messages.
369
   */
2318.6.61 by Olaf van der Spek
Refactor
370
  static void cleanupTransactionMessage(message::Transaction *transaction, Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
371
  
372
  /** Helper method which returns an initialized Statement message for methods
373
   * doing insertion of data.
374
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
375
   * @param[in] session Session object doing the processing
376
   * @param[in] table Table object being inserted into
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
377
   * @param[out] next_segment_id The next Statement segment id to be used
378
   */
2318.6.61 by Olaf van der Spek
Refactor
379
  static message::Statement &getInsertStatement(Session&, Table&, uint32_t *next_segment_id);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
380
  
381
  /**
382
   * Helper method which initializes the header message for
383
   * insert operations.
384
   *
385
   * @param[in,out] statement Statement message container to modify
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
386
   * @param[in] session Session object doing the processing
387
   * @param[in] table Table object being inserted into
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
388
   */
2318.6.61 by Olaf van der Spek
Refactor
389
  static void setInsertHeader(message::Statement&,
390
                       const Session&,
391
                       Table&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
392
  /**
393
   * Helper method which returns an initialized Statement
394
   * message for methods doing updates of data.
395
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
396
   * @param[in] session Session object doing the processing
397
   * @param[in] table Table object being updated
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
398
   * @param[in] old_record Pointer to the old data in the record
399
   * @param[in] new_record Pointer to the new data in the record
400
   * @param[out] next_segment_id The next Statement segment id to be used
401
   */
2318.6.61 by Olaf van der Spek
Refactor
402
  static message::Statement &getUpdateStatement(Session&,
403
                                         Table&,
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
404
                                         const unsigned char *old_record, 
405
                                         const unsigned char *new_record,
406
                                         uint32_t *next_segment_id);
407
  /**
408
   * Helper method which initializes the header message for
409
   * update operations.
410
   *
411
   * @param[in,out] statement Statement message container to modify
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
412
   * @param[in] session Session object doing the processing
413
   * @param[in] table Table object being updated
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
414
   * @param[in] old_record Pointer to the old data in the record
415
   * @param[in] new_record Pointer to the new data in the record
416
   */
2318.6.61 by Olaf van der Spek
Refactor
417
  static void setUpdateHeader(message::Statement&,
418
                       const Session&,
419
                       Table&,
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
420
                       const unsigned char *old_record, 
421
                       const unsigned char *new_record);
422
423
  /**
424
   * Helper method which returns an initialized Statement
425
   * message for methods doing deletion of data.
426
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
427
   * @param[in] session Session object doing the processing
428
   * @param[in] table Table object being deleted from
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
429
   * @param[out] next_segment_id The next Statement segment id to be used
430
   */
2318.6.61 by Olaf van der Spek
Refactor
431
  static message::Statement &getDeleteStatement(Session&, Table&, uint32_t *next_segment_id);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
432
  
433
  /**
434
   * Helper method which initializes the header message for
435
   * insert operations.
436
   *
437
   * @param[in,out] statement Statement message container to modify
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
438
   * @param[in] session Session object doing the processing
439
   * @param[in] table Table object being deleted from
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
440
   */
2318.6.61 by Olaf van der Spek
Refactor
441
  static void setDeleteHeader(message::Statement&, const Session&, Table&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
442
443
  /** 
444
   * Commits a normal transaction (see above) and pushes the transaction
445
   * message out to the replicators.
446
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
447
   * @param session Session object committing the transaction
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
448
   */
2318.6.61 by Olaf van der Spek
Refactor
449
  static int commitTransactionMessage(Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
450
451
  /** 
452
   * Marks the current active transaction message as being rolled back and
453
   * pushes the transaction message out to replicators.
454
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
455
   * @param session Session object committing the transaction
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
456
   */
2318.6.61 by Olaf van der Spek
Refactor
457
  static void rollbackTransactionMessage(Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
458
459
  /**
460
   * Rolls back the current statement, deleting the last Statement out of
461
   * the current Transaction message.
462
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
463
   * @param session Session object committing the transaction
464
   *
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
465
   * @note This depends on having clear statement boundaries (i.e., one
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
466
   * Statement message per actual SQL statement).
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
467
   */
2318.6.61 by Olaf van der Spek
Refactor
468
  static void rollbackStatementMessage(Session&);
2088.6.1 by David Shrewsbury
Clean up TransactionServices inteface by moving several methods from public to private.
469
470
  /**
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
471
   * Checks if a field has been updated 
472
   *
473
   * @param current_field Pointer to the field to check if it is updated 
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
474
   * @param table Table object containing update information
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
475
   * @param old_record Pointer to the raw bytes representing the old record/row
476
   * @param new_record Pointer to the raw bytes representing the new record/row
477
   */
2318.6.61 by Olaf van der Spek
Refactor
478
  static bool isFieldUpdated(Field *current_field,
479
                      Table&,
1795.2.2 by Joseph Daly
add test and add isFieldUpdated function
480
                      const unsigned char *old_record,
481
                      const unsigned char *new_record);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
482
483
  /**
484
   * Create a Transaction that contains event information and send it off.
485
   *
486
   * This differs from other uses of Transaction in that we don't use the
487
   * message associated with Session. We create a totally new message and
488
   * use it.
489
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
490
   * @param session Session object
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
491
   * @param event Event message to send
492
   *
493
   * @note Used by the public Events API.
494
   *
495
   * @returns Non-zero on error
496
   */
2318.6.61 by Olaf van der Spek
Refactor
497
  static int sendEvent(Session&, const message::Event &event);
1819.4.1 by David Shrewsbury
Add server startup and shutdown events to the replication stream.
498
1819.4.4 by David Shrewsbury
Merge from trunk and resolve conflicts
499
  /**
2069.3.3 by David Shrewsbury
Actually use segment info in Transaction message. Cleanup TransactionServices::getXYZStatement() method to a simpler form.
500
   * Makes a given Transaction message segmented.
501
   *
502
   * The given Transaction message will have its segment information set
503
   * appropriately and a new Transaction message, containing the same
504
   * transaction ID as the supplied Transaction, and is created.
505
   *
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
506
   * @param session Session object
507
   * @param transaction Transaction message to segment.
2069.3.3 by David Shrewsbury
Actually use segment info in Transaction message. Cleanup TransactionServices::getXYZStatement() method to a simpler form.
508
   *
509
   * @returns Returns a pointer to a new Transaction message ready for use.
1821.2.1 by Joseph Daly
fix 655352
510
   */
2318.6.61 by Olaf van der Spek
Refactor
511
  static message::Transaction *segmentTransactionMessage(Session&, message::Transaction*);
512
513
  static int commitPhaseOne(Session&, bool all);
514
515
  static uint64_t getCurrentTransactionId(Session&);
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
516
};
517
518
} /* namespace drizzled */
519