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

NRG (2.11): Don't revert pterm to beginning of log when installing snapshots #5792

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all 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
20 changes: 6 additions & 14 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,31 +1029,23 @@ func (n *raft) InstallSnapshot(data []byte) error {
}

if n.applied == 0 {
n.debug("Not snapshotting as there are no applied entries")
return errNoSnapAvailable
}

n.debug("Installing snapshot of %d bytes", len(data))

var term uint64
term := n.pterm
if ae, _ := n.loadEntry(n.applied); ae != nil {
// Use the term from the most recently applied entry if possible.
term = ae.term
} else if ae, _ = n.loadFirstEntry(); ae != nil {
// Otherwise see if we can find the term from the first entry.
term = ae.term
} else {
// Last resort is to use the last pterm that we knew of.
term = n.pterm
}

snap := &snapshot{
n.debug("Installing snapshot of %d bytes", len(data))

return n.installSnapshot(&snapshot{
lastTerm: term,
lastIndex: n.applied,
peerstate: encodePeerState(&peerState{n.peerNames(), n.csz, n.extSt}),
data: data,
}

return n.installSnapshot(snap)
})
}

// Install the snapshot.
Expand Down