I am not sure if I understand the RequestVote RPC detail in Raft correctly.
In the paper, it says
Receiver implementation:
1. Reply false if term < currentTerm (§5.1)
2. If votedFor is null or candidateId, and candidate’s log is at least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)
In which circumstance will voteFor == candidateId
hold true when the receiver receives RequestVote RPC? A candidate will not send another RequestVote RPC during the same term. If it starts another election, the term will increase, so the receiver should convert to a follower and voteFor is null
.
In my previous implementation of Raft, my logic is as follow:
If votedFor is null or me, and candidate’s log is at least as up-to-date as receiver’s log, grant vote
Though it is obviously wrong, it seems to work fine, that is, the leader election and send requestVotes can work stably.
Any advice will be greatly appreciated and thanks in advance