forked from TrueCloudLab/frostfs-node
[#419] cmd/node: Cache eACL tables read from sidechain
Implement TTL cache of eACL tables read from sidechain. Use it as a eACL storage in neofs-node app. Current cache size is set to 100, TTL is 30s (constants). Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
34a51ed38b
commit
f9342aa562
2 changed files with 35 additions and 2 deletions
|
@ -5,8 +5,10 @@ import (
|
|||
"time"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
||||
containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl"
|
||||
)
|
||||
|
||||
type netValueReader func(interface{}) (interface{}, error)
|
||||
|
@ -108,3 +110,34 @@ func (s *ttlContainerStorage) Get(cid *containerSDK.ID) (*containerSDK.Container
|
|||
|
||||
return val.(*containerSDK.Container), nil
|
||||
}
|
||||
|
||||
type ttlEACLStorage ttlNetCache
|
||||
|
||||
func newCachedEACLStorage(v eacl.Storage) eacl.Storage {
|
||||
const (
|
||||
eaclCacheSize = 100
|
||||
eaclCacheTTL = 30 * time.Second
|
||||
)
|
||||
|
||||
lruCnrCache := newNetworkTTLCache(eaclCacheSize, eaclCacheTTL, func(key interface{}) (interface{}, error) {
|
||||
cid := containerSDK.NewID()
|
||||
|
||||
err := cid.Parse(key.(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return v.GetEACL(cid)
|
||||
})
|
||||
|
||||
return (*ttlEACLStorage)(lruCnrCache)
|
||||
}
|
||||
|
||||
func (s *ttlEACLStorage) GetEACL(cid *containerSDK.ID) (*eaclSDK.Table, error) {
|
||||
val, err := (*ttlNetCache)(s).get(cid.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return val.(*eaclSDK.Table), nil
|
||||
}
|
||||
|
|
|
@ -343,9 +343,9 @@ func initObjectService(c *cfg) {
|
|||
),
|
||||
acl.WithLocalStorage(ls),
|
||||
acl.WithEACLValidatorOptions(
|
||||
eacl.WithEACLStorage(&morphEACLStorage{
|
||||
eacl.WithEACLStorage(newCachedEACLStorage(&morphEACLStorage{
|
||||
w: c.cfgObject.cnrClient,
|
||||
}),
|
||||
})),
|
||||
eacl.WithLogger(c.log),
|
||||
),
|
||||
acl.WithNetmapState(c.cfgNetmap.state),
|
||||
|
|
Loading…
Reference in a new issue