[#1451] placement: Return copy of slice from container nodes cache
Some checks failed
DCO action / DCO (pull_request) Successful in 1m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m28s
Tests and linters / Run gofumpt (pull_request) Successful in 2m37s
Vulncheck / Vulncheck (pull_request) Successful in 2m38s
Tests and linters / Staticcheck (pull_request) Failing after 2m44s
Tests and linters / Lint (pull_request) Failing after 2m50s
Build / Build Components (pull_request) Successful in 2m55s
Tests and linters / Tests with -race (pull_request) Failing after 2m58s
Tests and linters / Tests (pull_request) Failing after 3m11s
Tests and linters / gopls check (pull_request) Successful in 3m29s
Some checks failed
DCO action / DCO (pull_request) Successful in 1m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m28s
Tests and linters / Run gofumpt (pull_request) Successful in 2m37s
Vulncheck / Vulncheck (pull_request) Successful in 2m38s
Tests and linters / Staticcheck (pull_request) Failing after 2m44s
Tests and linters / Lint (pull_request) Failing after 2m50s
Build / Build Components (pull_request) Successful in 2m55s
Tests and linters / Tests with -race (pull_request) Failing after 2m58s
Tests and linters / Tests (pull_request) Failing after 3m11s
Tests and linters / gopls check (pull_request) Successful in 3m29s
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
5bd3b663a9
commit
5c5dfaaf35
1 changed files with 12 additions and 1 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()
|
||||
|
@ -67,3 +67,14 @@ func (c *ContainerNodesCache) ContainerNodes(nm *netmapSDK.NetMap, cnr cid.ID, p
|
|||
c.mtx.Unlock()
|
||||
return 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, len(nodes[repIdx]))
|
||||
for nodeIdx := range nodes[repIdx] {
|
||||
result[repIdx] = append(result[repIdx], nodes[repIdx][nodeIdx])
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue