Skip to content

Commit 2f2991f

Browse files
committed
commit on error
1 parent 865b5ef commit 2f2991f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

store/store_delete.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,19 @@ func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) error {
9696
}
9797

9898
// deleteSequential deletes [from:to) header range from the store sequentially.
99-
func (s *Store[H]) deleteSequential(ctx context.Context, from, to uint64) error {
99+
func (s *Store[H]) deleteSequential(ctx context.Context, from, to uint64) (err error) {
100100
log.Debugw("starting delete range sequential", "from_height", from, "to_height", to)
101101

102102
batch, err := s.ds.Batch(ctx)
103103
if err != nil {
104104
return fmt.Errorf("new batch: %w", err)
105105
}
106106
ctx = badger4.WithBatch(ctx, batch)
107+
defer func() {
108+
if derr := batch.Commit(ctx); derr != nil {
109+
err = errors.Join(err, fmt.Errorf("committing batch: %w", derr))
110+
}
111+
}()
107112

108113
s.onDeleteMu.Lock()
109114
onDelete := slices.Clone(s.onDelete)
@@ -115,10 +120,6 @@ func (s *Store[H]) deleteSequential(ctx context.Context, from, to uint64) error
115120
}
116121
}
117122

118-
if err := batch.Commit(ctx); err != nil {
119-
return fmt.Errorf("committing batch: %w", err)
120-
}
121-
122123
return nil
123124
}
124125

0 commit comments

Comments
 (0)