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

fix(Alpha): Immediately take a snapshot if we don't have one (#6458) #6969

Merged
merged 1 commit into from
Nov 24, 2020
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
19 changes: 16 additions & 3 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,22 @@ func (n *node) checkpointAndClose(done chan struct{}) {
}

if n.AmLeader() {
var calculate bool
// If leader doesn't have a snapshot, we should create one immediately. This is very
// useful when you bring up the cluster from bulk loader. If you remove an alpha and
// add a new alpha, the new follower won't get a snapshot if the leader doesn't have
// one.
snap, err := n.Store.Snapshot()
if err != nil {
glog.Errorf("While retrieving snapshot from Store: %v\n", err)
continue
}
calculate := raft.IsEmptySnap(snap) // If no snapshot, then calculate one immediately.

if chk, err := n.Store.Checkpoint(); err == nil {
if first, err := n.Store.FirstIndex(); err == nil {
// Save some cycles by only calculating snapshot if the checkpoint has gone
// quite a bit further than the first index.
calculate = chk >= first+uint64(x.WorkerConfig.SnapshotAfter)
calculate = calculate || chk >= first+uint64(x.WorkerConfig.SnapshotAfter)
glog.V(3).Infof("Evaluating snapshot first:%d chk:%d (chk-first:%d) "+
"snapshotAfter:%d snap:%v", first, chk, chk-first,
x.WorkerConfig.SnapshotAfter, calculate)
Expand All @@ -916,7 +926,10 @@ func (n *node) checkpointAndClose(done chan struct{}) {
// snapshotting. We just need to do enough, so that we don't have a huge backlog of
// entries to process on a restart.
if calculate {
if err := n.proposeSnapshot(x.WorkerConfig.SnapshotAfter); err != nil {
// We can set discardN argument to zero, because we already know that calculate
// would be true if either we absolutely needed to calculate the snapshot,
// or our checkpoint already crossed the SnapshotAfter threshold.
if err := n.proposeSnapshot(0); err != nil {
glog.Errorf("While calculating and proposing snapshot: %v", err)
}
}
Expand Down