From 0ba71f37e7f72f65b2c7f94068a7539f9d27f0c3 Mon Sep 17 00:00:00 2001 From: reubenninan Date: Sat, 13 Jul 2024 12:00:38 +0000 Subject: [PATCH] move guard --- server/raft.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/raft.go b/server/raft.go index dad6b902c21..d5bcc0c5eee 100644 --- a/server/raft.go +++ b/server/raft.go @@ -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[:] @@ -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 {