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(snapshot): update last snapshot time across members #7968

Merged
merged 1 commit into from
Jul 30, 2021
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
9 changes: 6 additions & 3 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ func (n *node) applyCommitted(proposal *pb.Proposal) error {
}
glog.Warningf("Error while calling CreateSnapshot: %v. Retrying...", err)
}
atomic.StoreInt64(&lastSnapshotTime, time.Now().Unix())
// We can now discard all invalid versions of keys below this ts.
pstore.SetDiscardTs(snap.ReadTs)
return nil
Expand Down Expand Up @@ -1340,6 +1341,8 @@ func (n *node) updateRaftProgress() error {
return nil
}

var lastSnapshotTime int64 = time.Now().Unix()

func (n *node) checkpointAndClose(done chan struct{}) {
snapshotAfterEntries := x.WorkerConfig.Raft.GetUint64("snapshot-after-entries")
x.AssertTruef(snapshotAfterEntries > 10, "raft.snapshot-after must be a number greater than 10")
Expand Down Expand Up @@ -1369,7 +1372,6 @@ func (n *node) checkpointAndClose(done chan struct{}) {
return chk-first >= snapshotAfterEntries
}

lastSnapshotTime := time.Now()
snapshotFrequency := x.WorkerConfig.Raft.GetDuration("snapshot-after-duration")
for {
select {
Expand Down Expand Up @@ -1409,10 +1411,11 @@ func (n *node) checkpointAndClose(done chan struct{}) {
// Note: In case we're exceeding threshold entries, but have not exceeded the
// threshold time since last snapshot, calculate would be false.
calculate := raft.IsEmptySnap(snap) || n.Store.NumLogFiles() > 4 // #0
lastSnapTime := time.Unix(atomic.LoadInt64(&lastSnapshotTime), 0)
if snapshotFrequency == 0 {
calculate = calculate || exceededSnapshotByEntries() // #1

} else if time.Since(lastSnapshotTime) > snapshotFrequency {
} else if time.Since(lastSnapTime) > snapshotFrequency {
// If we haven't taken a snapshot since snapshotFrequency, calculate would
// follow snapshot entries.
calculate = calculate || exceededSnapshotByEntries() // #2, #3
Expand All @@ -1436,7 +1439,7 @@ func (n *node) checkpointAndClose(done chan struct{}) {
if err := n.proposeSnapshot(); err != nil {
glog.Errorf("While calculating and proposing snapshot: %v", err)
} else {
lastSnapshotTime = time.Now()
atomic.StoreInt64(&lastSnapshotTime, time.Now().Unix())
}
}
go n.abortOldTransactions()
Expand Down