Introduction to distributed transactions

Source: Internet
Author: User

1. Transaction can be divided into local transaction and global transaction.
A connection commit is called a local transaction.
The commit involving multiple connections is called global transaction.
The author mentioned that global transaction.

2. Global transaction requires support for XA interfaces (including in JTA.

Import javax. SQL. xaconnection;
Import javax. transaction. Xa. Xid;
Import javax. transaction. Xa. xaresource;
Import javax. transaction. Xa. xaexception;
Import javax. transaction. transaction;
Import javax. transaction. transactionmanager;

The
Javax. SQL. xaconnection;
Javax. transaction. Xa. Xid;
Javax. transaction. Xa. xaresource;

The implementation of these XA interfaces requires the JDBC provision of the database.
The database itself must support Xa. Database JDBC must also provide XA implementation.

Oracle, Sybase, DB2, SQL Server, and other large databases support Xa and global transaction.
My SQL does not support local transaction, let alone Global transation.

3. Xa requires two-phase commit: prepare and commit.
Assume there are two connections, con1, con2. The general process is as follows,

Con1 = xaresouce1.getconnection...
Con2 = xaresouce2.getconnection...

Con1 do some thing.
Con2 do some thing.
After they finish.

Pre1 = xaresouce1.prepare ();
Pre2 = xaresouce2.prepare ();

If (both pre1 and pre2 are OK ){
Xaresouce1 and 2 commit
} Else {
Xaresouce1 and 2 rollback
}

As mentioned above, when xaresouce1 and 2 commit,
Maybe xaresouce1 commit () is successful, and xaresouce2 commit () fails.
At this time, a "heuristic exception" will be thrown ". The program can handle this exception. For example, xaresouce. Recover.
However, in general, there is no other way. The data administrator needs to perform all the Undo operations based on the data operation log, or recover the data backup.
Some databases generate a "reverse operation" log when performing data operations. For example, insert to delete.

4.The implementation of transactionmanager can handle multiple xaresouce (one xaresouce list) situations.
For example, tyrex. Or the transaction implementation code of EJB server such as JBoss.

 


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.