Stabilty improvements for split votes.

Was incorrectly resetting term and exiting on failed vote. Also was not properly stepping down when we were a candidate and saw an entry from a leader.

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2021-01-17 13:34:56 -08:00
parent 5479a8e867
commit d653627e7a

View File

@@ -1361,13 +1361,6 @@ func (n *raft) runAsCandidate() {
n.switchToLeader()
return
}
} else {
n.Lock()
n.term = vresp.term
n.writeTermVote()
n.Unlock()
n.switchToFollower(noLeader)
return
}
case vreq := <-n.reqs:
n.processVoteRequest(vreq)
@@ -1440,6 +1433,15 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {
return
}
// If we received an append entry as a candidate we should convert to a follower.
if n.state == Candidate {
n.debug("Received append entry in candidate state from %q, converting to follower", ae.leader)
n.term = ae.term
n.Unlock()
n.stepdown <- ae.leader
return
}
// Catching up state.
catchingUp := n.catchup != nil
// Is this a new entry or a replay on startup?