forked from TrueCloudLab/frostfs-node
[#217] policer: Handler redundant local copy of the object
Detect redundant local copy of the object in Object Policer. Add redundant copy callback (`WithRedundantCopyCallback` option). Pass address of the redundant copy to callback. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
35073fb61b
commit
277e3ca20a
2 changed files with 27 additions and 3 deletions
|
@ -48,8 +48,9 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) {
|
|||
|
||||
func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes netmap.Nodes, shortage uint32) {
|
||||
prm := new(headsvc.RemoteHeadPrm).WithObjectAddress(addr)
|
||||
redundantLocalCopy := false
|
||||
|
||||
for i := 0; shortage > 0 && i < len(nodes); i++ {
|
||||
for i := 0; i < len(nodes); i++ {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
@ -68,8 +69,13 @@ func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes
|
|||
}
|
||||
|
||||
if network.IsLocalAddress(p.localAddrSrc, node) {
|
||||
shortage--
|
||||
if shortage == 0 {
|
||||
redundantLocalCopy = true
|
||||
break
|
||||
} else {
|
||||
shortage--
|
||||
}
|
||||
} else if shortage > 0 {
|
||||
callCtx, cancel := context.WithTimeout(ctx, p.headTimeout)
|
||||
|
||||
_, err = p.remoteHeader.Head(callCtx, prm.WithNodeAddress(node))
|
||||
|
@ -107,5 +113,7 @@ func (p *Policer) processNodes(ctx context.Context, addr *object.Address, nodes
|
|||
WithNodes(nodes).
|
||||
WithCopiesNumber(shortage),
|
||||
)
|
||||
} else if redundantLocalCopy {
|
||||
p.cbRedundantCopy(addr)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
|
@ -25,6 +26,10 @@ type Policer struct {
|
|||
// Option is an option for Policer constructor.
|
||||
type Option func(*cfg)
|
||||
|
||||
// RedundantCopyCallback is a callback to pass
|
||||
// the redundant local copy of the object.
|
||||
type RedundantCopyCallback func(*object.Address)
|
||||
|
||||
type cfg struct {
|
||||
headTimeout time.Duration
|
||||
|
||||
|
@ -45,6 +50,8 @@ type cfg struct {
|
|||
localAddrSrc network.LocalAddressSource
|
||||
|
||||
replicator *replicator.Replicator
|
||||
|
||||
cbRedundantCopy RedundantCopyCallback
|
||||
}
|
||||
|
||||
func defaultCfg() *cfg {
|
||||
|
@ -148,3 +155,12 @@ func WithReplicator(v *replicator.Replicator) Option {
|
|||
c.replicator = v
|
||||
}
|
||||
}
|
||||
|
||||
// WithRedundantCopyCallback returns option to set
|
||||
// callback to pass redundant local object copies
|
||||
// detected by Policer.
|
||||
func WithRedundantCopyCallback(cb RedundantCopyCallback) Option {
|
||||
return func(c *cfg) {
|
||||
c.cbRedundantCopy = cb
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue