-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VotedFor is not stored when a node is candidate and receives an AppendEntriesRpc #29
Comments
The In the scenario you said, when Node 2 and 3 become followers, they will save the first log, a NoOp log with only term in it. So Node 4 won't have a chance to become a leader without that log. The NoOp log is the tricky part in the Raft algorithm. I cannot remember the exact chapter where it is discussed. Maybe the edge cases in the last several chapters. |
But the log is written after the node becomes follower from candidate. |
Sorry, my explanation might not be clear. The NoOp log is inserted by the new leader and replicated to followers.
So, Node 4 won't get enough votes before step 2 or after step 2. Hope this answers your question. |
Okay, I see. Thanks for your further explanation. You mean the leader writes NoOp in this task, right?
And in this task the leader will send AppendEntriesRpc requests to other nodes. But the 2nd step in your comment is not atomic, i.e., the operation set leader and merge logs are executed in two lines: xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeImpl.java Lines 611 to 612 in 3442abc
So here's the concurrency scenario: before appendEntries(rpc) is executed (before writing NoOp log), Node 4 can launch the new leader election process and get votes from Node 2 and 3.
|
I guess you have misunderstood the thread model of XRaft. It's a single thread application except the connection handlers. For the node receiving xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeImpl.java Lines 580 to 585 in 3442abc
Any new messages will be queued and processed later, not at the same time. TaskContext comes from here. xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeBuilder.java Lines 268 to 269 in 3442abc
|
Sorry for my misunderstanding. Now I've got the thread model. Thanks again for your explanation. I seemingly find out a possible buggy scenario, which can occur when using After Node 1 finishes synchronizing the NoOp log (
We know that votedFor == null holds on Node 2 and 3.
Here in
|
Of course node 2 and 3 should vote for node 4 if node 4 has effectively latest log. After node 4 receives |
A network partition is not essential. When |
Here the candidate should store the message sender, i.e., current leader, in votedFor.
xraft/xraft-core/src/main/java/in/xnnyygn/xraft/core/node/NodeImpl.java
Line 611 in 3442abc
This issue can result in two leader with the same term in the following complex scenario.
Consider a cluster of 5 nodes. Node 1 ~ 3 become candidates with term 1. Node 4 and 5 are followers.
Here both Node 1 and Node 4 are the leader with term 1, which violate Raft's safety property.
The text was updated successfully, but these errors were encountered: