[#1451] placement: Return copy of slice from container nodes cache
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 1m53s
DCO action / DCO (pull_request) Successful in 2m8s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m12s
Vulncheck / Vulncheck (pull_request) Successful in 3m6s
Build / Build Components (pull_request) Successful in 3m23s
Tests and linters / Staticcheck (pull_request) Successful in 3m17s
Tests and linters / Tests (pull_request) Successful in 3m21s
Tests and linters / gopls check (pull_request) Successful in 3m35s
Tests and linters / Lint (pull_request) Successful in 4m15s
Tests and linters / Tests with -race (pull_request) Successful in 6m31s
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 1m53s
DCO action / DCO (pull_request) Successful in 2m8s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m12s
Vulncheck / Vulncheck (pull_request) Successful in 3m6s
Build / Build Components (pull_request) Successful in 3m23s
Tests and linters / Staticcheck (pull_request) Successful in 3m17s
Tests and linters / Tests (pull_request) Successful in 3m21s
Tests and linters / gopls check (pull_request) Successful in 3m35s
Tests and linters / Lint (pull_request) Successful in 4m15s
Tests and linters / Tests with -race (pull_request) Successful in 6m31s
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
bec16a7e7c
commit
b4adf43557
1 changed files with 11 additions and 2 deletions
|
@ -3,6 +3,7 @@ package placement
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
|
@ -44,7 +45,7 @@ func (c *ContainerNodesCache) ContainerNodes(nm *netmapSDK.NetMap, cnr cid.ID, p
|
||||||
raw, ok := c.containerCache.Get(cnr)
|
raw, ok := c.containerCache.Get(cnr)
|
||||||
c.mtx.Unlock()
|
c.mtx.Unlock()
|
||||||
if ok {
|
if ok {
|
||||||
return raw, nil
|
return c.cloneResult(raw), nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.lastEpoch = nm.Epoch()
|
c.lastEpoch = nm.Epoch()
|
||||||
|
@ -65,5 +66,13 @@ func (c *ContainerNodesCache) ContainerNodes(nm *netmapSDK.NetMap, cnr cid.ID, p
|
||||||
c.containerCache.Add(cnr, cn)
|
c.containerCache.Add(cnr, cn)
|
||||||
}
|
}
|
||||||
c.mtx.Unlock()
|
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] = slices.Clone(nodes[repIdx])
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue