What is a two-phase commit protocol (two-phase commit protocol)

Source: Internet
Author: User

Reprinted: http://hi.baidu.com/liuhann/item/d644cfd873c904ffcb0c39b1

Two-phase submission Protocol

The key to implementing distributed transactions is the two-phase commit protocol. In this Protocol, one or more Resource Manager activities are controlled by a separate software component called the Transaction Coordinator. The five steps in this Protocol are as follows:

ApplicationProgramCall the commit method in the Transaction Coordinator.

The transaction Coordinator contacts each resource manager involved in the transaction and notifies them to prepare for committing the transaction (this is the beginning of the first phase ).

To respond to the preparation phase in a positive way, the resource manager must put itself in the following status: ensure that the transaction can be committed when the transaction is requested, or roll back the transaction when the transaction is required to be rolled back. Most resource managers write the log files (or equivalent files) that they plan to change to the persistent storage. If the resource manager cannot prepare a transaction, it will respond to the Transaction Coordinator with a negative response.

The transaction Coordinator collects all responses from the resource manager.

In the second stage, the Transaction Coordinator notifies each resource manager of the transaction result. If any resource manager makes a negative response, the Transaction Coordinator sends a rollback command to all resource managers involved in the transaction. If the resource manager responds positively, the Transaction Coordinator instructs all resource managers to submit transactions. Once the resource manager is notified to submit, subsequent transactions cannot fail. By responding to the first stage in a positive way, each resource manager has ensured that the transaction will not fail if it is notified to commit the transaction later.

Figure 1 and figure 2 use two sequence diagrams to describe the two-phase commit protocol.

Figure 1 transaction commit

Figure 1 shows the transaction succeeded (committed ). Figure 2 shows the two-phase commit protocol when one of the resource managers cannot submit for some reason.

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.