34
36
* A type of storage engine which supports distributed
35
37
* transactions in the XA protocol.
39
* The real XA resource manager interface is in the
40
* plugin::XaResourceManager class. We would extend
41
* XaResourceManager from plugin::Plugin but unfortunately
42
* that would lead to member name ambiguity (because plugin::Plugin
43
* has member data). So, in this case, TransactionalStorageEngine
44
* inherits from plugin::Plugin and XaResourceManager is a pure
45
* virtual abstract base class with the X/Open XA distributed
46
* transaction protocol interface for resource managers.
37
class XaStorageEngine :public TransactionalStorageEngine
48
class XaStorageEngine :public TransactionalStorageEngine,
49
public XaResourceManager
40
52
XaStorageEngine(const std::string name_arg,
43
55
virtual ~XaStorageEngine();
45
int prepare(Session *session, bool normal_transaction)
47
return doPrepare(session, normal_transaction);
50
int commitXid(XID *xid)
52
return doCommitXid(xid);
55
int rollbackXid(XID *xid)
57
return doRollbackXid(xid);
60
int recover(XID * append_to, size_t len)
62
return doRecover(append_to, len);
66
* The below static class methods wrap the interaction
67
* of the vector of registered XA storage engines.
57
int startTransaction(Session *session, start_transaction_option_t options)
59
TransactionServices &transaction_services= TransactionServices::singleton();
60
transaction_services.registerResourceForTransaction(session, this, this, this);
61
return doStartTransaction(session, options);
64
void startStatement(Session *session)
66
TransactionServices &transaction_services= TransactionServices::singleton();
67
transaction_services.registerResourceForStatement(session, this, this, this);
68
doStartStatement(session);
72
* The below are simple virtual overrides for the plugin::MonitoredInTransaction
69
static int commitOrRollbackXID(XID *xid, bool commit);
70
static int recoverAllXids(HASH *commit_list);
75
bool participatesInSqlTransaction() const
77
return true; /* We DO participate in the SQL transaction */
79
bool participatesInXaTransaction() const
81
return true; /* We DO participate in the XA transaction */
83
bool alwaysRegisterForXaTransaction() const
85
return false; /* We only register in the XA transaction if the engine's data is modified */
72
88
/* Class Methods for operating on plugin */
73
89
static bool addPlugin(plugin::XaStorageEngine *engine);
74
90
static void removePlugin(plugin::XaStorageEngine *engine);
78
* Does the PREPARE stage of the two-phase commit.
80
virtual int doPrepare(Session *session, bool normal_transaction)= 0;
82
* Rolls back a transaction identified by a XID.
84
virtual int doRollbackXid(XID *xid)= 0;
86
* Commits a transaction identified by a XID.
88
virtual int doCommitXid(XID *xid)= 0;
90
* Notifies the transaction manager of any transactions
91
* which had been marked prepared but not committed at
92
* crash time or that have been heurtistically completed
93
* by the storage engine.
95
* @param[out] Reference to a vector of XIDs to add to
98
* Returns the number of transactions left to recover
101
virtual int doRecover(XID * append_to, size_t len)= 0;
94
* Indicates to a storage engine the start of a
95
* new SQL transaction. This is called ONLY in the following
98
* 1) An explicit BEGIN WORK/START TRANSACTION is called
99
* 2) After an explicit COMMIT AND CHAIN is called
100
* 3) After an explicit ROLLBACK AND RELEASE is called
101
* 4) When in AUTOCOMMIT mode and directly before a new
102
* SQL statement is started.
104
* Engines should typically use the doStartStatement()
105
* and doEndStatement() methods to manage transaction state,
106
* since the kernel ALWAYS notifies engines at the start
107
* and end of statement transactions and at the end of the
108
* normal transaction by calling doCommit() or doRollback().
110
virtual int doStartTransaction(Session *session, start_transaction_option_t options)
118
* Indicates to a storage engine the start of a
121
virtual void doStartStatement(Session *session)
105
127
} /* namespace plugin */