From 6226c3ba86509d23213005b8e87dd88da6aaa623 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 6 Mar 2023 16:47:35 +0300 Subject: [PATCH] [#129] policer: Use safer defaults If `processNodes` exits earlier for some reason, `needLocalCopy` could be false. See https://github.com/nspcc-dev/neofs-node/issues/2267 Signed-off-by: Evgenii Stratonikov --- pkg/services/policer/check.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index 312dc59b..1da07f45 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -127,7 +127,7 @@ func (p *Policer) processObject(ctx context.Context, addrWithType objectcore.Add p.processNodes(c, addrWithType, nn[i], policy.ReplicaNumberByIndex(i), checkedNodes) } - if !c.needLocalCopy { + if !c.needLocalCopy && c.removeLocalCopy { p.log.Info("redundant local object copy detected", zap.Stringer("object", addr), ) @@ -139,7 +139,11 @@ func (p *Policer) processObject(ctx context.Context, addrWithType objectcore.Add type processPlacementContext struct { context.Context + // needLocalCopy is true if the current node must store an object according to the storage policy. needLocalCopy bool + // removeLocalCopy is true if all copies are stored according to the storage policy + // and the current node doesn't need to store an object. + removeLocalCopy bool } func (p *Policer) processNodes(ctx *processPlacementContext, addrWithType objectcore.AddressWithType, @@ -242,9 +246,11 @@ func (p *Policer) processNodes(ctx *processPlacementContext, addrWithType object } else if uncheckedCopies > 0 { // If we have more copies than needed, but some of them are from the maintenance nodes, // save the local copy. - ctx.needLocalCopy = true p.log.Debug("some of the copies are stored on nodes under maintenance, save local copy", zap.Int("count", uncheckedCopies)) + } else if uncheckedCopies == 0 { + // Safe to remove: checked all copies, shortage == 0. + ctx.removeLocalCopy = true } }