guille / RaftCore

An implementation of the Raft algorithm using .NET Core
MIT License
67 stars 22 forks source link

Add vote codition #8

Closed cjmld5 closed 3 years ago

cjmld5 commented 3 years ago

in RequestVote method,should we compare with term > CurrentTerm and vote true?

if(term>CurrentTerm)
 voteGranted = true;
guille commented 3 years ago

I don't think so. It's been a while, but I just opened the Raft paper to check and I think your proposed change doesn't correctly follow the algorithm.

You can refer to Figure 2 in the paper for a summary of the RequestVote receiver implementation, or read §5.2 for more context.

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)