diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index 35ce50f65..db8ae40d0 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -17,6 +17,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" + "golang.org/x/sync/errgroup" ) // InhumePrm encapsulates parameters for inhume operation. @@ -72,8 +73,30 @@ func (e *StorageEngine) Inhume(ctx context.Context, prm InhumePrm) (res InhumeRe defer span.End() err = e.execIfNotBlocked(func() error { - res, err = e.inhume(ctx, prm) - return err + groupSize := 100 + totalSize := len(prm.addrs) + batchSize := max(totalSize/groupSize, 1) + + g := errgroup.Group{} + g.SetLimit(groupSize) + + for batchBase := 0; batchBase < totalSize; batchBase += batchSize { + batchPrm := InhumePrm{ + tombstone: prm.tombstone, + // TODO: write tests with different number of address, + // especially when + // (totalSize > groupSize) and (totalSize % groupSize != 0) + addrs: prm.addrs[batchBase:min(batchBase+batchSize, totalSize)], + forceRemoval: prm.forceRemoval, + } + + g.Go(func() error { + _, err = e.inhume(ctx, batchPrm) + return err + }) + } + + return g.Wait() }) return