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