From dce1422abcec6d31bbc7acf2d73a946e8d65e694 Mon Sep 17 00:00:00 2001 From: 1797818494 <1797818494@qq.com> Date: Sat, 3 Feb 2024 12:04:21 +0800 Subject: [PATCH 1/2] improve the lease Signed-off-by: 1797818494 <1797818494@qq.com> --- raft.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raft.go b/raft.go index 85b066ec..6ab5ae98 100644 --- a/raft.go +++ b/raft.go @@ -1062,7 +1062,7 @@ func (r *raft) Step(m pb.Message) error { case m.Term > r.Term: if m.Type == pb.MsgVote || m.Type == pb.MsgPreVote { force := bytes.Equal(m.Context, []byte(campaignTransfer)) - inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout + inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout && r.Lead != m.From if !force && inLease { // If a server receives a RequestVote request within the minimum election timeout // of hearing from a current leader, it does not update its term or grant its vote From 6cb42408b1b265893274e0fe98d2e4134d0f66cd Mon Sep 17 00:00:00 2001 From: 1797818494 <1797818494@qq.com> Date: Sat, 3 Feb 2024 13:44:28 +0800 Subject: [PATCH 2/2] fix name Signed-off-by: 1797818494 <1797818494@qq.com> --- raft.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raft.go b/raft.go index 6ab5ae98..418eae94 100644 --- a/raft.go +++ b/raft.go @@ -1062,7 +1062,7 @@ func (r *raft) Step(m pb.Message) error { case m.Term > r.Term: if m.Type == pb.MsgVote || m.Type == pb.MsgPreVote { force := bytes.Equal(m.Context, []byte(campaignTransfer)) - inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout && r.Lead != m.From + inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout && r.lead != m.From if !force && inLease { // If a server receives a RequestVote request within the minimum election timeout // of hearing from a current leader, it does not update its term or grant its vote