Skip to content

Commit

Permalink
Fix candidate stepdown logic
Browse files Browse the repository at this point in the history
Candidates should not be stepping down based on their pterm but rather their actual term.

Signed-off-by: reubenninan <[email protected]>
  • Loading branch information
ReubenMathew committed Jul 29, 2024
1 parent 12e1889 commit cf84c4b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3187,10 +3187,9 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {
// another node has taken on the leader role already, so we should convert
// to a follower of that node instead.
if n.State() == Candidate {
// Ignore old terms, otherwise we might end up stepping down incorrectly.
// Needs to be ahead of our pterm (last log index), as an isolated node
// could have bumped its vote term up considerably past this point.
if ae.term >= n.pterm {
// If we have a leader in the current term or higher, we should stepdown,
// write the term and vote if the term of the request is higher.
if ae.term >= n.term {
// If the append entry term is newer than the current term, erase our
// vote.
if ae.term > n.term {
Expand Down

0 comments on commit cf84c4b

Please sign in to comment.