Distributed consistency Algorithm Paxos

Source: Internet
Author: User

Paxos is a distributed consistency algorithm based on message passing, proposed by Leslie Lamport (Leslie Lambert) in 1990. is currently recognized as one of the most effective algorithms for solving distributed conformance problems.
?

Problems to be solved and the application scenarios

?
The problem to be solved by the Paxos algorithm can be understood as: in a distributed system of asynchronous communication, how to agree on a certain value (resolution).
Asynchronous communication here means that the message is lost, timed out, and disorderly in the network transmission process.
?
Typical application scenarios are:
In a distributed system, if the initial state of each node is consistent, and each node executes the same sequence of commands, then a consistent state can be obtained in the end. To ensure that each node executes the same sequence of commands, the consistency algorithm (such as the Paxos algorithm) needs to be executed on each instruction to ensure that each node directive is consistent.
?

Concept definition

?
Proposal: A proposal initiated to agree on a value, including the proposal number and the value of the proposal.
?
The following roles are involved:
Proposer: The sponsor of the proposal, in order to agree on a certain value, proposer can start any number of proposals at any speed, can be stopped or restarted.
Acceptor: Approving the proposal, responding to, making a commitment, or approving the proposal.
Learner: Proposal learners can obtain approved proposals from the acceptor.
?

Conventions

?
Paxos need to follow the following conventions:
1. A acceptor must approve the first proposal it received.
2. If the proposal with number n is approved, then all the numbers are greater than the N proposal, and the value must be the same as the value of the proposal with number N.
?

Algorithm description

?
Phase One: Preparation phase
?
1, proposer Select a proposal number N, to acceptor broadcast prepare (n) request.
2, Acceptor received the prepare (n) request, if the number n is greater than the previous response to all the prepare requested number, then the maximum number of previously approved proposal feedback to proposer, and promised to no longer receive a smaller number than n proposal. otherwise ignored.
?
Phase II: Approval phase
?
1, proposer received more than half of the acceptor response, if the response does not include any proposals, then the proposal number N and its own value, as a proposal to send the accept request to acceptor. Otherwise will number n, the value of the proposal with the largest number in the received response, and send the accept request to acceptor as a proposal.
2. Acceptor receives an accept request with number N, as long as acceptor has not responded to a prepare request with a number greater than N, the proposal can be approved.
?

Dead Loop problem

?
If Proposer1 presented a proposal numbered N1, and completed stage one. At the same time Proposer2 presented a proposal numbered N2, N2>N1, which also completed stage one. So acceptor promised not to approve the proposal of the number less than N2, when Proposer1 entered phase two o'clock, it will be ignored. Similarly, at this time, Proposer1 can put forward a proposal numbered as N3, N3>n2, will lead to Proposer2 of the proposal numbered N2 into Phase two o'clock is ignored. And so on, will go into the dead loop.
?
Workaround:
?
You can choose a proposer as the main proposer and agree that only the main proposer can make proposals. Therefore, as long as the main proposer can communicate with more than half of the acceptor, then any proposal with a higher number proposed by the master proposer will be approved.
?

Learner

?
Once Acceptor approves a proposal, it will be sent to all learner. In order to avoid large amounts of communication, acceptor can also issue approved proposals to the main learner, which is distributed by the main learner to other learner. Taking into account the main learner single point of issue, you can also consider Acceptor will approve the proposal, issued to the main learner group, distributed by the main learner group to other learner.
?

Reference documents

?
Paxos Made Simple (Chinese translation version)
Introduction of Phxpaxos realization principle of self-developed production Grade Paxos class Library
"Original" Step-by-step understanding of the Paxos algorithm
?

Postscript

?
The Paxos algorithm is relatively difficult to understand and implement, so the raft algorithm which is easier to understand and implement is presented later.
The follow-up will be summarized separately.

Distributed consistency Algorithm Paxos

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.