From d15a7d8d3d35886faccec1f107eb33e11826b879 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 11 Aug 2022 18:48:16 +0400 Subject: [PATCH] [#1632] node/container: Update GET cache on successful removal In previous implementation storage node responded with the removed container up until cache invalidation due to TTL. In order to avoid false-positive responses node should update its cache on `DeleteSuccess` events. Make node to call `handleRemoval` method of the container cache which leads to subsequent `apistatus.ErrContainerNotFound` errors. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/cache.go | 5 +++++ cmd/neofs-node/container.go | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-node/cache.go b/cmd/neofs-node/cache.go index 9061744a9..3ac4e9f40 100644 --- a/cmd/neofs-node/cache.go +++ b/cmd/neofs-node/cache.go @@ -10,6 +10,7 @@ import ( cntClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/user" @@ -147,6 +148,10 @@ func newCachedContainerStorage(v container.Source) *ttlContainerStorage { return (*ttlContainerStorage)(lruCnrCache) } +func (s *ttlContainerStorage) handleRemoval(cnr cid.ID) { + (*ttlNetCache)(s).set(cnr.EncodeToString(), nil, apistatus.ContainerNotFound{}) +} + // Get returns container value from the cache. If value is missing in the cache // or expired, then it returns value from side chain and updates the cache. func (s *ttlContainerStorage) Get(cnr cid.ID) (*container.Container, error) { diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 454fb8ed8..b64629780 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -69,12 +69,6 @@ func initContainerService(c *cfg) { ) }) - subscribeToContainerRemoval(c, func(e event.Event) { - c.log.Debug("container removal event's receipt", - zap.Stringer("id", e.(containerEvent.DeleteSuccess).ID), - ) - }) - if c.cfgMorph.disableCache { c.cfgObject.eaclSource = eACLFetcher cnrRdr.eacl = eACLFetcher @@ -87,6 +81,16 @@ func initContainerService(c *cfg) { cachedEACLStorage := newCachedEACLStorage(eACLFetcher) cachedContainerLister := newCachedContainerLister(wrap) + subscribeToContainerRemoval(c, func(e event.Event) { + ev := e.(containerEvent.DeleteSuccess) + + cachedContainerStorage.handleRemoval(ev.ID) + + c.log.Debug("container removal event's receipt", + zap.Stringer("id", ev.ID), + ) + }) + c.cfgObject.eaclSource = cachedEACLStorage c.cfgObject.cnrSource = cachedContainerStorage