forked from TrueCloudLab/frostfs-node
[#5] services/object_manager: Use generic LRU cache
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
1b3374ac7f
commit
f0be0befc5
3 changed files with 10 additions and 11 deletions
|
@ -9,7 +9,7 @@ import (
|
||||||
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
netmapSDK "github.com/TrueCloudLab/frostfs-sdk-go/netmap"
|
netmapSDK "github.com/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
"github.com/hashicorp/golang-lru/simplelru"
|
"github.com/hashicorp/golang-lru/v2/simplelru"
|
||||||
)
|
)
|
||||||
|
|
||||||
type netMapBuilder struct {
|
type netMapBuilder struct {
|
||||||
|
@ -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
|
containerCache simplelru.LRUCache[string, [][]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(defaultContainerCacheSize, nil) // no error
|
cache, _ := simplelru.NewLRU[string, [][]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(defaultContainerCacheSize, nil) // no error
|
cache, _ := simplelru.NewLRU[string, [][]netmapSDK.NodeInfo](defaultContainerCacheSize, nil) // no error
|
||||||
return &netMapBuilder{
|
return &netMapBuilder{
|
||||||
nmSrc: nmSrc,
|
nmSrc: nmSrc,
|
||||||
containerCache: cache,
|
containerCache: cache,
|
||||||
|
@ -65,8 +65,7 @@ func (b *netMapBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, p netmapSDK.Plac
|
||||||
raw, ok := b.containerCache.Get(string(binCnr))
|
raw, ok := b.containerCache.Get(string(binCnr))
|
||||||
b.mtx.Unlock()
|
b.mtx.Unlock()
|
||||||
if ok {
|
if ok {
|
||||||
cn := raw.([][]netmapSDK.NodeInfo)
|
return BuildObjectPlacement(nm, raw, obj)
|
||||||
return BuildObjectPlacement(nm, cn, obj)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
b.containerCache.Purge()
|
b.containerCache.Purge()
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ type Source interface {
|
||||||
// `ExpirationChecker{}` declarations leads to undefined behaviour
|
// `ExpirationChecker{}` declarations leads to undefined behaviour
|
||||||
// and may lead to panics.
|
// and may lead to panics.
|
||||||
type ExpirationChecker struct {
|
type ExpirationChecker struct {
|
||||||
cache *lru.Cache
|
cache *lru.Cache[string, uint64]
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func (g *ExpirationChecker) IsTombstoneAvailable(ctx context.Context, a oid.Addr
|
||||||
|
|
||||||
expEpoch, ok := g.cache.Get(addrStr)
|
expEpoch, ok := g.cache.Get(addrStr)
|
||||||
if ok {
|
if ok {
|
||||||
return expEpoch.(uint64) > epoch
|
return expEpoch > epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
ts, err := g.tsSource.Tombstone(ctx, a, epoch)
|
ts, err := g.tsSource.Tombstone(ctx, a, epoch)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ func NewChecker(oo ...Option) *ExpirationChecker {
|
||||||
|
|
||||||
panicOnNil(cfg.tsSource, "Tombstone source")
|
panicOnNil(cfg.tsSource, "Tombstone source")
|
||||||
|
|
||||||
cache, err := lru.New(cfg.cacheSize)
|
cache, err := lru.New[string, uint64](cfg.cacheSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("could not create LRU cache with %d size: %w", cfg.cacheSize, err))
|
panic(fmt.Errorf("could not create LRU cache with %d size: %w", cfg.cacheSize, err))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue