13.3.8.3 Restrictions on XA Transactions对XA事务的限制

XA transaction support is limited to the InnoDB storage engine.XA事务支持仅限于InnoDB存储引擎。

For external XA, a MySQL server acts as a Resource Manager and client programs act as Transaction Managers. 对于“外部XA”,MySQL服务器充当资源管理器,客户端程序充当事务管理器。For Internal XA, storage engines within a MySQL server act as RMs, and the server itself acts as a TM. 对于“内部XA”,MySQL服务器中的存储引擎充当RMs,服务器本身充当TM。Internal XA support is limited by the capabilities of individual storage engines. 内部XA支持受到单个存储引擎功能的限制。Internal XA is required for handling XA transactions that involve more than one storage engine. 处理涉及多个存储引擎的XA事务需要内部XA。The implementation of internal XA requires that a storage engine support two-phase commit at the table handler level, and currently this is true only for InnoDB.内部XA的实现要求存储引擎在表处理程序级别支持两阶段提交,目前这仅适用于InnoDB

For XA START, the JOIN and RESUME clauses are recognized but have no effect.对于XA START,可以识别JOINRESUME子句,但不起作用。

For XA END the SUSPEND [FOR MIGRATE] clause is recognized but has no effect.对于XA END,可以识别SUSPEND [For MIGRATE]子句,但不起作用。

The requirement that the bqual part of the xid value be different for each XA transaction within a global transaction is a limitation of the current MySQL XA implementation. 对于全局事务中的每个XA事务,xid值的bqual部分必须不同,这是当前MySQL XA实现的一个限制。It is not part of the XA specification.它不是XA规范的一部分。

An XA transaction is written to the binary log in two parts. XA事务分两部分写入二进制日志。When XA PREPARE is issued, the first part of the transaction up to XA PREPARE is written using an initial GTID. 发出XA PREPARE时,使用初始GTID写入事务的第一部分(直到XA PREPARE)。A XA_prepare_log_event is used to identify such transactions in the binary log. XA_prepare_log_event用于在二进制日志中标识此类事务。When XA COMMIT or XA ROLLBACK is issued, a second part of the transaction containing only the XA COMMIT or XA ROLLBACK statement is written using a second GTID. 发出XA COMMITXA ROLLBACK时,使用第二个GTID编写仅包含XA COMMITXA ROLLBACK语句的事务的第二部分。Note that the initial part of the transaction, identified by XA_prepare_log_event, is not necessarily followed by its XA COMMIT or XA ROLLBACK, which can cause interleaved binary logging of any two XA transactions. 请注意,事务的初始部分(由XA_prepare_log_event标识)后面不一定跟着XA COMMITXA ROLLBACK,这可能导致任何两个XA事务的交错二进制日志记录。The two parts of the XA transaction can even appear in different binary log files. XA事务的两个部分甚至可以出现在不同的二进制日志文件中。This means that an XA transaction in PREPARED state is now persistent until an explicit XA COMMIT or XA ROLLBACK statement is issued, ensuring that XA transactions are compatible with replication.这意味着在发出显式XA COMMITXA ROLLBACK语句之前,处于PREPARED状态的XA事务现在是持久的,以确保XA事务与复制兼容。

On a replica, immediately after the XA transaction is prepared, it is detached from the replication applier thread, and can be committed or rolled back by any thread on the replica. 在复制副本上,准备XA事务后,它立即与复制应用程序线程分离,并且可以由复制副本上的任何线程提交或回滚。This means that the same XA transaction can appear in the events_transactions_current table with different states on different threads. 这意味着相同的XA事务可以出现在不同线程上具有不同状态的events_transactions_current表中。The events_transactions_current table displays the current status of the most recent monitored transaction event on the thread, and does not update this status when the thread is idle. events_transactions_current表显示线程上最近受监视的事务事件的当前状态,并且在线程空闲时不更新此状态。So the XA transaction can still be displayed in the PREPARED state for the original applier thread, after it has been processed by another thread. 因此,XA事务在被另一个线程处理后,仍然可以以原始applier线程的PREPARED状态显示。To positively identify XA transactions that are still in the PREPARED state and need to be recovered, use the XA RECOVER statement rather than the Performance Schema transaction tables.要确定仍处于PREPARED状态且需要恢复的XA事务,请使用XA RECOVER语句,而不是性能模式事务表。

The following restrictions exist for using XA transactions:使用XA事务存在以下限制:

Note注意

Prior to MySQL 5.7.7, XA transactions were not compatible with replication at all. 在MySQL 5.7.7之前,XA事务与复制完全不兼容。This was because an XA transaction that was in PREPARED state would be rolled back on clean server shutdown or client disconnect. 这是因为处于PREPARED状态的XA事务将在干净的服务器关闭或客户端断开连接时回滚。Similarly, an XA transaction that was in PREPARED state would still exist in PREPARED state in case the server was shutdown abnormally and then started again, but the contents of the transaction could not be written to the binary log. 类似地,如果服务器异常关闭然后再次启动,处于PREPARED状态的XA事务仍将处于PREPARED状态,但事务的内容无法写入二进制日志。In both of these situations the XA transaction could not be replicated correctly.在这两种情况下,无法正确复制XA事务。