The consistency protocol in Distributed system

Source: Internet
Author: User

Objective

In the process of distributed system design, we need to consider the guideline of CAP theory, as shown in, p partition fault tolerance, considering that distributed system is deployed on multiple nodes, partition fault tolerance is the most basic of distributed system. So we can only make a tradeoff between consistency and usability. So there are a lot of consistency agreements. Well-known protocols have two-phase commit protocols, three-phase commit protocols, and Paxos algorithms . This paper mainly introduces the theoretical basis of the two-phase submission protocol and the three-phase commit protocol.

Basic concepts

① two phase commit.

2PC is the abbreviation for Two-phase-commit, which is two-phase commit. The second stage is divided into committing the transaction request and executing the transaction commit.

② three-phase submission

3pc is the abbreviation for Three-phase-commit, which is a three-phase commit. Three stages are divided into Cancommit, Precommit and Docommit.

③ Coordinator

A component that uniformly dispatches the execution logic of all distributed nodes is called the coordinator. When a transactional operation needs to span multiple distributed nodes, in order to maintain the acid characteristics of the transaction, it is necessary to introduce a component called "Coordinator" to uniformly dispatch the execution logic of all distributed nodes.

④ participants

Distributed nodes that are dispatched by the Coordinator are called participants.

2PC

The two-phase commit protocol, which is considered a consistency protocol, is used to ensure data consistency in distributed systems. The two-phase commit protocol, as the name implies, is divided into two phases: committing a transaction request and executing a transaction commit .

① Commit a transaction request

(1). Transaction inquiry: The coordinator sends transactional content to all participants, asking if a transaction commit operation can be performed and starting to wait for the response of each participant.

(2). Perform transactions: Transaction operations performed by each participant node, and the undo and redo information is logged in the transaction log.

(3). Each participant responds to the Coordinator's response to a transaction inquiry: If a participant successfully performs a transactional operation, it responds to the coordinator yes to indicate that the transaction can be executed, and if the participant does not successfully perform the transaction operation, the response to the Coordinator No is indicated that the transaction cannot be executed.

② performing a transaction commit

(1). Performing a transaction submission

If all the participants responded with a yes, the transaction commits.

(2). Interrupt Transaction

If any of the participants ' feedback is no, or after waiting for a timeout, no feedback is collected from all participants. The transaction will be interrupted.

Summary: The two-phase commit protocol is simple in principle and easy to implement. But there are synchronous blockages, single point problems, brain fissures, too conservative.

3PC

The three-phase commit protocol, an improved version of the two-phase commit agreement, divides the process of submitting a transaction request into a split. The formation of Cancommit, Precommit, do Commit three stages of composition.

①cancommit

Transaction inquiry: The coordinator sends a CANCOMMIT request to all participants that contains the transactional content, asks if the transaction commit operation can be performed, and starts waiting for the response of each participant.

Each participant responds to the Coordinator with a response to the transaction inquiry: The participant receives the CANCOMMIT request from the coordinator and, if it thinks it can execute smoothly, gives the feedback yes and enters the standby state. Otherwise feedback No.

②precommit

Perform a transaction pre-commit: If the coordinator obtains feedback from all participants is yes, then the transaction is pre-committed.

Transaction interruption: If any of the participants feedback the information is no, or wait for timeout, has not collected the feedback information of all participants. The transaction will be interrupted.

③do Commit

Execute commit: If the coordinator receives all the participant ACK responses, the pre-commit status is set to the state of the commit.

Interrupt transaction: Any one participant coordinates this feedback no response. Then the transaction will be interrupted.

Summary: Reduce the blocking range of participants and be able to continue to agree after a single point of failure.

The three-stage reduction of the participant blocking range, but also introduces a new problem, after the participants received the PRECOMMIT message, if a network partition, the coordinator is located in the node and the participants can not communicate, the participants will still commit transactions, which will inevitably cause data inconsistencies.

2PC and 3PC commit protocols do not fully resolve the problem of consistency, another very important and effective algorithm Paxos is a highly fault-tolerant consistency algorithm.

The consistency protocol in Distributed system

Related Article

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.