mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user