Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Raft Improvements #5951

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3604,13 +3604,7 @@ func (n *raft) processPeerState(ps *peerState) {
func (n *raft) processAppendEntryResponse(ar *appendEntryResponse) {
n.trackPeer(ar.peer)

if ar.success {
// The remote node successfully committed the append entry.
n.trackResponse(ar)
arPool.Put(ar)
} else if ar.term > n.term {
// The remote node didn't commit the append entry, it looks like
// they are on a newer term than we are. Step down.
if ar.term > n.term {
n.Lock()
n.term = ar.term
n.vote = noVote
Expand All @@ -3619,6 +3613,20 @@ func (n *raft) processAppendEntryResponse(ar *appendEntryResponse) {
n.stepdownLocked(noLeader)
n.Unlock()
arPool.Put(ar)
return
}

// ignore responses from older terms
if ar.term < n.term {
n.debug("Ignoring old append entry response from term %d", ar.term)
arPool.Put(ar)
return
}

if ar.success {
// The remote node successfully committed the append entry.
n.trackResponse(ar)
arPool.Put(ar)
} else if ar.reply != _EMPTY_ {
// The remote node didn't commit the append entry and they are
// still on the same term, so let's try to catch them up.
Expand Down Expand Up @@ -4074,15 +4082,9 @@ func (n *raft) processVoteRequest(vr *voteRequest) error {
voteOk := n.vote == noVote || n.vote == vr.candidate
if voteOk && (vr.lastTerm > n.pterm || vr.lastTerm == n.pterm && vr.lastIndex >= n.pindex) {
vresp.granted = true
n.term = vr.term
n.vote = vr.candidate
n.writeTermVote()
n.resetElectionTimeout()
} else {
if vr.term >= n.term && n.vote == noVote {
n.term = vr.term
n.resetElect(randCampaignTimeout())
}
}

// Term might have changed, make sure response has the most current
Expand Down
Loading