Compare commits
1 commit
cd53b9c883
...
4474f052de
Author | SHA1 | Date | |
---|---|---|---|
4474f052de |
8 changed files with 41 additions and 41 deletions
|
@ -687,7 +687,7 @@ func (a *app) initPools(ctx context.Context) {
|
|||
}
|
||||
|
||||
if a.cfg.GetBool(cfgFeaturesTreePoolNetmapSupport) {
|
||||
prmTree.SetNetMapInfoSource(frostfs.NewSource(frostfs.NewFrostFS(p), cache.NewNetMapCache(getNetMapCacheOptions(a.cfg, a.log)), a.bucketCache, a.log))
|
||||
prmTree.SetNetMapInfoSource(frostfs.NewSource(frostfs.NewFrostFS(p), cache.NewNetmapCache(getNetmapCacheOptions(a.cfg, a.log)), a.bucketCache, a.log))
|
||||
}
|
||||
|
||||
treePool, err := treepool.NewPool(prmTree)
|
||||
|
@ -750,8 +750,8 @@ func getBucketCacheOptions(v *viper.Viper, l *zap.Logger) *cache.Config {
|
|||
return cacheCfg
|
||||
}
|
||||
|
||||
func getNetMapCacheOptions(v *viper.Viper, l *zap.Logger) *cache.NetMapCacheConfig {
|
||||
cacheCfg := cache.DefaultNetMapConfig(l)
|
||||
func getNetmapCacheOptions(v *viper.Viper, l *zap.Logger) *cache.NetmapCacheConfig {
|
||||
cacheCfg := cache.DefaultNetmapConfig(l)
|
||||
|
||||
cacheCfg.Lifetime = fetchCacheLifetime(v, l, cfgNetmapCacheLifetime, cacheCfg.Lifetime)
|
||||
|
||||
|
|
38
internal/cache/netmap.go
vendored
38
internal/cache/netmap.go
vendored
|
@ -11,41 +11,41 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
// NetMapCache provides cache for net map.
|
||||
NetMapCache struct {
|
||||
// NetmapCache provides cache for netmap.
|
||||
NetmapCache struct {
|
||||
cache gcache.Cache
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NetMapCacheConfig stores expiration params for cache.
|
||||
NetMapCacheConfig struct {
|
||||
// NetmapCacheConfig stores expiration params for cache.
|
||||
NetmapCacheConfig struct {
|
||||
Lifetime time.Duration
|
||||
Logger *zap.Logger
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultNetMapCacheLifetime = 1 * time.Minute
|
||||
netMapCacheSize = 1
|
||||
netMapKey = "net_map"
|
||||
DefaultNetmapCacheLifetime = 1 * time.Minute
|
||||
netmapCacheSize = 1
|
||||
netmapKey = "netmap"
|
||||
)
|
||||
|
||||
// DefaultNetMapConfig returns new default cache expiration values.
|
||||
func DefaultNetMapConfig(logger *zap.Logger) *NetMapCacheConfig {
|
||||
return &NetMapCacheConfig{
|
||||
Lifetime: DefaultNetMapCacheLifetime,
|
||||
// DefaultNetmapConfig returns new default cache expiration values.
|
||||
func DefaultNetmapConfig(logger *zap.Logger) *NetmapCacheConfig {
|
||||
return &NetmapCacheConfig{
|
||||
Lifetime: DefaultNetmapCacheLifetime,
|
||||
Logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// NewNetMapCache creates an object of NetMapCache.
|
||||
func NewNetMapCache(config *NetMapCacheConfig) *NetMapCache {
|
||||
gc := gcache.New(netMapCacheSize).LRU().Expiration(config.Lifetime).Build()
|
||||
return &NetMapCache{cache: gc, logger: config.Logger}
|
||||
// NewNetmapCache creates an object of NetmapCache.
|
||||
func NewNetmapCache(config *NetmapCacheConfig) *NetmapCache {
|
||||
gc := gcache.New(netmapCacheSize).LRU().Expiration(config.Lifetime).Build()
|
||||
return &NetmapCache{cache: gc, logger: config.Logger}
|
||||
}
|
||||
|
||||
func (c *NetMapCache) Get() *netmap.NetMap {
|
||||
entry, err := c.cache.Get(netMapKey)
|
||||
func (c *NetmapCache) Get() *netmap.NetMap {
|
||||
entry, err := c.cache.Get(netmapKey)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -60,6 +60,6 @@ func (c *NetMapCache) Get() *netmap.NetMap {
|
|||
return &result
|
||||
}
|
||||
|
||||
func (c *NetMapCache) Put(nm netmap.NetMap) error {
|
||||
return c.cache.Set(netMapKey, nm)
|
||||
func (c *NetmapCache) Put(nm netmap.NetMap) error {
|
||||
return c.cache.Set(netmapKey, nm)
|
||||
}
|
||||
|
|
|
@ -93,5 +93,5 @@ const (
|
|||
FailedToLoadMultinetConfig = "failed to load multinet config"
|
||||
MultinetConfigWontBeUpdated = "multinet config won't be updated"
|
||||
ObjectNotFoundByFilePathTrySearchByFileName = "object not found by filePath attribute, try search by fileName"
|
||||
CouldntCacheNetMap = "couldn't cache net map"
|
||||
CouldntCacheNetmap = "couldn't cache netmap"
|
||||
)
|
||||
|
|
|
@ -174,13 +174,13 @@ func (x *FrostFS) GetEpochDurations(ctx context.Context) (*utils.EpochDurations,
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func (x *FrostFS) NetMapSnapshot(ctx context.Context) (netmap.NetMap, error) {
|
||||
netMap, err := x.pool.NetMapSnapshot(ctx)
|
||||
func (x *FrostFS) NetmapSnapshot(ctx context.Context) (netmap.NetMap, error) {
|
||||
netmapSnapshot, err := x.pool.NetMapSnapshot(ctx)
|
||||
if err != nil {
|
||||
return netMap, handleObjectError("get net map via connection pool", err)
|
||||
return netmapSnapshot, handleObjectError("get netmap via connection pool", err)
|
||||
}
|
||||
|
||||
return netMap, nil
|
||||
return netmapSnapshot, nil
|
||||
}
|
||||
|
||||
// ResolverFrostFS represents virtual connection to the FrostFS network.
|
||||
|
|
|
@ -14,36 +14,36 @@ import (
|
|||
|
||||
type Source struct {
|
||||
frostFS *FrostFS
|
||||
netMapCache *cache.NetMapCache
|
||||
netmapCache *cache.NetmapCache
|
||||
bucketCache *cache.BucketCache
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
func NewSource(frostFS *FrostFS, netMapCache *cache.NetMapCache, bucketCache *cache.BucketCache, log *zap.Logger) *Source {
|
||||
func NewSource(frostFS *FrostFS, netmapCache *cache.NetmapCache, bucketCache *cache.BucketCache, log *zap.Logger) *Source {
|
||||
return &Source{
|
||||
frostFS: frostFS,
|
||||
netMapCache: netMapCache,
|
||||
netmapCache: netmapCache,
|
||||
bucketCache: bucketCache,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Source) NetMapSnapshot(ctx context.Context) (netmap.NetMap, error) {
|
||||
cachedNetMap := s.netMapCache.Get()
|
||||
if cachedNetMap != nil {
|
||||
return *cachedNetMap, nil
|
||||
cachedNetmap := s.netmapCache.Get()
|
||||
if cachedNetmap != nil {
|
||||
return *cachedNetmap, nil
|
||||
}
|
||||
|
||||
netMap, err := s.frostFS.NetMapSnapshot(ctx)
|
||||
netmapSnapshot, err := s.frostFS.NetmapSnapshot(ctx)
|
||||
if err != nil {
|
||||
return netmap.NetMap{}, fmt.Errorf("get netmap: %w", err)
|
||||
}
|
||||
|
||||
if err = s.netMapCache.Put(netMap); err != nil {
|
||||
s.log.Warn(logs.CouldntCacheNetMap, zap.Error(err))
|
||||
if err = s.netmapCache.Put(netmapSnapshot); err != nil {
|
||||
s.log.Warn(logs.CouldntCacheNetmap, zap.Error(err))
|
||||
}
|
||||
|
||||
return netMap, nil
|
||||
return netmapSnapshot, nil
|
||||
}
|
||||
|
||||
func (s *Source) PlacementPolicy(ctx context.Context, cnrID cid.ID) (netmap.PlacementPolicy, error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue