Skip to content

Commit

Permalink
fix: batch
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Sep 29, 2023
1 parent 75cf483 commit 15b25a8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/storer/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -113,14 +118,18 @@ 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)
}

start++
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 {
Expand Down

0 comments on commit 15b25a8

Please sign in to comment.