InnoDB storage engine provides support for XA transactions, and by supporting distributed transactions XA transaction implementation
Distributed Transaction means: allow multiple separate transactional resources to participate in a global transaction. Transactional resources are usually relational database system, but may also be other types of resources
Global transaction requires all participating transactions which are either committed or rolled back , which for the original ACID transaction requirements, there has been increased. In addition, when using distributed transactions, InnoDB's transaction isolation level must be set to SERIALIZABLE
XA transaction allows distributed transactions between different databases, such as a server, MySQL database, and the other is an Oracle database, and there may be a server, each node of SQL Server as long as participation in global affairs are XA transaction support
Distributed Transaction may be more common in the transfer of the banking system, as users need David transferred from Shanghai to Beijing 10 000 users Mariah's bank card:
In this case, we need to use distributed transactions to ensure data security. If the operation can not take place globally committed or rolled back, then any node problem can lead to serious results. Either David's account is debited, but Mariah did not receive, or is David's account no charge, Mariah has received money
innodb_support_xa parameters
This parameter is used to control whether to support XA transactions
The default is ON, expressed support for XA transactions
Second, the composition XA transactions
XA transaction by the following three parts:
Resource Manager (Resource Managers): provides a way to access transactional resources. Usually a database is a resource manager
Transaction manager (Transaction Manager): coordinate participation in all affairs global transaction. And require all resource managers involved in global transactions communicate
Application (Application Program): operational boundaries, global transaction specified in the definition of affairs
MySQL databases in a distributed transaction, the resource manager is MySQL database, transaction manager to connect to the MySQL server's client-side
The following figure shows a distributed transaction model:
Use two-phase commit distributed transactions are:
The first phase, all the nodes of the global transaction parameters are beginning to prepare (PREPARE), tells the transaction manager that they are ready to submit a
The second phase, the transaction manager tells Explorer organic ROLLBACK or COMMIT. If you can not submit any node display, all nodes are told to roll back
Visible and local transaction is different, distributed transactions need more time PREPARE operation after, until you receive the same information for all nodes, and then COMMIT or ROLLBACK operation
Three Grammatical, XA transaction
Examples of single-node operation
Run on a single node in a distributed transaction is not much practical significance, but to demonstrate a distributed transaction involved multiple nodes in a MySQL database command is not feasible
V. Internal XA transaction
Distributed Transaction previously discussed external affairs, namely resource manager is MySQL database itself. There is another distributed transaction in a MySQL database, which is between the engine and plug-in storage, or between storage engine and storage engine, called the internal XA transaction
Internal XA transaction guarantee from the main
The most common internal XA transaction exists between binlog and InnoDB storage engine