Prevent benign spin between competing leaders with same index but differen term.

Remove lock from route processing for updating peers progress, altready handled in trackPeer.

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2023-02-27 11:21:33 -08:00
parent 43916290df
commit 2711460b7b

View File

@@ -2733,7 +2733,11 @@ func (n *raft) createCatchup(ae *appendEntry) string {
// Truncate our WAL and reset.
// Lock should be held.
func (n *raft) truncateWAL(term, index uint64) {
n.debug("Truncating and repairing WAL")
n.debug("Truncating and repairing WAL to Term %d Index %d", term, index)
if term == 0 && index == 0 {
n.warn("Resetting WAL state")
}
defer func() {
// Check to see if we invalidated any snapshots that might have held state
@@ -2762,6 +2766,11 @@ func (n *raft) truncateWAL(term, index uint64) {
}
// Reset our WAL.
func (n *raft) resetWAL() {
n.truncateWAL(0, 0)
}
// Lock should be held
func (n *raft) updateLeader(newLeader string) {
n.leader = newLeader
@@ -3097,7 +3106,9 @@ func (n *raft) processAppendEntryResponse(ar *appendEntryResponse) {
n.term = ar.term
n.vote = noVote
n.writeTermVote()
n.warn("Detected another leader with higher term, will stepdown and reset")
n.stepdown.push(noLeader)
n.resetWAL()
} else if ar.reply != _EMPTY_ {
n.catchupFollower(ar)
}
@@ -3109,14 +3120,6 @@ func (n *raft) handleAppendEntryResponse(sub *subscription, c *client, _ *Accoun
ar := n.decodeAppendEntryResponse(msg)
ar.reply = reply
n.resp.push(ar)
if ar.success {
n.Lock()
// Update peer's last index.
if ps := n.peers[ar.peer]; ps != nil && ar.index > ps.li {
ps.li = ar.index
}
n.Unlock()
}
}
func (n *raft) buildAppendEntry(entries []*Entry) *appendEntry {