From d24cbb0b1df7c8e94a9ece8c788b77b21a6e7ea5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 20 Jan 2025 16:09:35 +0300 Subject: [PATCH] policer: Do not mutate slice under iteration Nothing wrong with it, besides being difficult to read. Signed-off-by: Evgenii Stratonikov --- pkg/services/policer/check.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index dbd2e64de..537d2e4ee 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -110,6 +110,7 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe // Number of copies that are stored on maintenance nodes. var uncheckedCopies int + var candidates []netmap.NodeInfo for i := 0; shortage > 0 && i < len(nodes); i++ { select { case <-ctx.Done(): @@ -126,8 +127,8 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe if st == nodeDoesNotHoldObject { // 1. The node does not hold object (`st == nodeDoesNotHoldObject`). // 2. This is the first time the node is encountered (`!cached``). - // So we leave the node in the list and skip its removal - // at the end of the loop body. + // So we need to try to put an object to it. + candidates = append(candidates, nodes[i]) continue } } @@ -153,12 +154,9 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe default: panic("unreachable") } - - nodes = append(nodes[:i], nodes[i+1:]...) - i-- } - p.handleProcessNodesResult(ctx, addr, requirements, nodes, checkedNodes, shortage, uncheckedCopies) + p.handleProcessNodesResult(ctx, addr, requirements, candidates, checkedNodes, shortage, uncheckedCopies) } func (p *Policer) checkStatus(ctx context.Context, addr oid.Address, node netmap.NodeInfo) (nodeProcessStatus, error) {