Skip to content

Commit 16e00b6

Browse files
committed
spanrecv: squash WriteSST method
Epic: none Release note: none
1 parent 031ee73 commit 16e00b6

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func (s *SSTSnapshotStorageScratch) NewFile(
146146
func (s *SSTSnapshotStorageScratch) WriteSST(
147147
ctx context.Context, write func(storage.Writer) error,
148148
) error {
149+
if s.closed {
150+
return errors.AssertionFailedf("SSTSnapshotStorageScratch closed")
151+
}
152+
153+
// TODO(itsbilal): Write to SST directly rather than buffer in a MemObject.
149154
sstFile := &storage.MemObject{}
150155
w := storage.MakeIngestionSSTWriter(ctx, s.st, sstFile)
151156
defer w.Close()
@@ -155,28 +160,15 @@ func (s *SSTSnapshotStorageScratch) WriteSST(
155160
if err := w.Finish(); err != nil {
156161
return err
157162
}
158-
if w.DataSize > 0 {
159-
// TODO(itsbilal): Write to SST directly rather than buffer in a MemObject.
160-
return s.writeSSTData(ctx, sstFile.Data())
161-
}
162-
return nil
163-
}
164-
165-
// writeSSTData writes SST data to a file. The method closes
166-
// the provided SST when it is finished using it. If the provided SST is empty,
167-
// then no file will be created and nothing will be written.
168-
func (s *SSTSnapshotStorageScratch) writeSSTData(ctx context.Context, data []byte) error {
169-
if s.closed {
170-
return errors.AssertionFailedf("SSTSnapshotStorageScratch closed")
171-
}
172-
if len(data) == 0 {
163+
if w.DataSize == 0 {
173164
return nil
174165
}
166+
175167
f, err := s.NewFile(ctx, 512<<10 /* 512 KB */)
176168
if err != nil {
177169
return err
178170
}
179-
if err := f.Write(data); err != nil {
171+
if err := f.Write(sstFile.Data()); err != nil {
180172
f.Abort()
181173
return err
182174
}

0 commit comments

Comments
 (0)