[#1605] policer: Do not mutate slice under iteration
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 27s
DCO action / DCO (pull_request) Successful in 36s
Vulncheck / Vulncheck (pull_request) Successful in 1m6s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m23s
Build / Build Components (pull_request) Successful in 1m38s
Tests and linters / Staticcheck (pull_request) Successful in 1m56s
Tests and linters / Lint (pull_request) Successful in 2m44s
Tests and linters / Tests (pull_request) Successful in 2m57s
Tests and linters / gopls check (pull_request) Successful in 4m12s
Tests and linters / Tests with -race (pull_request) Successful in 4m23s

Nothing wrong with it, besides being difficult to read.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2025-01-20 16:09:35 +03:00
parent 91c8a1a1fc
commit 3d953d7185
Signed by: fyrchik
SSH key fingerprint: SHA256:m/TTwCzjnRkXgnzEx9X92ccxy1CcVeinOgDb3NPWWmg

View file

@ -110,6 +110,7 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe
// Number of copies that are stored on maintenance nodes. // Number of copies that are stored on maintenance nodes.
var uncheckedCopies int var uncheckedCopies int
var candidates []netmap.NodeInfo
for i := 0; shortage > 0 && i < len(nodes); i++ { for i := 0; shortage > 0 && i < len(nodes); i++ {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -125,8 +126,8 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe
if st == nodeDoesNotHoldObject { if st == nodeDoesNotHoldObject {
// 1. This is the first time the node is encountered (`!st.Processed()`). // 1. This is the first time the node is encountered (`!st.Processed()`).
// 2. The node does not hold object (`st == nodeDoesNotHoldObject`). // 2. The node does not hold object (`st == nodeDoesNotHoldObject`).
// So we leave the node in the list and skip its removal // So we need to try to put an object to it.
// at the end of the loop body. candidates = append(candidates, nodes[i])
continue continue
} }
} }
@ -152,12 +153,9 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe
default: default:
panic("unreachable") 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) { func (p *Policer) checkStatus(ctx context.Context, addr oid.Address, node netmap.NodeInfo) (nodeProcessStatus, error) {