[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-08-11 18:48:16 +04:00 committed by LeL
parent a529149e6f
commit d15a7d8d3d
2 changed files with 15 additions and 6 deletions

View file

@ -10,6 +10,7 @@ import (
cntClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" cntClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl" "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl"
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" 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" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/user" "github.com/nspcc-dev/neofs-sdk-go/user"
@ -147,6 +148,10 @@ func newCachedContainerStorage(v container.Source) *ttlContainerStorage {
return (*ttlContainerStorage)(lruCnrCache) 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 // 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. // or expired, then it returns value from side chain and updates the cache.
func (s *ttlContainerStorage) Get(cnr cid.ID) (*container.Container, error) { func (s *ttlContainerStorage) Get(cnr cid.ID) (*container.Container, error) {

View file

@ -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 { if c.cfgMorph.disableCache {
c.cfgObject.eaclSource = eACLFetcher c.cfgObject.eaclSource = eACLFetcher
cnrRdr.eacl = eACLFetcher cnrRdr.eacl = eACLFetcher
@ -87,6 +81,16 @@ func initContainerService(c *cfg) {
cachedEACLStorage := newCachedEACLStorage(eACLFetcher) cachedEACLStorage := newCachedEACLStorage(eACLFetcher)
cachedContainerLister := newCachedContainerLister(wrap) 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.eaclSource = cachedEACLStorage
c.cfgObject.cnrSource = cachedContainerStorage c.cfgObject.cnrSource = cachedContainerStorage