Briefly describe the paxos algorithm

Enter image description

The paxos algorithm is a message-passing and highly fault-tolerant algorithm. The problem it solves is how a distributed system can agree on a certain value or a certain agreement. The premise of the algorithm is to assume that there is no Byzantine generals problem. .

There are three roles in the algorithm: proposer, accpetor and learner. The proposer is responsible for making proposals, the acceptor is responsible for making decisions on the proposal, and the learner is responsible for learning the obtained proposals. In order to avoid a single point of failure, there will be a set of acceptors, proposers send proposals to the set, each member of the acceptor set may agree to the proposal and each acceptor can only approve one proposal, when more than half of the members agree, agree to the proposal.

It is mainly divided into two stages: prepare stage and accept stage respectively. The first is the prepare stage. The proposer first proposes a proposal numbered Mn, and sends a prepare request to the accpetor set. Accept gives feedback: It is guaranteed that no proposal with a smaller number than Mn will be accepted; if the acceptor has approved a proposal, it will return the value of the approved proposal with the highest number to the proposer.

If the acceptor receives a request numbered Mn and the number is greater than the number of all prepare requests that the accpetor has responded to, it will feed back the proposal value with the highest number that it has approved to the proposer, and the acceptor promises not to accept any more number ratios. Mn small proposal. (Optimization: ignore requests with numbers less than approved proposals).

If the proposer receives at least half of the set of responses, it sends an accept request for Mn Vn to Accpetor. Vn is the value of the highest numbered proposal among all the responses received. If the response does not include a value, any value can be chosen by the proposer.

Then there is the accpet stage, which is to accept the requirements of the proposal. When the Acceptor receives the accpet request, as long as it does not receive any prepare request with a number greater than Mn, the proposal will be passed.

Optimization: In order to avoid an infinite loop, for example, two proposers propose a series of proposals with increasing numbers at a time, and a main proposer can be generated, and the proposal can only be proposed by the main proposer.

Application of paxos algorithm: chubby (distributed lock service, master election in GFS).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325173315&siteId=291194637