An XA transaction progresses through the following states:XA事务通过以下状态进行:
Use 使用XA START
to start an XA transaction and put it in the ACTIVE
state.XA START
启动XA事务并将其置于ACTIVE
状态。
For an 对于ACTIVE
XA transaction, issue the SQL statements that make up the transaction, and then issue an XA END
statement. ACTIVE
XA事务,发出组成事务的SQL语句,然后发出XA END
语句。XA END
puts the transaction in the IDLE
state.XA END
将事务置于空闲状态。
For an 对于IDLE
XA transaction, you can issue either an XA PREPARE
statement or an XA COMMIT ... ONE PHASE
statement:IDLE
(空闲)XA事务,您可以发出XA PREPARE
语句或XA COMMIT ... ONE PHASE
语句:
XA PREPARE
puts the transaction in the PREPARED
state. XA PREPARE
将事务置于PREPARED
状态。An 此时的XA RECOVER
statement at this point includes the transaction's xid
value in its output, because XA RECOVER
lists all XA transactions that are in the PREPARED
state.XA RECOVER
语句在其输出中包含事务的xid
值,因为XA RECOVER
列出了处于PREPARED
状态的所有XA事务。
XA COMMIT ... ONE PHASE
prepares and commits the transaction. XA COMMIT ... ONE PHASE
准备并提交事务。The xid
value is not listed by XA RECOVER
because the transaction terminates.XA RECOVER
未列出xid
值,因为事务终止。
For a 对于PREPARED
XA transaction, you can issue an XA COMMIT
statement to commit and terminate the transaction, or XA ROLLBACK
to roll back and terminate the transaction.PREPARED
XA事务,可以发出XA COMMIT
语句来提交和终止事务,或者发出XA ROLLBACK
语句来回滚和终止事务。
Here is a simple XA transaction that inserts a row into a table as part of a global transaction:下面是一个简单的XA事务,它将行作为全局事务的一部分插入表中:
mysql>XA START 'xatest';
Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO mytable (i) VALUES(10);
Query OK, 1 row affected (0.04 sec) mysql>XA END 'xatest';
Query OK, 0 rows affected (0.00 sec) mysql>XA PREPARE 'xatest';
Query OK, 0 rows affected (0.00 sec) mysql>XA COMMIT 'xatest';
Query OK, 0 rows affected (0.00 sec)
Within the context of a given client connection, XA transactions and local (non-XA) transactions are mutually exclusive. 在给定客户端连接的上下文中,XA事务和本地(非XA)事务是互斥的。For example, if 例如,如果发出XA START
has been issued to begin an XA transaction, a local transaction cannot be started until the XA transaction has been committed or rolled back. XA START
以开始XA事务,则在提交或回滚XA事务之前,无法启动本地事务。Conversely, if a local transaction has been started with 相反,如果本地事务是用START TRANSACTION
, no XA statements can be used until the transaction has been committed or rolled back.START TRANSACTION
启动的,则在提交或回滚事务之前,不能使用XA语句。
If an XA transaction is in the 如果XA事务处于ACTIVE
state, you cannot issue any statements that cause an implicit commit. ACTIVE
状态,则不能发出任何导致隐式提交的语句。That would violate the XA contract because you could not roll back the XA transaction. 这将违反XA合同,因为您无法回滚XA事务。Trying to execute such a statement raises the following error:尝试执行此类语句会引发以下错误:
ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state
Statements to which the preceding remark applies are listed at Section 13.3.3, “Statements That Cause an Implicit Commit”.第13.3.3节,“导致隐式提交的语句”中列出了上述备注适用的语句。