From 60ad4c8192f1156a75357aeeff3dfcea9707d224 Mon Sep 17 00:00:00 2001 From: Matthias Hanel Date: Sat, 13 Mar 2021 18:43:10 -0500 Subject: [PATCH] Incorporating review comments Signed-off-by: Matthias Hanel --- server/raft.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/server/raft.go b/server/raft.go index 279c6779..663337ce 100644 --- a/server/raft.go +++ b/server/raft.go @@ -147,9 +147,6 @@ type raft struct { c *client dflag bool - // last term this node was leader - llterm uint64 - // Subjects for votes, updates, replays. psubj string rpsubj string @@ -2051,7 +2048,6 @@ func (n *raft) runAsCandidate() { for len(n.votes) > 0 { <-n.votes } - lastTermAsLeader := n.llterm n.Unlock() // Send out our request for votes. @@ -2084,7 +2080,6 @@ func (n *raft) runAsCandidate() { case <-tikChan: // disable timeout and receipt of more votes voteChan = nil - tikChan = nil if won { // we are here if we won the election but some server did not respond n.switchToLeader() @@ -2098,9 +2093,8 @@ func (n *raft) runAsCandidate() { votes++ if n.wonElection(votes) { // This would be ok as we'd be guaranteed to have the latest history. - if len(n.peers) == votes || lastTermAsLeader+1 == n.term { - // Become LEADER if we have won and gotten a quorum with everyone or if we have been leader - // in the previous round and thus already waited + if len(n.peers) == votes { + // Become LEADER if we have won and gotten a quorum with everyone n.switchToLeader() return } else { @@ -3072,6 +3066,5 @@ func (n *raft) switchToLeader() { } n.debug("Switching to leader") n.leader = n.id - n.llterm = n.term n.switchState(Leader) }