Speaking of Paxos, many people know, and everyone's view of it is basically "obscure difficult to understand." In addition to the Lamport of the 2 famous native paper, online articles are also many. But it seems to look, always feel "enveloping", do not know why to do so, and what it can solve the problem.
 
I think the reason, on the one hand is a lot of Paxos data, are in the formal proof, to demonstrate the correctness of the algorithm, natural obscures, on the other hand, based on the Paxos of mature engineering practice is not much, we discuss to discuss, can not be implemented to the practical level.
 
And I also experienced such a "confused" process, and finally a little bit to understand what is Paxos.
 
And this sequence, trying to go from the beginning to the point, a little bit to lead everyone into the Paxos world.
 
A basic concurrency problem
 
Let's look at one of the most basic concurrency problems: Let's say I have a kv storage cluster, 3 clients, and send 3 requests to this cluster concurrently. Excuse me, when I finally go to get (x), x should be equal to a few.
 
The answer is: x = 1, or x = 3, or x = 5 are all right. But x = 4, is wrong.
 
Because 3 requests are concurrent from the client's point of view, the order in which 3 requests arrive at the server is indeterminate, so the final 3 results are possible.
 
Here's a key point: Put the above answer in another way, that is, if the result of the final cluster is x = 1. Then when CLIENT1 sends x = 1, the server returns x = 1, returns X=1 when Client2 sends x = 5, and returns X=7 when Client3 sends X=1. The equivalent of CLIENT1 's request was accepted, and Client2/client3 's request was rejected. If the end result of the cluster is x=3, or x=5, the same is true:
 
And this is a feature of the Paxos protocol. Now this is still obscure, and we'll come back to the question later.
What do you mean "timing" ?
 
Further refinement of the above problem: Suppose this kv cluster, there are 3 machines, 3 machines communicate with each other, the value of their own to the other machines, 3 clients to 3 machines sent 3 requests.
 
 
Let's say each machine has its own requests, which are stored in logs (including requests from clients and requests from other node). Then ask: When these 3 requests completed, 3 machines above the log, respectively, what order should be.
 
The following is the correct result: regardless of the order, as long as 3 machines above the log sequence is the same, the result is correct. For example, the 1th case, 3 machines above, the stored log order is x=1/x=3/x=5, then the final cluster, the value of x must be equal to 5. Other cases are similar.
 
It is clear that a total of 3 are in full alignment, a total of 6 cases.
 
And the following situation is wrong: Machine 1 above the log sequence is 1,3,5, so the final value is x=5; Machine 2 is 3,5,1, the final value is x=1; machine 3 is 1,5,3 and the final value is x=3. 3 machines above the value of X is inconsistent.
 
With this simple example, we can have a visual understanding of the "timing": Although 3 clients are concurrent, there is no sequencing, but to the server cluster, must be guaranteed 3 machines above, the log sequence is the same, this is called "distributed consistency." Paxos Solve what problem
 
In the example above, Node1 received the x=1 and copied it to Node2/node3;
Node2 received x=3, copy to Node1/node3;
Node3 after receiving x=5, copy to Node1/node2.
 
The client is concurrent, and the replication between 3 node is concurrent, so how to ensure that 3 node's final log order is the same. That is 1 of the 6 correct cases mentioned above.
 
For example, Node1 first received the client's x=1, then received Node3 x=5, and finally received node2 of x=3;
Node2 first received the client's x=3, then received Node1 X=1, and finally received node3 of x=5;
。。。
 
How to guarantee the same log order stored on 3 node ...
 
And this is the problem that Paxos to solve. In the next sequence, we'll step through the discussion of how Paxos solves this problem. finally
 
Unlike many Paxos articles, this article does not say what Paxos is, but rather introduces a scenario in which we can generally understand, a concurrency problem. If you understand the scene, the next look at Paxos, it will be a lot easier.