1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
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) 2009-2010 Jay Pipes <jaypipes@gmail.com>
|
|
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
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 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
21 |
#pragma once
|
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
22 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
23 |
#include <drizzled/definitions.h> /* for start_transaction_option_t */ |
24 |
#include <drizzled/plugin/storage_engine.h> |
|
25 |
#include <drizzled/transaction_services.h> |
|
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
26 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
27 |
#include <drizzled/visibility.h> |
2119.4.1
by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by |
28 |
|
2280.1.1
by Olaf van der Spek
Refactor |
29 |
namespace drizzled { |
30 |
namespace plugin { |
|
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
31 |
|
32 |
/**
|
|
33 |
* A type of storage engine which supports SQL transactions.
|
|
34 |
*
|
|
35 |
* This class adds the SQL transactional API to the regular
|
|
36 |
* storage engine. In other words, it adds support for the
|
|
37 |
* following SQL statements:
|
|
38 |
*
|
|
39 |
* START TRANSACTION;
|
|
40 |
* COMMIT;
|
|
41 |
* ROLLBACK;
|
|
42 |
* ROLLBACK TO SAVEPOINT;
|
|
43 |
* SET SAVEPOINT;
|
|
44 |
* RELEASE SAVEPOINT;
|
|
45 |
*
|
|
46 |
* @note
|
|
47 |
*
|
|
48 |
* This class does not implement the XA protocol (two phase commit).
|
|
49 |
* There is an XaStorageEngine class which extends this class that
|
|
50 |
* exposes the XA API.
|
|
51 |
*
|
|
52 |
* @todo
|
|
53 |
*
|
|
54 |
* kill two_phase_commit member. Use an HTON flag if
|
|
55 |
* absolutely needed to keep.
|
|
56 |
*/
|
|
2280.1.1
by Olaf van der Spek
Refactor |
57 |
class DRIZZLED_API TransactionalStorageEngine : public StorageEngine |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
58 |
{
|
1947.1.4
by Stewart Smith
have SEAPITester be a friend of StorageEngine instead of changing 'protected' to 'public' for some methods. |
59 |
friend class SEAPITester; |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
60 |
public: |
2353.2.8
by Stewart Smith
TransactionalStorageEngine: Function parameter 'name_arg' is passed by value. It could be passed by reference instead. |
61 |
TransactionalStorageEngine(const std::string &name_arg, |
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
62 |
const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS); |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
63 |
|
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
64 |
virtual int startTransaction(Session *session, start_transaction_option_t options) |
1273.1.27
by Jay Pipes
Completes the work of removing the weirdness around transaction |
65 |
{
|
2318.6.62
by Olaf van der Spek
Refactor |
66 |
TransactionServices::registerResourceForTransaction(*session, this, this); |
1273.1.27
by Jay Pipes
Completes the work of removing the weirdness around transaction |
67 |
return doStartTransaction(session, options); |
68 |
}
|
|
69 |
||
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
70 |
virtual void startStatement(Session *session) |
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/ |
71 |
{
|
2318.6.62
by Olaf van der Spek
Refactor |
72 |
TransactionServices::registerResourceForStatement(*session, this, this); |
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/ |
73 |
doStartStatement(session); |
74 |
}
|
|
75 |
||
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
76 |
virtual int commit(Session *session, bool normal_transaction) |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
77 |
{
|
78 |
return doCommit(session, normal_transaction); |
|
79 |
}
|
|
80 |
||
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
81 |
virtual int rollback(Session *session, bool normal_transaction) |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
82 |
{
|
83 |
return doRollback(session, normal_transaction); |
|
84 |
}
|
|
85 |
||
86 |
int setSavepoint(Session *session, NamedSavepoint &sp) |
|
87 |
{
|
|
88 |
return doSetSavepoint(session, sp); |
|
89 |
}
|
|
90 |
||
91 |
int rollbackToSavepoint(Session *session, NamedSavepoint &sp) |
|
92 |
{
|
|
93 |
return doRollbackToSavepoint(session, sp); |
|
94 |
}
|
|
95 |
||
96 |
int releaseSavepoint(Session *session, NamedSavepoint &sp) |
|
97 |
{
|
|
98 |
return doReleaseSavepoint(session, sp); |
|
99 |
}
|
|
100 |
||
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
101 |
/*
|
102 |
* The below are simple virtual overrides for the plugin::MonitoredInTransaction
|
|
103 |
* interface.
|
|
104 |
*/
|
|
105 |
virtual bool participatesInSqlTransaction() const |
|
106 |
{
|
|
107 |
return true; /* We DO participate in the SQL transaction */ |
|
108 |
}
|
|
109 |
virtual bool participatesInXaTransaction() const |
|
110 |
{
|
|
111 |
return false; /* We DON'T participate in the XA transaction */ |
|
112 |
}
|
|
113 |
virtual bool alwaysRegisterForXaTransaction() const |
|
114 |
{
|
|
115 |
return false; |
|
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
116 |
}
|
117 |
||
118 |
/**
|
|
119 |
* The below static class methods wrap the interaction
|
|
120 |
* of the vector of transactional storage engines.
|
|
121 |
*/
|
|
1273.1.27
by Jay Pipes
Completes the work of removing the weirdness around transaction |
122 |
static int notifyStartTransaction(Session *session, start_transaction_option_t options); |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
123 |
/**
|
124 |
* @todo Kill this one entirely. It's implementation, not interface...
|
|
125 |
*/
|
|
2280.1.3
by Olaf van der Spek
Refactor |
126 |
static void releaseTemporaryLatches(Session *session); |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
127 |
|
128 |
/* Class Methods for operating on plugin */
|
|
129 |
static bool addPlugin(plugin::TransactionalStorageEngine *engine); |
|
130 |
static void removePlugin(plugin::TransactionalStorageEngine *engine); |
|
131 |
||
132 |
private: |
|
133 |
void setTransactionReadWrite(Session& session); |
|
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/ |
134 |
|
135 |
/*
|
|
136 |
* Indicates to a storage engine the start of a
|
|
1273.1.27
by Jay Pipes
Completes the work of removing the weirdness around transaction |
137 |
* new SQL transaction. This is called ONLY in the following
|
138 |
* scenarios:
|
|
139 |
*
|
|
140 |
* 1) An explicit BEGIN WORK/START TRANSACTION is called
|
|
141 |
* 2) After an explicit COMMIT AND CHAIN is called
|
|
142 |
* 3) After an explicit ROLLBACK AND RELEASE is called
|
|
143 |
* 4) When in AUTOCOMMIT mode and directly before a new
|
|
144 |
* SQL statement is started.
|
|
145 |
*
|
|
146 |
* Engines should typically use the doStartStatement()
|
|
147 |
* and doEndStatement() methods to manage transaction state,
|
|
148 |
* since the kernel ALWAYS notifies engines at the start
|
|
149 |
* and end of statement transactions and at the end of the
|
|
150 |
* normal transaction by calling doCommit() or doRollback().
|
|
151 |
*/
|
|
152 |
virtual int doStartTransaction(Session *session, start_transaction_option_t options) |
|
153 |
{
|
|
154 |
(void) session; |
|
155 |
(void) options; |
|
156 |
return 0; |
|
157 |
}
|
|
158 |
||
159 |
/*
|
|
160 |
* Indicates to a storage engine the start of a
|
|
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/ |
161 |
* new SQL statement.
|
162 |
*/
|
|
163 |
virtual void doStartStatement(Session *session) |
|
164 |
{
|
|
165 |
(void) session; |
|
166 |
}
|
|
167 |
||
168 |
/*
|
|
169 |
* Indicates to a storage engine the end of
|
|
170 |
* the current SQL statement in the supplied
|
|
171 |
* Session.
|
|
172 |
*/
|
|
173 |
virtual void doEndStatement(Session *session) |
|
174 |
{
|
|
175 |
(void) session; |
|
176 |
}
|
|
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
177 |
/**
|
178 |
* Implementing classes should override these to provide savepoint
|
|
179 |
* functionality.
|
|
180 |
*/
|
|
181 |
virtual int doSetSavepoint(Session *session, NamedSavepoint &savepoint)= 0; |
|
182 |
virtual int doRollbackToSavepoint(Session *session, NamedSavepoint &savepoint)= 0; |
|
183 |
virtual int doReleaseSavepoint(Session *session, NamedSavepoint &savepoint)= 0; |
|
184 |
||
185 |
/**
|
|
186 |
* Commits either the "statement transaction" or the "normal transaction".
|
|
187 |
*
|
|
188 |
* @param[in] The Session
|
|
189 |
* @param[in] true if it's a real commit, that makes persistent changes
|
|
190 |
* false if it's not in fact a commit but an end of the
|
|
191 |
* statement that is part of the transaction.
|
|
192 |
* @note
|
|
193 |
*
|
|
194 |
* 'normal_transaction' is also false in auto-commit mode where 'end of statement'
|
|
195 |
* and 'real commit' mean the same event.
|
|
196 |
*/
|
|
197 |
virtual int doCommit(Session *session, bool normal_transaction)= 0; |
|
198 |
||
199 |
/**
|
|
200 |
* Rolls back either the "statement transaction" or the "normal transaction".
|
|
201 |
*
|
|
202 |
* @param[in] The Session
|
|
203 |
* @param[in] true if it's a real commit, that makes persistent changes
|
|
204 |
* false if it's not in fact a commit but an end of the
|
|
205 |
* statement that is part of the transaction.
|
|
206 |
* @note
|
|
207 |
*
|
|
208 |
* 'normal_transaction' is also false in auto-commit mode where 'end of statement'
|
|
209 |
* and 'real commit' mean the same event.
|
|
210 |
*/
|
|
211 |
virtual int doRollback(Session *session, bool normal_transaction)= 0; |
|
2280.1.3
by Olaf van der Spek
Refactor |
212 |
virtual int doReleaseTemporaryLatches(Session*) |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
213 |
{
|
214 |
return 0; |
|
215 |
}
|
|
2280.1.3
by Olaf van der Spek
Refactor |
216 |
virtual int doStartConsistentSnapshot(Session*) |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
217 |
{
|
218 |
return 0; |
|
219 |
}
|
|
220 |
};
|
|
221 |
||
222 |
} /* namespace plugin */ |
|
223 |
} /* namespace drizzled */ |
|
224 |