From e8665f6ceffc921d06a65ca4f072e86bdbb7ee88 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 29 Jul 2021 18:57:53 +0300 Subject: [PATCH] [#730] node/morph: Use `disable_cache` config param Do not init caches for eACL, containers and netmap if `disable_cache` config options is `true`, use direct RPC calls instead. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 4 +++ cmd/neofs-node/cache.go | 2 +- cmd/neofs-node/config.go | 6 ++-- cmd/neofs-node/container.go | 10 +++++- cmd/neofs-node/morph.go | 14 +++++++- cmd/neofs-node/object.go | 36 +++++++++++++------- pkg/services/object/acl/eacl/opts.go | 2 +- pkg/services/object/acl/eacl/types.go | 10 +++--- pkg/services/object/acl/eacl/v2/eacl_test.go | 2 +- pkg/services/object/acl/eacl/validator.go | 2 +- 10 files changed, 63 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 304fea26..e4dcd6b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Changelog for NeoFS Node ## [Unreleased] +### Upgrading from v0.23.0 +Added `NEOFS_MORPH_DISABLE_CACHE` env. If `true`, none of +the `eACL`/`netmap`/`container` RPC responses cached. + ## [0.23.0] - 2021-07-23 - Wando (완도, 莞島) Improved stability for notary disabled environment. diff --git a/cmd/neofs-node/cache.go b/cmd/neofs-node/cache.go index bbcf160f..8d5f928b 100644 --- a/cmd/neofs-node/cache.go +++ b/cmd/neofs-node/cache.go @@ -159,7 +159,7 @@ func (s *ttlContainerStorage) Get(cid *cid.ID) (*containerSDK.Container, error) type ttlEACLStorage ttlNetCache -func newCachedEACLStorage(v eacl.Storage) eacl.Storage { +func newCachedEACLStorage(v eacl.Source) eacl.Source { const ( eaclCacheSize = 100 eaclCacheTTL = 30 * time.Second diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index e0bc3aff..d5ec7174 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -127,6 +127,8 @@ type cfgGRPC struct { type cfgMorph struct { client *client.Client + disableCache bool + blockTimers []*timer.BlockTimer // all combined timers eigenTrustTimer *timer.BlockTimer // timer for EigenTrust iterations } @@ -165,9 +167,9 @@ type cfgNodeInfo struct { } type cfgObject struct { - netMapStorage netmapCore.Source + netMapSource netmapCore.Source - cnrStorage container.Source + cnrSource container.Source cnrClient *cntwrapper.Wrapper diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 0216cd12..711be629 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -43,7 +43,15 @@ func initContainerService(c *cfg) { cnrSrc := wrapper.AsContainerSource(wrap) - c.cfgObject.cnrStorage = newCachedContainerStorage(cnrSrc) // use RPC node as source of containers (with caching) + var containerSource containerCore.Source + + if c.cfgMorph.disableCache { + containerSource = cnrSrc + } else { + containerSource = newCachedContainerStorage(cnrSrc) // use RPC node as source of containers (with caching) + } + + c.cfgObject.cnrSource = containerSource c.cfgObject.cnrClient = wrap localMetrics := &localStorageLoad{ diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 07adc34b..47d09d85 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" mainchainconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/mainchain" morphconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/morph" + "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" @@ -61,7 +62,18 @@ func initMorphComponents(c *cfg) { wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgNetmap.scriptHash, 0) fatalOnErr(err) - c.cfgObject.netMapStorage = newCachedNetmapStorage(c.cfgNetmap.state, wrap) + var netmapSource netmap.Source + + c.cfgMorph.disableCache = morphconfig.DisableCache(c.appCfg) + + if c.cfgMorph.disableCache { + netmapSource = wrap + } else { + // use RPC node as source of netmap (with caching) + netmapSource = newCachedNetmapStorage(c.cfgNetmap.state, wrap) + } + + c.cfgObject.netMapSource = netmapSource c.cfgNetmap.wrapper = wrap } diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index cbdbea9a..8e5df0e0 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -187,7 +187,7 @@ func initObjectService(c *cfg) { clientConstructor := &reputationClientConstructor{ log: c.log, - nmSrc: c.cfgObject.netMapStorage, + nmSrc: c.cfgObject.netMapSource, netState: c.cfgNetmap.state, trustStorage: c.cfgReputation.localTrustStorage, basicConstructor: c.clientCache, @@ -230,9 +230,9 @@ func initObjectService(c *cfg) { pol := policer.New( policer.WithLogger(c.log), policer.WithLocalStorage(ls), - policer.WithContainerSource(c.cfgObject.cnrStorage), + policer.WithContainerSource(c.cfgObject.cnrSource), policer.WithPlacementBuilder( - placement.NewNetworkMapSourceBuilder(c.cfgObject.netMapStorage), + placement.NewNetworkMapSourceBuilder(c.cfgObject.netMapSource), ), policer.WithWorkScope(100), policer.WithExpansionRate(10), @@ -265,7 +265,7 @@ func initObjectService(c *cfg) { } }) - traverseGen := util.NewTraverserGenerator(c.cfgObject.netMapStorage, c.cfgObject.cnrStorage, c) + traverseGen := util.NewTraverserGenerator(c.cfgObject.netMapSource, c.cfgObject.cnrSource, c) c.workers = append(c.workers, pol) @@ -274,8 +274,8 @@ func initObjectService(c *cfg) { putsvc.WithClientConstructor(coreConstructor), putsvc.WithMaxSizeSource(c), putsvc.WithLocalStorage(ls), - putsvc.WithContainerSource(c.cfgObject.cnrStorage), - putsvc.WithNetworkMapSource(c.cfgObject.netMapStorage), + putsvc.WithContainerSource(c.cfgObject.cnrSource), + putsvc.WithNetworkMapSource(c.cfgObject.netMapSource), putsvc.WithLocalAddressSource(c), putsvc.WithFormatValidatorOpts( objectCore.WithDeleteHandler(objInhumer), @@ -364,6 +364,20 @@ func initObjectService(c *cfg) { respSvc, ) + var ( + eACLSource eacl.Source + eACLFetcher = &morphEACLFetcher{ + w: c.cfgObject.cnrClient, + } + ) + + if c.cfgMorph.disableCache { + eACLSource = eACLFetcher + } else { + // use RPC node as source of eACL (with caching) + eACLSource = newCachedEACLStorage(eACLFetcher) + } + aclSvc := acl.New( acl.WithSenderClassifier( acl.NewSenderClassifier( @@ -373,14 +387,12 @@ func initObjectService(c *cfg) { ), ), acl.WithContainerSource( - c.cfgObject.cnrStorage, + c.cfgObject.cnrSource, ), acl.WithNextService(signSvc), acl.WithLocalStorage(ls), acl.WithEACLValidatorOptions( - eacl.WithEACLStorage(newCachedEACLStorage(&morphEACLStorage{ - w: c.cfgObject.cnrClient, - })), + eacl.WithEACLSource(eACLSource), eacl.WithLogger(c.log), ), acl.WithNetmapState(c.cfgNetmap.state), @@ -398,7 +410,7 @@ func initObjectService(c *cfg) { } } -type morphEACLStorage struct { +type morphEACLFetcher struct { w *cntrwrp.Wrapper } @@ -413,7 +425,7 @@ func (s *signedEACLTable) SignedDataSize() int { return (*eaclSDK.Table)(s).ToV2().StableSize() } -func (s *morphEACLStorage) GetEACL(cid *cid.ID) (*eaclSDK.Table, error) { +func (s *morphEACLFetcher) GetEACL(cid *cid.ID) (*eaclSDK.Table, error) { table, err := s.w.GetEACL(cid) if err != nil { return nil, err diff --git a/pkg/services/object/acl/eacl/opts.go b/pkg/services/object/acl/eacl/opts.go index 4cc0a318..1b5b40d5 100644 --- a/pkg/services/object/acl/eacl/opts.go +++ b/pkg/services/object/acl/eacl/opts.go @@ -10,7 +10,7 @@ func WithLogger(v *logger.Logger) Option { } } -func WithEACLStorage(v Storage) Option { +func WithEACLSource(v Source) Option { return func(c *cfg) { c.storage = v } diff --git a/pkg/services/object/acl/eacl/types.go b/pkg/services/object/acl/eacl/types.go index 973c9ce2..a2e859a4 100644 --- a/pkg/services/object/acl/eacl/types.go +++ b/pkg/services/object/acl/eacl/types.go @@ -6,16 +6,16 @@ import ( bearer "github.com/nspcc-dev/neofs-api-go/v2/acl" ) -// Storage is the interface that wraps -// basic methods of extended ACL table storage. -type Storage interface { - // GetEACL reads the table from the storage by identifier. +// Source is the interface that wraps +// basic methods of extended ACL table source. +type Source interface { + // GetEACL reads the table from the source by identifier. // It returns any error encountered. // // GetEACL must return exactly one non-nil value. // // Must return pkg/core/container.ErrEACLNotFound if requested - // eACL table is not in storage. + // eACL table is not in source. GetEACL(*cid.ID) (*eacl.Table, error) } diff --git a/pkg/services/object/acl/eacl/v2/eacl_test.go b/pkg/services/object/acl/eacl/v2/eacl_test.go index 6c16e784..d925eb51 100644 --- a/pkg/services/object/acl/eacl/v2/eacl_test.go +++ b/pkg/services/object/acl/eacl/v2/eacl_test.go @@ -149,7 +149,7 @@ func TestHeadRequest(t *testing.T) { } validator := eacl2.NewValidator( - eacl2.WithEACLStorage(eStorage), + eacl2.WithEACLSource(eStorage), ) require.Equal(t, eacl.ActionDeny, validator.CalculateAction(unit)) diff --git a/pkg/services/object/acl/eacl/validator.go b/pkg/services/object/acl/eacl/validator.go index 21243320..187d4978 100644 --- a/pkg/services/object/acl/eacl/validator.go +++ b/pkg/services/object/acl/eacl/validator.go @@ -23,7 +23,7 @@ type Option func(*cfg) type cfg struct { logger *logger.Logger - storage Storage + storage Source } func defaultCfg() *cfg {