Skip to content

Commit f831666

Browse files
committed
Fixup: Make start and abort multipart insert version scoped
1 parent afbc5a0 commit f831666

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

go/oasis-node/cmd/storage/checkpoint.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ func importCheckpoints(ctx context.Context, ndb api.NodeDB, ns common.Namespace,
300300
return fmt.Errorf("failed to read checkpoints: %w", err)
301301
}
302302

303+
if len(cps) == 0 {
304+
return fmt.Errorf("no checkpoints found")
305+
}
306+
307+
if err := ndb.StartMultipartInsert(cps[0].Root.Version); err != nil {
308+
return fmt.Errorf("failed to start multipart insert: %w", err)
309+
}
310+
defer func() {
311+
if err := ndb.AbortMultipartInsert(); err != nil {
312+
logger.Error("failed to abort multi-part insert", "err", err)
313+
}
314+
}()
303315
var roots []node.Root
304316
for _, cp := range cps {
305317
if err := importCp(ctx, ndb, provider, cp); err != nil {
@@ -315,15 +327,6 @@ func importCheckpoints(ctx context.Context, ndb api.NodeDB, ns common.Namespace,
315327
}
316328

317329
func importCp(ctx context.Context, ndb api.NodeDB, provider checkpoint.Creator, cp *checkpoint.Metadata) error {
318-
if err := ndb.StartMultipartInsert(cp.Root.Version); err != nil {
319-
return fmt.Errorf("failed to start multipart insert: %w", err)
320-
}
321-
defer func() {
322-
if err := ndb.AbortMultipartInsert(); err != nil {
323-
logger.Error("failed to abort multi-part insert", "err", err)
324-
}
325-
}()
326-
327330
for idx := range cp.Chunks {
328331
chunk, err := cp.GetChunkMetadata(uint64(idx))
329332
if err != nil {

0 commit comments

Comments
 (0)