From 072a7d61ab11b23e1dea755876a80987771a561b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 27 Dec 2022 11:20:54 +0300 Subject: [PATCH] [#2176] neofs-node: Do not cache full container list We rarely need to list all containers: as one example we need it for tree service synchronization once per epoch. Given that cache TTL has the order of block time it makes no sense to cache the list of all containers. Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 3 ++- cmd/frostfs-node/cache.go | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01692e4d0..2967f8b87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,7 +58,8 @@ Changelog for FrostFS Node - Use `sync.Pool` in Object.PUT service (#2139) - Shard uses metabase for `HEAD` requests by default, not write-cache (#2167) - Clarify help for `--expire-at` parameter for commands `object lock/put` and `bearer create` (#2097) -- Node spawns `GETRANGE` requests signed with the node's key if session key was not found for `RANGEHASH` (#2144) +- Node spawns `GETRANGE` requests signed with the node's key if session key was not found for `RANGEHASH` (#2144) +- Full list of container is no longer cached (#2176) ### Fixed - Open FSTree in sync mode by default (#1992) diff --git a/cmd/frostfs-node/cache.go b/cmd/frostfs-node/cache.go index b0deca1c2..ea11cbec5 100644 --- a/cmd/frostfs-node/cache.go +++ b/cmd/frostfs-node/cache.go @@ -215,7 +215,8 @@ func (s *lruNetmapSource) Epoch() (uint64, error) { // wrapper over TTL cache of values read from the network // that implements container lister. type ttlContainerLister struct { - *ttlNetCache[string, *cacheItemContainerList] + inner *ttlNetCache[string, *cacheItemContainerList] + client *cntClient.Client } // value type for ttlNetCache used by ttlContainerLister. @@ -251,20 +252,18 @@ func newCachedContainerLister(c *cntClient.Client, ttl time.Duration) ttlContain }, nil }) - return ttlContainerLister{lruCnrListerCache} + return ttlContainerLister{inner: lruCnrListerCache, client: c} } // List returns list of container IDs from the cache. If list is missing in the // cache or expired, then it returns container IDs from side chain and updates // the cache. func (s ttlContainerLister) List(id *user.ID) ([]cid.ID, error) { - var str string - - if id != nil { - str = id.EncodeToString() + if id == nil { + return s.client.List(nil) } - item, err := s.get(str) + item, err := s.inner.get(id.EncodeToString()) if err != nil { return nil, err } @@ -287,14 +286,14 @@ func (s ttlContainerLister) List(id *user.ID) ([]cid.ID, error) { func (s *ttlContainerLister) update(owner user.ID, cnr cid.ID, add bool) { strOwner := owner.EncodeToString() - val, ok := s.cache.Peek(strOwner) + val, ok := s.inner.cache.Peek(strOwner) if !ok { // we could cache the single cnr but in this case we will disperse // with the Sidechain a lot return } - if s.ttl <= time.Since(val.t) { + if s.inner.ttl <= time.Since(val.t) { return }