Skip to content

Commit 6358d24

Browse files
committed
kvserver: pass context into write functor
Epic: none Release note: none
1 parent 16e00b6 commit 6358d24

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

pkg/kv/kvserver/kvstorage/snaprecv/sst_snapshot_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (s *SSTSnapshotStorageScratch) NewFile(
144144
// WriteSST creates an SST populated with the given write function, and writes
145145
// it to a file. Does nothing if no data is written.
146146
func (s *SSTSnapshotStorageScratch) WriteSST(
147-
ctx context.Context, write func(storage.Writer) error,
147+
ctx context.Context, write func(context.Context, storage.Writer) error,
148148
) error {
149149
if s.closed {
150150
return errors.AssertionFailedf("SSTSnapshotStorageScratch closed")
@@ -154,7 +154,7 @@ func (s *SSTSnapshotStorageScratch) WriteSST(
154154
sstFile := &storage.MemObject{}
155155
w := storage.MakeIngestionSSTWriter(ctx, s.st, sstFile)
156156
defer w.Close()
157-
if err := write(&w); err != nil {
157+
if err := write(ctx, &w); err != nil {
158158
return err
159159
}
160160
if err := w.Finish(); err != nil {

pkg/kv/kvserver/snapshot_apply_prepare.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type snapWriteBuilder struct {
2727

2828
todoEng storage.Engine
2929
sl stateloader.StateLoader
30-
writeSST func(context.Context, func(storage.Writer) error) error
30+
writeSST func(context.Context, func(context.Context, storage.Writer) error) error
3131

3232
truncState kvserverpb.RaftTruncatedState
3333
hardState raftpb.HardState
@@ -42,14 +42,9 @@ type snapWriteBuilder struct {
4242
// prepareSnapApply writes the unreplicated SST for the snapshot and clears disk data for subsumed replicas.
4343
func (s *snapWriteBuilder) prepareSnapApply(ctx context.Context) error {
4444
_ = applySnapshotTODO // 3.1 + 1.1 + 2.5.
45-
if err := s.writeSST(ctx, func(w storage.Writer) error {
46-
// Clear the raft state/log, and initialize it again with the provided
47-
// HardState and RaftTruncatedState.
48-
return s.rewriteRaftState(ctx, w)
49-
}); err != nil {
45+
if err := s.writeSST(ctx, s.rewriteRaftState); err != nil {
5046
return err
5147
}
52-
5348
_ = applySnapshotTODO // 3.2 + 2.1 + 2.2 + 2.3
5449
return s.clearSubsumedReplicaDiskData(ctx, s.todoEng)
5550
}
@@ -121,7 +116,7 @@ func (s *snapWriteBuilder) clearSubsumedReplicaDiskData(
121116
totalKeySpans := append([]roachpb.Span(nil), keySpans...)
122117
for _, subDesc := range s.subsumedDescs {
123118
// We have to create an SST for the subsumed replica's range-id local keys.
124-
if err := s.writeSST(ctx, func(w storage.Writer) error {
119+
if err := s.writeSST(ctx, func(ctx context.Context, w storage.Writer) error {
125120
// NOTE: We set mustClearRange to true because we are setting
126121
// RangeTombstoneKey. Since Clears and Puts need to be done in increasing
127122
// order of keys, it is not safe to use ClearRangeIter.
@@ -200,7 +195,7 @@ func (s *snapWriteBuilder) clearSubsumedReplicaDiskData(
200195
//
201196
// We need to additionally clear [b,sn).
202197

203-
if err := s.writeSST(ctx, func(w storage.Writer) error {
198+
if err := s.writeSST(ctx, func(ctx context.Context, w storage.Writer) error {
204199
return storage.ClearRangeWithHeuristic(
205200
ctx, reader, w,
206201
keySpans[i].EndKey, totalKeySpans[i].EndKey,

pkg/kv/kvserver/snapshot_apply_prepare_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func TestPrepareSnapApply(t *testing.T) {
4343

4444
var sb redact.StringBuilder
4545

46-
writeSST := func(ctx context.Context, write func(storage.Writer) error) error {
46+
writeSST := func(ctx context.Context, write func(context.Context, storage.Writer) error) error {
4747
// Use WriteBatch so that we print the writes in exactly the order in which
4848
// they are made. The real code creates an SST writer.
4949
b := eng.NewWriteBatch()
5050
defer b.Close()
51-
if err := write(b); err != nil {
51+
if err := write(ctx, b); err != nil {
5252
return err
5353
}
5454
str, err := print.DecodeWriteBatch(b.Repr())

0 commit comments

Comments
 (0)