[#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 <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2020-10-21 14:50:48 +03:00 committed by Alex Vanin
parent 2d46baa4a5
commit f66c7958e7
2 changed files with 17 additions and 1 deletions

View File

@ -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),
)
}
}

View File

@ -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
}
}