From cbfeb724662ccc8c041286cacbf8ca18df2eedf7 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 2 Feb 2024 20:14:47 +0300 Subject: [PATCH] [#956] policer: Remove WithMaxCapacity option We already provide the pool and this argument is used only for preallocation. No functional changes. Signed-off-by: Evgenii Stratonikov --- cmd/frostfs-node/object.go | 1 - pkg/services/policer/option.go | 10 ---------- pkg/services/policer/policer.go | 2 +- pkg/services/policer/policer_test.go | 8 ++++++++ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cmd/frostfs-node/object.go b/cmd/frostfs-node/object.go index 5c82f0dcc..7f1d094fd 100644 --- a/cmd/frostfs-node/object.go +++ b/cmd/frostfs-node/object.go @@ -263,7 +263,6 @@ func addPolicer(c *cfg, keyStorage *util.KeyStorage, clientConstructor *cache.Cl ) } }), - policer.WithMaxCapacity(c.cfgObject.pool.replicatorPoolSize), policer.WithPool(c.cfgObject.pool.replication), policer.WithMetrics(c.metricsCollector.PolicerMetrics()), ) diff --git a/pkg/services/policer/option.go b/pkg/services/policer/option.go index fe47555c4..92cf83a84 100644 --- a/pkg/services/policer/option.go +++ b/pkg/services/policer/option.go @@ -64,8 +64,6 @@ type cfg struct { taskPool *ants.Pool - maxCapacity int - batchSize, cacheSize uint32 rebalanceFreq, evictDuration, sleepDuration time.Duration @@ -158,14 +156,6 @@ func WithRedundantCopyCallback(cb RedundantCopyCallback) Option { } } -// WithMaxCapacity returns option to set max capacity -// that can be set to the pool. -func WithMaxCapacity(capacity int) Option { - return func(c *cfg) { - c.maxCapacity = capacity - } -} - // WithPool returns option to set pool for // policy and replication operations. func WithPool(p *ants.Pool) Option { diff --git a/pkg/services/policer/policer.go b/pkg/services/policer/policer.go index a68b194d4..363c0b922 100644 --- a/pkg/services/policer/policer.go +++ b/pkg/services/policer/policer.go @@ -66,7 +66,7 @@ func New(opts ...Option) *Policer { cfg: c, cache: cache, objsInWork: &objectsInWork{ - objs: make(map[oid.Address]struct{}, c.maxCapacity), + objs: make(map[oid.Address]struct{}, c.taskPool.Cap()), }, } } diff --git a/pkg/services/policer/policer_test.go b/pkg/services/policer/policer_test.go index c73d33629..41abeb384 100644 --- a/pkg/services/policer/policer_test.go +++ b/pkg/services/policer/policer_test.go @@ -239,6 +239,7 @@ func TestProcessObject(t *testing.T) { gotReplicateTo = append(gotReplicateTo, int(node.PublicKey()[0])) } })), + WithPool(testPool(t)), ) addrWithType := objectcore.AddressWithType{ @@ -276,6 +277,7 @@ func TestProcessObjectError(t *testing.T) { p := New( WithContainerSource(source), WithBuryFunc(buryFn), + WithPool(testPool(t)), ) addrWithType := objectcore.AddressWithType{ @@ -348,6 +350,12 @@ func TestIteratorContract(t *testing.T) { }, it.calls) } +func testPool(t *testing.T) *ants.Pool { + pool, err := ants.NewPool(4) + require.NoError(t, err) + return pool +} + type nextResult struct { objs []objectcore.AddressWithType err error