Understanding Paxos Algorithm

When I first came into contact with the Paxos algorithm, it was rare to think that I had a certain idea of ​​​​understanding. I wrote down the understanding process for communication, which may not strictly correspond to Paxos and the process. It mainly refers to the process of reaching a proposal. If there is a problem, I hope to correct it.

The purpose of the algorithm

There is a group of Acceptors. Simply put, each Acceptor has one vote and can only vote for one proposal; a group of Proposers provide proposals and coordinate to reach the final proposal.

The final purpose of voting is to have one and only one proposal. The proposal requires more than half of the votes. Of course, other proposals cannot get more than half of the votes.

Second, the algorithm understanding

First of all, all the votes owned by the Acceptor are likened to pits. Proposers' proposals are likened to radishes, greens, and cucumbers.

Occupying the pit: Prepare request , as long as the pit is not filled, whoever grabs it later can own it, and the occupied party cannot fill the pit and can only grab it again. The reason will be explained later.

Filling the pit: Accept request, the contents of the filled pit cannot be changed anymore

Time to occupy the pit: the proposal number, the order of occupying the pit corresponds to the small and large number of the number

The algorithm process can be simply described as the iteration of occupying and filling pits, and finally reaching more than half of a certain proposal to fill the pits. The description is convenient in three steps:

Step 1, grab the pit:

Each Proposer asks more than half of the Acceptors whether the pit has not been filled yet, and if so, what is being planted, and what is the time (number) for filling the pit; if the pit is not filled, grab it first and set time to grab. The Proposer that has already grabbed this pit (the number is smaller than the current one) can only be grabbed again next time.

Step 2, determine whether to fill the pit:

Each Proposer collects the Acceptor's reply, and in the reply message: what kind of radish has been filled in, and what is the latest to fill in the pit, assuming radish, how many kinds of radish are there in the reply information, and how many unfilled pits are there, if It is found that the number of radishes that have been planted + the number of pits that have not been filled is more than half, then you can consider planting radishes.

1) Why is it required that the number of radishes that have been planted + the number of pits that have not been filled in > half , because the number of pits that have not been filled has been preempted, unless it is robbed by other proposers, it can be guaranteed that more than half can be filled in Radish. Of course, if the pit is taken away by someone else, it is actually repeating this process.

2) Why do you consider the latest (largest number) to fill in the pit? It is not in this discussion. It may be to make all Proposer proposals converge quickly and reach a final agreement.

3) If the number of radishes that have been planted + the number of pits that have not been filled <= half , go back to step 1 directly.

4) If the pits involved in the current reply are all to be filled, then the specific types are also up to you, and generally fill in your own proposal.

Step three, fill the pit

Send a pit filling request to more than half of the Acceptors. If there is a pit to be filled and can be grabbed ( Prepare >= the current time to fill the pit), fill in

After completing step 3, there may not be more than half of the pits filled with radishes, and then go back to step 1 to grab the pits.

3. Summary

Guarantee that the last request to fill in the pit , the already planted X+> half of the pit to be filled, to ensure that more than half of X can be filled

1. In the initial state, more than half of the pits to be filled meet the requirements. The first Prepare request of the Proposer is generally the ones to be filled.

2. When considering filling the pits, if the already planted X + more than half of the pits to be filled, start filling the pits. If the pits are not robbed, it can be guaranteed that more than half of X can be filled in the end.

3. In the process of filling the pit, in case the pit that has been robbed is robbed again , consider 2 when initiating a pit filling request for the Proposer that robbed the pit.


Guess you like

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