Skip to content

Commit

Permalink
move guard
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenMathew committed Jul 13, 2024
1 parent 38cc515 commit 0ba71f3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3184,6 +3184,13 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {
return
}

if ae.term < n.term {
// ignore
n.debug("ignoring ae req from a leader with term %d which is less than ours", ae.term)
n.Unlock()
return
}

// Scratch buffer for responses.
var scratch [appendEntryResponseLen]byte
arbuf := scratch[:]
Expand Down Expand Up @@ -3294,12 +3301,7 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {
n.debug("Term higher than ours and we are not a follower: %v, stepping down to %q", n.State(), ae.leader)
n.stepdownLocked(ae.leader)
}
} else if ae.term < n.term {
// ignore
n.debug("ignoring ae req from a leader with term %d which is less than ours")
return
}
// FIX: we need to handle if term is less than ours as well, we should be ignoring the entry

// BUG: leader was being updated even if the leader's term was out of date (behind ours)
if isNew && n.leader != ae.leader && n.State() == Follower {
Expand Down

0 comments on commit 0ba71f3

Please sign in to comment.