问题
I have pasted pseudocode for a paxos algorithm here:
What is a "view" in the Paxos consensus algorithm?
and was wondering if someone could point me in the right direction.
The algorithm says that each node has a "state" which contains a bunch of information the node should keep track of.
Suppose we have two nodes: Node #1 and Node #2. In the simplest case Node #2 joins Node #1 and they both play paxos. What exactly happens to the states of Node #1 and Node #2 after 2 joins 1? When does the "views" data structure change and what does it contain? If someone can explain to me this simple case of two nodes playing paxos, then I think I can figure out multiple node case.
My current understanding (which I'm pretty sure is not correct) is as follows:
- Node #2 sends a message to join Node #1.
- Node #1 receives message from Node #2 asking to join.
- Node #1 assumes leadership and kicks into phase 1, computes my_num = max(0,0) + 1 = 1
- Node #1 sends all nodes in views[0] (which is empty) prepare(1,1)
- Node #1 sends initial contact node (Node #2) prepare(1,1)
- Node #1 sends Node #1 (itself) prepare(1,1)
- Node #2 receives prepare(1,1). It sets its num_h=1 and returns to leader PROMISE(0,{empty list})
- Node #1 receives prepare(1,1) and sets its num_h=1 and returns itself PROMISE(0,{empty list}).
now we get to phase 2
This is where I am quite confused.
Node #1 is the leader and it receives two PROMISE(0,{empty list}) messages. According to the algorithm, if the leader gets a majority of promises in views[0] then it can set a value for "v" and send the ACCEPT message to all responders.
What I am confused about is currently the views[0] for the leader is empty so how can you compute the majority of an empty list?
Also, let's assume the leader has received a majority of promises and proceeds to set v = set of pingable nodes (including self). What exactly are pingable nodes? Is it just Node #1 and Node #2?
Would appreciate all / any help and will definitely award points to those that help.
回答1:
The pseudocode is not specialized for a particular problem. In fact, the professor said we don't need to use pseudocode if we don't want to and said we can look at other Paxos papers (i.e. paxos made simple, paxos made live,etc..) for guidance on implementing this algorithm. Maybe you are right, I should probably look at Wikipedia to implement this algorithm. So the views[..] is simply a hash map of and a node can choose any value it wishes to. If I understand you correctly, you say the majority statement just checks if it received "enough" PROMISE messages. But the only way to know if we have enough is if the node keeps track of who its group members are. Which means that I need a different data structure for this.
Also, I cannot award points to you because you made a comment. If you post an answer then I can give you points.
来源:https://stackoverflow.com/questions/10558382/how-to-make-sense-of-phase-2-in-paxos-distributed-consensus-algorithm