Compare commits

..

1 commit

Author SHA1 Message Date
cd53b9c883 [#185] Update SDK to support new tree/pool version
All checks were successful
/ DCO (pull_request) Successful in 2m16s
/ Vulncheck (pull_request) Successful in 7m32s
/ Builds (pull_request) Successful in 2m33s
/ Lint (pull_request) Successful in 10m30s
/ Tests (pull_request) Successful in 2m20s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
2024-12-20 11:43:51 +03:00
8 changed files with 41 additions and 41 deletions

View file

@ -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)

View file

@ -164,5 +164,5 @@ HTTP_GW_INDEX_PAGE_TEMPLATE_PATH=internal/handler/templates/index.gotmpl
# Enable using fallback path to search for a object by attribute
HTTP_GW_FEATURES_ENABLE_FILEPATH_FALLBACK=false
# Enable using new version of tree pool, which uses netmap to select nodes, for requests to tree service
# Enable using new version of tree pool, which uses net map to select nodes, for requests to tree service
HTTP_GW_FEATURES_TREE_POOL_NETMAP_SUPPORT=true

View file

@ -179,5 +179,5 @@ multinet:
features:
# Enable using fallback path to search for a object by attribute
enable_filepath_fallback: false
# Enable using new version of tree pool, which uses netmap to select nodes, for requests to tree service
# Enable using new version of tree pool, which uses net map to select nodes, for requests to tree service
tree_pool_netmap_support: true

View file

@ -473,4 +473,4 @@ features:
| Parameter | Type | SIGHUP reload | Default value | Description |
|-------------------------------------|--------|---------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `features.enable_filepath_fallback` | `bool` | yes | `false` | Enable using fallback path to search for a object by attribute. If the value of the `FilePath` attribute in the request contains no `/` symbols or single leading `/` symbol and the object was not found, then an attempt is made to search for the object by the attribute `FileName`. |
| `features.tree_pool_netmap_support` | `bool` | no | `false` | Enable using new version of tree pool, which uses netmap to select nodes, for requests to tree service. |
| `features.tree_pool_netmap_support` | `bool` | no | `false` | Enable using new version of tree pool, which uses net map to select nodes, for requests to tree service. |

View file

@ -11,41 +11,41 @@ import (
)
type (
// NetmapCache provides cache for netmap.
NetmapCache struct {
// NetMapCache provides cache for net map.
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 = "netmap"
DefaultNetMapCacheLifetime = 1 * time.Minute
netMapCacheSize = 1
netMapKey = "net_map"
)
// 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)
}

View file

@ -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 netmap"
CouldntCacheNetMap = "couldn't cache net map"
)

View file

@ -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) {
netmapSnapshot, err := x.pool.NetMapSnapshot(ctx)
func (x *FrostFS) NetMapSnapshot(ctx context.Context) (netmap.NetMap, error) {
netMap, err := x.pool.NetMapSnapshot(ctx)
if err != nil {
return netmapSnapshot, handleObjectError("get netmap via connection pool", err)
return netMap, handleObjectError("get net map via connection pool", err)
}
return netmapSnapshot, nil
return netMap, nil
}
// ResolverFrostFS represents virtual connection to the FrostFS network.

View file

@ -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
}
netmapSnapshot, err := s.frostFS.NetmapSnapshot(ctx)
netMap, err := s.frostFS.NetMapSnapshot(ctx)
if err != nil {
return netmap.NetMap{}, fmt.Errorf("get netmap: %w", err)
return netmap.NetMap{}, fmt.Errorf("get net map: %w", err)
}
if err = s.netmapCache.Put(netmapSnapshot); err != nil {
s.log.Warn(logs.CouldntCacheNetmap, zap.Error(err))
if err = s.netMapCache.Put(netMap); err != nil {
s.log.Warn(logs.CouldntCacheNetMap, zap.Error(err))
}
return netmapSnapshot, nil
return netMap, nil
}
func (s *Source) PlacementPolicy(ctx context.Context, cnrID cid.ID) (netmap.PlacementPolicy, error) {