From f66c7958e78812d80e3c223863fa79dc191a5487 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 21 Oct 2020 14:50:48 +0300 Subject: [PATCH] [#109] services/policer: Assign tasks to Replicator Make Policer to call AddTask method of Replicator when an insufficient number of copies of an object is detected in the container. Signed-off-by: Leonard Lyubich --- pkg/services/policer/check.go | 8 +++++++- pkg/services/policer/policer.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index 85f2a6c41..0d3fceea6 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/network" headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head" + "github.com/nspcc-dev/neofs-node/pkg/services/replicator" "go.uber.org/zap" ) @@ -98,6 +99,11 @@ func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes p.log.Info("shortage of object copies detected", zap.Uint32("shortage", shortage), ) - // TODO: send task to replicator + + p.replicator.AddTask(new(replicator.Task). + WithObjectAddress(addr). + WithNodes(nodes). + WithCopiesNumber(shortage), + ) } } diff --git a/pkg/services/policer/policer.go b/pkg/services/policer/policer.go index 8a0d5e57d..fdc594c85 100644 --- a/pkg/services/policer/policer.go +++ b/pkg/services/policer/policer.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/network" headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" + "github.com/nspcc-dev/neofs-node/pkg/services/replicator" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" ) @@ -42,6 +43,8 @@ type cfg struct { remoteHeader *headsvc.RemoteHeader localAddrSrc network.LocalAddressSource + + replicator *replicator.Replicator } func defaultCfg() *cfg { @@ -138,3 +141,10 @@ func WithLocalAddressSource(v network.LocalAddressSource) Option { c.localAddrSrc = v } } + +// WithReplicator returns option to set object replicator of Policer. +func WithReplicator(v *replicator.Replicator) Option { + return func(c *cfg) { + c.replicator = v + } +}