MySQL transaction learning-distributed transactions

Source: Internet
Author: User
The Innodb Storage engine supports XA transactions and distributed transactions. Distributed transactions refer to multiple independent transaction resources (transactionalres ).

The Innodb Storage engine supports XA transactions and distributed transactions. Distributed transactions refer to multiple independent transaction resources (transac tional res ).

Distributed transactions

The Innodb Storage engine supports XA transactions and distributed transactions. Distributed Transactions allow multiple independent transaction resources to participate in a global transaction. Transaction resources are usually relational database systems or other types of resources.

Global transactions require that all the transactions involved in the transaction be either committed or rolled back. This improves the original ACID Requirements of the transaction. In addition, when using distributed transactions, the transaction isolation level of the InnoDB Storage engine must be set to serialiable.

XA Transactions allow distributed transactions between different databases. For example, one server is a mysql database, the other is an Oracle database, and the other may be an sqlserver, as long as each node in the global transaction supports XA transactions. Distributed transactions may be more common in the bank system transfer, for example, a user needs to transfer from Shanghai to a user account in Beijing for RMB 1000:

# Bank ofshanghai:

Updateuser_account set money = money-10000 where user = 'xiaozhang ';

# Bank ofBeijing:

Updateuser_account set money = money + 10000 where user = 'xiaoli ';

In this case, distributed transactions are required, either committed or rolled back. If a problem occurs on any node, the result is: 1 xiaozhang's account is deducted, but xiaoli does not receive the money; 2 xiaozhang's account is not deducted, but xiaoli receives the money.

A distributed Transaction is composed of one or more Resource managers, One Transaction Manager, and one Application Program.

Resource Manager: provides methods to access transaction resources. Generally, a database is a resource manager.

Transaction Manager: coordinates various transactions involved in global transactions. You need to communicate with the resource manager involved in the global transaction.

Application: defines the transaction boundary and specifies the operations in the global transaction.

In a Distributed Transaction in mysql, the resource manager is the mysql database, and the transaction manager is the Client Connected to the mysql server. As shown in:

Distributed transactions use the two-phase commit method. In the first phase, all nodes involved in the global transaction begin to prepare and tell the Transaction Manager that they are ready for submission. In the second stage, the transaction manager tells the resource manager to execute rollback or commit. If any node cannot be displayed as commit, all nodes must be rollback.

The current java jta java transaction API can well support mysql distributed transactions. For details, refer to the jta manual. The following example shows how to use jta to call mysql distributed transactions.

Recommended reading:

Startup, shutdown, and restoration of the InnoDB Storage Engine

MySQL InnoDB independent tablespace Configuration

Architecture of MySQL Server layer and InnoDB Engine Layer

InnoDB deadlock Case Analysis

MySQL Innodb independent tablespace Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.