forked from TrueCloudLab/frostfs-node
[#1248] placement: Use cid.ID as key in the cache
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
d5dc14c639
commit
21431f22c0
1 changed files with 5 additions and 5 deletions
|
@ -19,7 +19,7 @@ type netMapBuilder struct {
|
||||||
lastNm *netmapSDK.NetMap
|
lastNm *netmapSDK.NetMap
|
||||||
// containerCache caches container nodes by ID. It is used to skip `GetContainerNodes` invocation if
|
// containerCache caches container nodes by ID. It is used to skip `GetContainerNodes` invocation if
|
||||||
// neither netmap nor container has changed.
|
// neither netmap nor container has changed.
|
||||||
containerCache simplelru.LRUCache[string, [][]netmapSDK.NodeInfo]
|
containerCache simplelru.LRUCache[cid.ID, [][]netmapSDK.NodeInfo]
|
||||||
}
|
}
|
||||||
|
|
||||||
type netMapSrc struct {
|
type netMapSrc struct {
|
||||||
|
@ -32,7 +32,7 @@ type netMapSrc struct {
|
||||||
const defaultContainerCacheSize = 10
|
const defaultContainerCacheSize = 10
|
||||||
|
|
||||||
func NewNetworkMapBuilder(nm *netmapSDK.NetMap) Builder {
|
func NewNetworkMapBuilder(nm *netmapSDK.NetMap) Builder {
|
||||||
cache, _ := simplelru.NewLRU[string, [][]netmapSDK.NodeInfo](defaultContainerCacheSize, nil) // no error
|
cache, _ := simplelru.NewLRU[cid.ID, [][]netmapSDK.NodeInfo](defaultContainerCacheSize, nil) // no error
|
||||||
return &netMapBuilder{
|
return &netMapBuilder{
|
||||||
nmSrc: &netMapSrc{nm: nm},
|
nmSrc: &netMapSrc{nm: nm},
|
||||||
containerCache: cache,
|
containerCache: cache,
|
||||||
|
@ -40,7 +40,7 @@ func NewNetworkMapBuilder(nm *netmapSDK.NetMap) Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNetworkMapSourceBuilder(nmSrc netmap.Source) Builder {
|
func NewNetworkMapSourceBuilder(nmSrc netmap.Source) Builder {
|
||||||
cache, _ := simplelru.NewLRU[string, [][]netmapSDK.NodeInfo](defaultContainerCacheSize, nil) // no error
|
cache, _ := simplelru.NewLRU[cid.ID, [][]netmapSDK.NodeInfo](defaultContainerCacheSize, nil) // no error
|
||||||
return &netMapBuilder{
|
return &netMapBuilder{
|
||||||
nmSrc: nmSrc,
|
nmSrc: nmSrc,
|
||||||
containerCache: cache,
|
containerCache: cache,
|
||||||
|
@ -62,7 +62,7 @@ func (b *netMapBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, p netmapSDK.Plac
|
||||||
|
|
||||||
b.mtx.Lock()
|
b.mtx.Lock()
|
||||||
if nm == b.lastNm {
|
if nm == b.lastNm {
|
||||||
raw, ok := b.containerCache.Get(string(binCnr))
|
raw, ok := b.containerCache.Get(cnr)
|
||||||
b.mtx.Unlock()
|
b.mtx.Unlock()
|
||||||
if ok {
|
if ok {
|
||||||
return BuildObjectPlacement(nm, raw, obj)
|
return BuildObjectPlacement(nm, raw, obj)
|
||||||
|
@ -78,7 +78,7 @@ func (b *netMapBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, p netmapSDK.Plac
|
||||||
}
|
}
|
||||||
|
|
||||||
b.mtx.Lock()
|
b.mtx.Lock()
|
||||||
b.containerCache.Add(string(binCnr), cn)
|
b.containerCache.Add(cnr, cn)
|
||||||
b.mtx.Unlock()
|
b.mtx.Unlock()
|
||||||
|
|
||||||
return BuildObjectPlacement(nm, cn, obj)
|
return BuildObjectPlacement(nm, cn, obj)
|
||||||
|
|
Loading…
Reference in a new issue