diff --git a/pkg/storer/compact.go b/pkg/storer/compact.go index 1cb6ebc14f8..c9a2846c21b 100644 --- a/pkg/storer/compact.go +++ b/pkg/storer/compact.go @@ -91,6 +91,11 @@ func Compact(ctx context.Context, basePath string, opts *Options, validate bool) start := uint32(0) end := lastUsedSlot + batch, err := store.Batch(ctx) + if err != nil { + return err + } + for start < end { if slots[start] != nil { @@ -113,7 +118,7 @@ func Compact(ctx context.Context, basePath string, opts *Options, validate bool) } from.Location = to - if err := store.Put(from); err != nil { + if err := batch.Put(from); err != nil { return fmt.Errorf("store put: %w", err) } @@ -121,6 +126,10 @@ func Compact(ctx context.Context, basePath string, opts *Options, validate bool) end-- } + if err := batch.Commit(); err != nil { + return err + } + logger.Info("shard truncated", "shard", fmt.Sprintf("%d/%d", shard, sharkyNoOfShards-1), "slot", end) if err := sharkyRecover.TruncateAt(context.Background(), uint8(shard), end+1); err != nil {