@@ -146,6 +146,11 @@ func (s *SSTSnapshotStorageScratch) NewFile(
146
146
func (s * SSTSnapshotStorageScratch ) WriteSST (
147
147
ctx context.Context , write func (storage.Writer ) error ,
148
148
) 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.
149
154
sstFile := & storage.MemObject {}
150
155
w := storage .MakeIngestionSSTWriter (ctx , s .st , sstFile )
151
156
defer w .Close ()
@@ -155,28 +160,15 @@ func (s *SSTSnapshotStorageScratch) WriteSST(
155
160
if err := w .Finish (); err != nil {
156
161
return err
157
162
}
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 {
173
164
return nil
174
165
}
166
+
175
167
f , err := s .NewFile (ctx , 512 << 10 /* 512 KB */ )
176
168
if err != nil {
177
169
return err
178
170
}
179
- if err := f .Write (data ); err != nil {
171
+ if err := f .Write (sstFile . Data () ); err != nil {
180
172
f .Abort ()
181
173
return err
182
174
}
0 commit comments