[#1451] placement: Return copy of slice from container nodes cache
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 1m21s
DCO action / DCO (pull_request) Successful in 1m32s
Vulncheck / Vulncheck (pull_request) Successful in 2m6s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m16s
Build / Build Components (pull_request) Successful in 2m35s
Tests and linters / Staticcheck (pull_request) Failing after 2m30s
Tests and linters / Lint (pull_request) Failing after 2m36s
Tests and linters / gopls check (pull_request) Successful in 3m12s
Tests and linters / Tests (pull_request) Successful in 5m36s
Tests and linters / Tests with -race (pull_request) Successful in 5m36s
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 1m21s
DCO action / DCO (pull_request) Successful in 1m32s
Vulncheck / Vulncheck (pull_request) Successful in 2m6s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m16s
Build / Build Components (pull_request) Successful in 2m35s
Tests and linters / Staticcheck (pull_request) Failing after 2m30s
Tests and linters / Lint (pull_request) Failing after 2m36s
Tests and linters / gopls check (pull_request) Successful in 3m12s
Tests and linters / Tests (pull_request) Successful in 5m36s
Tests and linters / Tests with -race (pull_request) Successful in 5m36s
Nodes from cache could be changed by traverser, if no objectID specified. So it is required to return copy of cache's slice. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
b013cda142
commit
94c2b36ae0
1 changed files with 13 additions and 2 deletions
|
@ -44,7 +44,7 @@ func (c *ContainerNodesCache) ContainerNodes(nm *netmapSDK.NetMap, cnr cid.ID, p
|
|||
raw, ok := c.containerCache.Get(cnr)
|
||||
c.mtx.Unlock()
|
||||
if ok {
|
||||
return raw, nil
|
||||
return c.cloneResult(raw), nil
|
||||
}
|
||||
} else {
|
||||
c.lastEpoch = nm.Epoch()
|
||||
|
@ -65,5 +65,16 @@ func (c *ContainerNodesCache) ContainerNodes(nm *netmapSDK.NetMap, cnr cid.ID, p
|
|||
c.containerCache.Add(cnr, cn)
|
||||
}
|
||||
c.mtx.Unlock()
|
||||
return cn, nil
|
||||
return c.cloneResult(cn), nil
|
||||
}
|
||||
|
||||
func (c *ContainerNodesCache) cloneResult(nodes [][]netmapSDK.NodeInfo) [][]netmapSDK.NodeInfo {
|
||||
result := make([][]netmapSDK.NodeInfo, len(nodes))
|
||||
for repIdx := range nodes {
|
||||
result[repIdx] = make([]netmapSDK.NodeInfo, 0, len(nodes[repIdx]))
|
||||
for nodeIdx := range nodes[repIdx] {
|
||||
result[repIdx] = append(result[repIdx], nodes[repIdx][nodeIdx])
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue