diff --git a/cmd/neofs-node/cache.go b/cmd/neofs-node/cache.go index d841f9c3d..7375047e2 100644 --- a/cmd/neofs-node/cache.go +++ b/cmd/neofs-node/cache.go @@ -128,13 +128,10 @@ func (c *lruNetCache) get(key interface{}) (interface{}, error) { // that implements container storage. type ttlContainerStorage ttlNetCache -func newCachedContainerStorage(v container.Source) *ttlContainerStorage { - const ( - containerCacheSize = 100 - containerCacheTTL = 30 * time.Second - ) +func newCachedContainerStorage(v container.Source, ttl time.Duration) *ttlContainerStorage { + const containerCacheSize = 100 - lruCnrCache := newNetworkTTLCache(containerCacheSize, containerCacheTTL, func(key interface{}) (interface{}, error) { + lruCnrCache := newNetworkTTLCache(containerCacheSize, ttl, func(key interface{}) (interface{}, error) { var id cid.ID err := id.DecodeString(key.(string)) @@ -165,13 +162,10 @@ func (s *ttlContainerStorage) Get(cnr cid.ID) (*container.Container, error) { type ttlEACLStorage ttlNetCache -func newCachedEACLStorage(v eacl.Source) *ttlEACLStorage { - const ( - eaclCacheSize = 100 - eaclCacheTTL = 30 * time.Second - ) +func newCachedEACLStorage(v eacl.Source, ttl time.Duration) *ttlEACLStorage { + const eaclCacheSize = 100 - lruCnrCache := newNetworkTTLCache(eaclCacheSize, eaclCacheTTL, func(key interface{}) (interface{}, error) { + lruCnrCache := newNetworkTTLCache(eaclCacheSize, ttl, func(key interface{}) (interface{}, error) { var id cid.ID err := id.DecodeString(key.(string)) @@ -253,13 +247,10 @@ type cacheItemContainerList struct { list []cid.ID } -func newCachedContainerLister(c *cntClient.Client) *ttlContainerLister { - const ( - containerListerCacheSize = 100 - containerListerCacheTTL = 30 * time.Second - ) +func newCachedContainerLister(c *cntClient.Client, ttl time.Duration) *ttlContainerLister { + const containerListerCacheSize = 100 - lruCnrListerCache := newNetworkTTLCache(containerListerCacheSize, containerListerCacheTTL, func(key interface{}) (interface{}, error) { + lruCnrListerCache := newNetworkTTLCache(containerListerCacheSize, ttl, func(key interface{}) (interface{}, error) { var ( id *user.ID strID = key.(string) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index dc9c29bfa..9f00240c1 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -148,7 +148,8 @@ type cfgMorph struct { notaryEnabled bool - disableCache bool + // TTL of Sidechain cached values. Non-positive value disables caching. + cacheTTL time.Duration eigenTrustTicker *eigenTrustTickers // timers for EigenTrust iterations diff --git a/cmd/neofs-node/config/morph/config.go b/cmd/neofs-node/config/morph/config.go index 83c7be33e..c81d744d5 100644 --- a/cmd/neofs-node/config/morph/config.go +++ b/cmd/neofs-node/config/morph/config.go @@ -27,6 +27,8 @@ const ( // PriorityDefault is a default endpoint priority for the morph client. PriorityDefault = 1 + + CacheTTLDefault = 30 * time.Second ) // RPCEndpoint returns list of the values of "rpc_endpoint" config parameter @@ -74,8 +76,15 @@ func DialTimeout(c *config.Config) time.Duration { return DialTimeoutDefault } -// DisableCache returns the value of "disable_cache" config parameter +// CacheTTL returns the value of "cache_ttl" config parameter // from "morph" section. -func DisableCache(c *config.Config) bool { - return config.BoolSafe(c.Sub(subsection), "disable_cache") +// +// Returns CacheTTLDefault if value is zero or invalid. Supports negative durations. +func CacheTTL(c *config.Config) time.Duration { + res := config.DurationSafe(c.Sub(subsection), "cache_ttl") + if res != 0 { + return res + } + + return CacheTTLDefault } diff --git a/cmd/neofs-node/config/morph/config_test.go b/cmd/neofs-node/config/morph/config_test.go index fa26e1044..24bdf24a8 100644 --- a/cmd/neofs-node/config/morph/config_test.go +++ b/cmd/neofs-node/config/morph/config_test.go @@ -17,7 +17,7 @@ func TestMorphSection(t *testing.T) { require.Panics(t, func() { morphconfig.RPCEndpoint(empty) }) require.Equal(t, morphconfig.DialTimeoutDefault, morphconfig.DialTimeout(empty)) - require.Equal(t, false, morphconfig.DisableCache(empty)) + require.Equal(t, morphconfig.CacheTTLDefault, morphconfig.CacheTTL(empty)) }) const path = "../../../../config/example/node" @@ -32,7 +32,7 @@ func TestMorphSection(t *testing.T) { var fileConfigTest = func(c *config.Config) { require.Equal(t, rpcs, morphconfig.RPCEndpoint(c)) require.Equal(t, 30*time.Second, morphconfig.DialTimeout(c)) - require.Equal(t, true, morphconfig.DisableCache(c)) + require.Equal(t, 15*time.Second, morphconfig.CacheTTL(c)) } configtest.ForEachFileType(path, fileConfigTest) diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index efb2dbcbb..056e024bb 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -63,7 +63,7 @@ func initContainerService(c *cfg) { neoClient: wrap, } - if c.cfgMorph.disableCache { + if c.cfgMorph.cacheTTL <= 0 { c.cfgObject.eaclSource = eACLFetcher cnrRdr.eacl = eACLFetcher c.cfgObject.cnrSource = cnrSrc @@ -71,9 +71,9 @@ func initContainerService(c *cfg) { cnrRdr.lister = wrap } else { // use RPC node as source of Container contract items (with caching) - cachedContainerStorage := newCachedContainerStorage(cnrSrc) - cachedEACLStorage := newCachedEACLStorage(eACLFetcher) - cachedContainerLister := newCachedContainerLister(wrap) + cachedContainerStorage := newCachedContainerStorage(cnrSrc, c.cfgMorph.cacheTTL) + cachedEACLStorage := newCachedEACLStorage(eACLFetcher, c.cfgMorph.cacheTTL) + cachedContainerLister := newCachedContainerLister(wrap, c.cfgMorph.cacheTTL) subscribeToContainerCreation(c, func(e event.Event) { ev := e.(containerEvent.PutSuccess) diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index ce2690993..54d0bccbf 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -86,9 +86,9 @@ func initMorphComponents(c *cfg) { var netmapSource netmap.Source - c.cfgMorph.disableCache = morphconfig.DisableCache(c.appCfg) + c.cfgMorph.cacheTTL = morphconfig.CacheTTL(c.appCfg) - if c.cfgMorph.disableCache { + if c.cfgMorph.cacheTTL <= 0 { netmapSource = wrap } else { // use RPC node as source of netmap (with caching) diff --git a/config/example/node.env b/config/example/node.env index 1544c444f..bd745c3f2 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -61,7 +61,7 @@ NEOFS_CONTRACTS_PROXY=ad7c6b55b737b696e5c82c85445040964a03e97f # Morph chain section NEOFS_MORPH_DIAL_TIMEOUT=30s -NEOFS_MORPH_DISABLE_CACHE=true +NEOFS_MORPH_CACHE_TTL=15s NEOFS_MORPH_RPC_ENDPOINT_0_ADDRESS="wss://rpc1.morph.fs.neo.org:40341/ws" NEOFS_MORPH_RPC_ENDPOINT_0_PRIORITY=0 NEOFS_MORPH_RPC_ENDPOINT_1_ADDRESS="wss://rpc2.morph.fs.neo.org:40341/ws" diff --git a/config/example/node.json b/config/example/node.json index ab639adbc..9b5548f01 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -99,7 +99,7 @@ }, "morph": { "dial_timeout": "30s", - "disable_cache": true, + "cache_ttl": "15s", "rpc_endpoint": [ { "address": "wss://rpc1.morph.fs.neo.org:40341/ws", diff --git a/config/example/node.yaml b/config/example/node.yaml index 89180417c..fe0160057 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -81,7 +81,8 @@ contracts: # side chain NEOFS contract script hashes; optional, override values morph: dial_timeout: 30s # timeout for side chain NEO RPC client connection - disable_cache: true # do not use TTL cache for side chain GET operations + cache_ttl: 15s # Sidechain cache TTL value (min interval between similar calls). Negative value disables caching. + # Cached entities: containers, container lists, eACL tables. rpc_endpoint: # side chain NEO RPC endpoints; are shuffled and used one by one until the first success - address: wss://rpc1.morph.fs.neo.org:40341/ws priority: 0