From 6f0519ec6a2c728685ed57e3a03af4f1bff0b314 Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Thu, 7 Nov 2024 11:25:43 +0300 Subject: [PATCH] [#1450] engine: Batch addresses in `(*StorageEngine).Inhume` Signed-off-by: Aleksey Savchuk --- pkg/local_object_storage/engine/inhume.go | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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