XA Transactions Restrictions on XA Transactions
小结:
1、innodb支持XA事务;
2、XA协议作为资源管理器(数据库)与事务管理器的接口标准;
3、提交或者回滚的点:必须所有的组件被提交或者被回滚;
4、2阶段
PC-1,TM告知所有RM要准备提交,各个RM汇报是否准备好;
PC-2,如果所有RM准备好,则TM告知所有RM提交;否则如果有RM未准备好,则TM告知所有RM回滚。
5、1阶段
当只有一个RM时,2阶段提交退化为one-phase commit 1阶段提交。
XA的Mysql实现是通过在全局事务中扮演资源管理者RM角色来处理XA事务;
连接到Mysql服务器的客户端程序扮演事务管理者TM角色。
MySQL :: MySQL 8.0 Reference Manual :: 13.3.8 XA Transactions https://dev.mysql.com/doc/refman/8.0/en/xa.html
MySQL :: MySQL 8.0 Reference Manual :: C.6 Restrictions on XA Transactions https://dev.mysql.com/doc/refman/8.0/en/xa-restrictions.html
13.3.8 XA Transactions
Support for XA transactions is available for the InnoDB storage engine. The MySQL XA implementation is based on the X/Open CAE document Distributed Transaction Processing: The XA Specification. This document is published by The Open Group and available athttp://www.opengroup.org/public/pubs/catalog/c193.htm. Limitations of the current XA implementation are described in Section C.6, “Restrictions on XA Transactions”.
On the client side, there are no special requirements. The XA interface to a MySQL server consists of SQL statements that begin with the XAkeyword. MySQL client programs must be able to send SQL statements and to understand the semantics of the XA statement interface. They do not need be linked against a recent client library. Older client libraries also will work.
Among the MySQL Connectors, MySQL Connector/J 5.0.0 and higher supports XA directly, by means of a class interface that handles the XA SQL statement interface for you.
XA supports distributed transactions, that is, the ability to permit multiple separate transactional resources to participate in a global transaction. Transactional resources often are RDBMSs but may be other kinds of resources.
A global transaction involves several actions that are transactional in themselves, but that all must either complete successfully as a group, or all be rolled back as a group. In essence, this extends ACID properties “up a level” so that multiple ACID transactions can be executed in concert as components of a global operation that also has ACID properties. (As with nondistributed transactions, SERIALIZABLE may be preferred if your applications are sensitive to read phenomena. REPEATABLE READ may not be sufficient for distributed transactions.)
Some examples of distributed transactions:
An application may act as an integration tool that combines a messaging service with an RDBMS. The application makes sure that transactions dealing with message sending, retrieval, and processing that also involve a transactional database all happen in a global transaction. You can think of this as “transactional email.”
An application performs actions that involve different database servers, such as a MySQL server and an Oracle server (or multiple MySQL servers), where actions that involve multiple servers must happen as part of a global transaction, rather than as separate transactions local to each server.
A bank keeps account information in an RDBMS and distributes and receives money through automated teller machines (ATMs). It is necessary to ensure that ATM actions are correctly reflected in the accounts, but this cannot be done with the RDBMS alone. A global transaction manager integrates the ATM and database resources to ensure overall consistency of financial transactions.
Applications that use global transactions involve one or more Resource Managers and a Transaction Manager:
A Resource Manager (RM) provides access to transactional resources. A database server is one kind of resource manager. It must be possible to either commit or roll back transactions managed by the RM.
A Transaction Manager (TM) coordinates the transactions that are part of a global transaction. It communicates with the RMs that handle each of these transactions. The individual transactions within a global transaction are “branches” of the global transaction. Global transactions and their branches are identified by a naming scheme described later.
The MySQL implementation of XA enables a MySQL server to act as a Resource Manager that handles XA transactions within a global transaction. A client program that connects to the MySQL server acts as the Transaction Manager.
To carry out a global transaction, it is necessary to know which components are involved, and bring each component to a point when it can be committed or rolled back. Depending on what each component reports about its ability to succeed, they must all commit or roll back as an atomic group. That is, either all components must commit, or all components must roll back. To manage a global transaction, it is necessary to take into account that any component or the connecting network might fail.
The process for executing a global transaction uses two-phase commit (2PC). This takes place after the actions performed by the branches of the global transaction have been executed.
In the first phase, all branches are prepared. That is, they are told by the TM to get ready to commit. Typically, this means each RM that manages a branch records the actions for the branch in stable storage. The branches indicate whether they are able to do this, and these results are used for the second phase.
In the second phase, the TM tells the RMs whether to commit or roll back. If all branches indicated when they were prepared that they will be able to commit, all branches are told to commit. If any branch indicated when it was prepared that it will not be able to commit, all branches are told to roll back.
In some cases, a global transaction might use one-phase commit (1PC). For example, when a Transaction Manager finds that a global transaction consists of only one transactional resource (that is, a single branch), that resource can be told to prepare and commit at the same time.
XA_百度百科 https://baike.baidu.com/item/XA
- 中文名
- XA
- 提 出
- Tuxedo
- 组 织
- X/Open
- 支 持
- Oracle、Informix、DB2和Sybase
简介
操作
X/Open XA
The goal of XA is to guarantee atomicity in "global transactions" that are executed across heterogeneous back end data stores (such as databases, application servers, message queues, transactional caches, etc.). To guarantee atomicity, XA uses a two-phase commit (2PC) to ensure that all resources either commit or roll back any particular transaction consistently (i.e. all do the same, atomically).
Specifically, XA describes the interface between the global transaction manager and a specific application. An application that wants to use XA will engage an XA transaction manager using a library or separate service. The transaction manager will then keep track of the participants in the transaction (i.e. the various other data stores to which the application is writing), and work with them to carry out the two-phase commit protocol. In other words, the XA transaction manager generally rides on top of the application's existing connections to the servers to which it wants to write a transaction. It maintains a log of its decisions to commit or abort (similar to how a database maintains a log of its own writes), which it can use to recover in case it fails and needs to be restarted.[1]
Many software vendors continue to support XA (meaning the software can participate in XA transactions), including a variety of relational databases and message brokers.[1]
Advantages and Disadvantages[edit]
Since XA uses two-phase commit, the advantages and disadvantages of that protocol generally apply to XA. The main advantage is that XA (using 2PC) allows an atomic transaction across multiple heterogeneous technologies (e.g. a single transaction could encompass multiple databases from different vendors as well as an email server and a message broker), whereas traditional database transactions are limited to a single database.
The main disadvantage is that 2PC is a blocking protocol: the other servers need to wait for the transaction manager to issue a decision about whether to commit or abort each transaction. If the transaction manager goes offline while transactions are waiting for its final decision, they will be stuck and hold their database locks until the transaction manager comes online again and issues its decision. This extended holding of locks may be disruptive to other applications that are using the same databases.[1]
Moreover if the transaction manager crashes and its record of decisions cannot be recovered (e.g. due to a bug in how the decisions were logged, or due to data corruption on the server), manual intervention may be necessary. Many XA implementations provide an "escape hatch" for transactions to independently decide whether to commit or abort (without waiting to hear from the transaction manager), but this risks violating the atomicity guarantee and is therefore reserved for emergencies.[1]
Specification[edit]
The XA specification describes what a resource manager must do to support transactional access. Resource managers that follow this specification are said to be XA-compliant.
The XA specification was based on an interface used in the Tuxedo system developed in the 1980s, but adopted by several systems since then.[2]
See also[edit]
XA transaction support is limited to the InnoDB storage engine.
For “external XA,” a MySQL server acts as a Resource Manager and client programs act as Transaction Managers. For “Internal XA”, storage engines within a MySQL server act as RMs, and the server itself acts as a TM. Internal XA support is limited by the capabilities of individual storage engines. Internal XA is required for handling XA transactions that involve more than one storage engine. 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.
For XA START, the JOIN and RESUME clauses are not supported.
For XA END, the SUSPEND [FOR MIGRATE] clause is not supported.
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. It is not part of the XA specification.
An XA transaction is written to the binary log in two parts. When XA PREPARE is issued, the first part of the transaction up to XA PREPARE is written using an initial GTID. A XA_prepare_log_event is used to identify such transactions in the binary log. When XA COMMIT or XA ROLLBACKis issued, a second part of the transaction containing only the XA COMMIT or XA ROLLBACK statement is written using a second GTID. 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. The two parts of the XA transaction can even appear in different binary log files. 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.
On a replication slave, immediately after the XA transaction is prepared, it is detached from the slave applier thread, and can be committed or rolled back by any thread on the slave. This means that the same XA transaction can appear in the events_transactions_current table with different states on different threads. 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. 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. 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.
The following restrictions exist for using XA transactions:
XA transactions are not fully resilient to an unexpected halt with respect to the binary log. If there is an unexpected halt while the server is in the middle of executing an
XA PREPARE,XA COMMIT,XA ROLLBACK, orXA COMMIT ... ONE PHASEstatement, the server might not be able to recover to a correct state, leaving the server and the binary log in an inconsistent state. In this situation, the binary log might either contain extra XA transactions that are not applied, or miss XA transactions that are applied. Also, if GTIDs are enabled, after recovery@@GLOBAL.GTID_EXECUTEDmight not correctly describe the transactions that have been applied. Note that if an unexpected halt occurs beforeXA PREPARE, betweenXA PREPAREandXA COMMIT(orXA ROLLBACK), or afterXA COMMIT(orXA ROLLBACK), the server and binary log are correctly recovered and taken to a consistent state.The use of replication filters or binary log filters in combination with XA transactions is not supported. Filtering of tables could cause an XA transaction to be empty on a replication slave, and empty XA transactions are not supported. Also, with the settings
master_info_repository=TABLEandrelay_log_info_repository=TABLEon a replication slave, which became the defaults in MySQL 8.0, the internal state of the data engine transaction is changed following a filtered XA transaction, and can become inconsistent with the replication transaction context state.The error
ER_XA_REPLICATION_FILTERSis logged whenever an XA transaction is impacted by a replication filter, whether or not the transaction was empty as a result. If the transaction is not empty, the replication slave is able to continue running, but you should take steps to discontinue the use of replication filters with XA transactions in order to avoid potential issues. If the transaction is empty, the replication slave stops. In that event, the replication slave might be in an undetermined state in which the consistency of the replication process might be compromised. In particular, thegtid_executedset on a slave of the slave might be inconsistent with that on the master. To resolve this situation, isolate the master and stop all replication, then check GTID consistency across the replication topology. Undo the XA transaction that generated the error message, then restart replication.XA transactions are considered unsafe for statement-based replication. If two XA transactions committed in parallel on the master are being prepared on the slave in the inverse order, locking dependencies can occur that cannot be safely resolved, and it is possible for replication to fail with deadlock on the slave. This situation can occur for a single-threaded or multithreaded replication slave. When
binlog_format=STATEMENTis set, a warning is issued for DML statements inside XA transactions. Whenbinlog_format=MIXEDorbinlog_format=ROWis set, DML statements inside XA transactions are logged using row-based replication, and the potential issue is not present.
Prior to MySQL 5.7.7, XA transactions were not compatible with replication at all. This was because an XA transaction that was in PREPARED state would be rolled back on clean server shutdown or client disconnect. 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. In both of these situations the XA transaction could not be replicated correctly.
XA Transactions Restrictions on XA Transactions的更多相关文章
- DTP模型之一:(XA协议之一)XA协议、二阶段2PC、三阶段3PC提交
XA协议 XA是一个分布式事务协议,由Tuxedo提出.XA中大致分为两部分:事务管理器和本地资源管理器.其中本地资源管理器往往由数据库实现,比如Oracle.DB2这些商业数据库都实现了XA接口,而 ...
- 如何实现XA式、非XA式Spring分布式事务
Spring应用的几种事务处理机制 Java Transaction API和XA协议是Spring常用的分布式事务机制,不过你可以选择选择其他的实现方式.理想的实现取决于你的应用程序使用何种资源,你 ...
- XA Transactions
XA Transactions XA is a two-phase commit protocol that is natively supported by many databases and t ...
- Distributed transactions in Spring, with and without XA
While it's common to use the Java Transaction API and the XA protocol for distributed transactions i ...
- MySQL binlog 组提交与 XA(两阶段提交)
1. XA-2PC (two phase commit, 两阶段提交 ) XA是由X/Open组织提出的分布式事务的规范(X代表transaction; A代表accordant?).XA规范主要定义 ...
- XA事务处理
XA接口详解 X/Open XA接口是双向的系统接口,在事务管理器(Transaction Manager)以及一个或多个资源管理器(Resource Manager)之间形成通信桥梁.事务管理器控制 ...
- 使用Atomikos Transactions Essentials实现多数据源JTA分布式事务--转载
原文:http://www.ite/topic/122700 9.17 update:使用NonXADataSourceBean. Mysql在5.0版本和Connecter/J5.0版本后提供了XA ...
- Spring JTA multiple resource transactions in Tomcat with Atomikos example--转载
原文地址:http://www.javacodegeeks.com/2013/07/spring-jta-multiple-resource-transactions-in-tomcat-with-a ...
- MySQL binlog 组提交与 XA(两阶段提交)--1
参考了网上几篇比较靠谱的文章 http://www.linuxidc.com/Linux/2015-11/124942.htm http://blog.csdn.net/woqutechteam/ar ...
随机推荐
- 用Python来玩微信跳一跳
微信2017年12月28日发布了新版本,在小程序里面有一个跳一跳小游戏,试着点一点玩了下.第二天刚好在一篇技术公众号中,看到有大神用Python代码计算出按压时间,向手机发送android adb命令 ...
- 为什么一点onclick按钮就提交表单?
下面是一个表单,有一个onclick按钮,点击后上面文本框的内容被添加到下面的文本域中,并可以一直添加,然后点击submit后提交到另一个页面.但是,在Ie9或者火狐浏览器中我一点onclick为什么 ...
- [转载][IoC容器Unity]第二回:Lifetime Managers生命周期
1.引言 Unity的生命周期是注册的类型对象的生命周期,而Unity默认情况下会自动帮我们维护好这些对象的生命周期,我们也可以显示配置对象的生命周期,Unity将按照配置自动管理,非常方便,下面就介 ...
- ubuntu下使用golang、qml与ubuntu sdk开发桌面应用 (简单示例)
找了很长时间go的gui库,试了gtk,准备试qt的时候发现了这个qml库,试了下很好用. ##准备工作 **1.Go 1.2RC1** go的版本应该不能低于这个,我是在1.2RC发布当天升级后发现 ...
- Go Revel - Testing(测试模块)
revel提供了一个测试框架来方便的为自己的程序编写功能测试用例. 默认创建的应用骨架附带一个简单的测试用例,这里将它作为起点 ##概览 测试保存在`tests`目录: corp/myapp app/ ...
- 如何在Excel中提取小数点后面的数字?
Excel中,如果某个单元格中包含一个带小数,要用公式提取该数值小数点后面的数字,例如A1单元格中包含一个数值“59178.68”,在B1单元格中输入下面的公式: =RIGHT(A1,LEN(A1)- ...
- “failed to excute script xxx” PyInstaller 打包python程序为exe文件过程错误
在使用PyInstaller打包python程序,打包命令为: pyinstaller -F -w -i manage.ico yourpyfile.py 顺便说一下几个参数的作用 -F:是直接生成单 ...
- Angular4学习笔记(八)- ng-content
内容投影 ng-content ng-content是一个占位符,有些类似于router-outlet. 以前举の例子,父组件包含子组件都是直接指明子组件的selector,比如子组件的selecto ...
- VS设置DLL所在的调试目录
如果一个项目依赖的DLL不想写在Path中,可以在 配置属性-调试-环境中添加 PATH=D:/OSG/bin;$(PATH)
- js的微任务和宏任务
1.机制如下: 注意一点: 宏任务需要多次事件循环才能执行完,微任务是一次性执行完的: 2.宏任务macrotask: (事件队列中的每一个事件都是一个macrotask) 优先级:主代码块 > ...