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