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

kvserver: use background context when applying snapshots #73484

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/store_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ func (s *Store) processRaftSnapshotRequest(
var expl string
var err error
stats, expl, err = r.handleRaftReadyRaftMuLocked(ctx, inSnap)
maybeFatalOnRaftReadyErr(ctx, expl, err)
if !stats.snap.applied {
// This line would be hit if a snapshot was sent when it isn't necessary
// (i.e. follower was able to catch up via the log in the interim) or when
// multiple snapshots raced (as is possible when raft leadership changes
// and both the old and new leaders send snapshots).
log.Infof(ctx, "ignored stale snapshot at index %d", snapHeader.RaftMessageRequest.Message.Snapshot.Metadata.Index)
}
maybeFatalOnRaftReadyErr(ctx, expl, err)
return nil
})
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/kv/kvserver/store_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,13 @@ func (s *Store) receiveSnapshot(
return err
}
inSnap.placeholder = placeholder
if err := s.processRaftSnapshotRequest(ctx, header, inSnap); err != nil {

// Use a background context for applying the snapshot, as handleRaftReady is
// not prepared to deal with arbitrary context cancellation. Also, we've
// already received the entire snapshot here, so there's no point in
// abandoning application half-way through if the caller goes away.
applyCtx := s.AnnotateCtx(context.Background())
if err := s.processRaftSnapshotRequest(applyCtx, header, inSnap); err != nil {
return sendSnapshotError(stream, errors.Wrap(err.GoError(), "failed to apply snapshot"))
}
return stream.Send(&SnapshotResponse{Status: SnapshotResponse_APPLIED})
Expand Down