The Two-Phase Commit Protocol

  • Post author:
  • Post category:칼럼
  • Post comments:0 Comments
  • Post last modified:January 26, 2020

The Two-Phase Commit (2PC) protocol is a simple and elegant ACP with two types of processes: A single coordinator that decides whether to reach a global commit or abort decision, and the participants that execute the transaction’s resource accesses and vote whether to commit or abort. The commit decision is made according to the global commit rule [11]:

  • If even one participant votes to abort the transaction, the coordinator has to reach a global abort decision.
  • If all participants vote to commit the transaction, the coordinator has to reach a global commit decision.

A description of 2PC that does not consider failures is provided in this section. Failure scenarios and a recovery protocol is described in section 2.6.2. Figure 2 should be helpful: The circles represent states, the whole lines represent state changes, the dashed lines represent messages (labeled with the message types), and the rectangles represent logging actions.

Figure 2: The Two-Phase Commit protocol

2PC has, not surprisingly, two phases:

Phase 1: A coordinator process is started (usually at the site where the transaction is initialized), writes a begin commit record in its log, sends a prepare message to the participants, and enters the wait state. This message also contains a unique transaction id (TID), which is also in all further messages in this protocol run.

When a participant receives a prepare message, it checks if it can commit the transaction. If it can, the participant writes a ready record in its log, sends a vote_commit message to the coordinator, and enters the ready state. Otherwise, the participants decides to unilaterally abort10 the transaction—it writes an abort record in the log and sends a vote_abort message to the coordinator. It enters the abort state and can forget about the transaction.

Phase 2: After the coordinator has received votes from all participants it decides whether to commit or abort according to the global commit rule, and writes this decision in the log. If the decision is to commit, it sends a global_commit message to all sites. Otherwise, it sends a global_abort message to all sites that voted to commit. Finally, it writes an end of transaction record in its log. The participants finish the transaction according to the decision and write the result in their logs [11].

To be accurate, the protocol described here is centralized 2PC with reliable message channels. There are many variations on 2PC that account for different network topologies, channel reliability and synchrony. These will not be discussed further here, as the described protocol is usable in our network model (see section 2.1) and strikes a balance between few messages and high concurrency.

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments