[#210] policier: Refactor object placement

Resolve containedctx and contextcheck linters.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-04-04 14:57:44 +03:00
parent 23575e1ac0
commit 080be5cfcd

View file

@ -105,9 +105,7 @@ func (p *Policer) processObject(ctx context.Context, addrWithType objectcore.Add
return
}
c := &processPlacementContext{
Context: ctx,
}
c := &placementRequirements{}
var numOfContainerNodes int
for i := range nn {
@ -124,8 +122,7 @@ func (p *Policer) processObject(ctx context.Context, addrWithType objectcore.Add
default:
}
//nolint: contextcheck
p.processNodes(c, addrWithType, nn[i], policy.ReplicaNumberByIndex(i), checkedNodes)
p.processNodes(ctx, c, addrWithType, nn[i], policy.ReplicaNumberByIndex(i), checkedNodes)
}
if !c.needLocalCopy && c.removeLocalCopy {
@ -137,10 +134,7 @@ func (p *Policer) processObject(ctx context.Context, addrWithType objectcore.Add
}
}
// nolint: containedctx
type processPlacementContext struct {
context.Context
type placementRequirements struct {
// 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
@ -149,7 +143,7 @@ type processPlacementContext struct {
}
// nolint: funlen
func (p *Policer) processNodes(ctx *processPlacementContext, addrWithType objectcore.AddressWithType,
func (p *Policer) processNodes(ctx context.Context, requirements *placementRequirements, addrWithType objectcore.AddressWithType,
nodes []netmap.NodeInfo, shortage uint32, checkedNodes *nodeCache) {
addr := addrWithType.Address
typ := addrWithType.Type
@ -189,7 +183,7 @@ func (p *Policer) processNodes(ctx *processPlacementContext, addrWithType object
}
if p.netmapKeys.IsLocalKey(nodes[i].PublicKey()) {
ctx.needLocalCopy = true
requirements.needLocalCopy = true
shortage--
} else if nodes[i].IsMaintenance() {
@ -253,7 +247,7 @@ func (p *Policer) processNodes(ctx *processPlacementContext, addrWithType object
zap.Int("count", uncheckedCopies))
} else if uncheckedCopies == 0 {
// Safe to remove: checked all copies, shortage == 0.
ctx.removeLocalCopy = true
requirements.removeLocalCopy = true
}
}