ape: Add morph chain cache #1044

Merged
dstepanov-yadro merged 1 commit from dstepanov-yadro/frostfs-node:fix/get_performance into master 2024-09-04 19:51:07 +00:00
2 changed files with 5 additions and 37 deletions
Showing only changes of commit 5d58b44bc8 - Show all commits

View file

@ -1076,7 +1076,7 @@ func initAccessPolicyEngine(_ context.Context, c *cfg) {
)
}
var morphRuleStorage policy_engine.MorphRuleChainStorage
var morphRuleStorage policy_engine.MorphRuleChainStorageReader
morphRuleStorage = policy_client.NewContractStorage(
client.NewSwitchRPCGuardedActor(c.cfgMorph.client),
c.cfgObject.cfgAccessPolicyEngine.policyContractHash)

View file

@ -19,14 +19,10 @@ type accessPolicyEngine struct {
chainRouter engine.ChainRouter
morphChainStorage engine.MorphRuleChainStorage
localOverrideDatabase chainbase.LocalOverrideDatabase
}
var _ engine.LocalOverrideEngine = (*accessPolicyEngine)(nil)
var _ engine.MorphRuleChainStorage = (*morphAPEChainCache)(nil)
var _ engine.MorphRuleChainStorageReader = (*morphAPEChainCache)(nil)
type morphAPEChainCacheKey struct {
name chain.Name
@ -34,22 +30,17 @@ type morphAPEChainCacheKey struct {
}
type morphAPEChainCache struct {
source engine.MorphRuleChainStorage
source engine.MorphRuleChainStorageReader
cache *expirable.LRU[morphAPEChainCacheKey, []*chain.Chain]
}
func newMorphCache(source engine.MorphRuleChainStorage, size int, ttl time.Duration) engine.MorphRuleChainStorage {
func newMorphCache(source engine.MorphRuleChainStorageReader, size int, ttl time.Duration) engine.MorphRuleChainStorageReader {
return &morphAPEChainCache{
source: source,
cache: expirable.NewLRU(size, func(morphAPEChainCacheKey, []*chain.Chain) {}, ttl),
}
}
func (m *morphAPEChainCache) AddMorphRuleChain(name chain.Name, target engine.Target, c *chain.Chain) (util.Uint256, uint32, error) {
m.cache.Remove(morphAPEChainCacheKey{name: name, target: target})
return m.source.AddMorphRuleChain(name, target, c)
}
func (m *morphAPEChainCache) GetAdmin() (util.Uint160, error) {
return m.source.GetAdmin()
}
@ -70,26 +61,12 @@ func (m *morphAPEChainCache) ListMorphRuleChains(name chain.Name, target engine.
return result, nil
}
func (m *morphAPEChainCache) RemoveMorphRuleChain(name chain.Name, target engine.Target, chainID chain.ID) (util.Uint256, uint32, error) {
m.cache.Remove(morphAPEChainCacheKey{name: name, target: target})
return m.source.RemoveMorphRuleChain(name, target, chainID)
}
func (m *morphAPEChainCache) SetAdmin(addr util.Uint160) (util.Uint256, uint32, error) {
return m.source.SetAdmin(addr)
}
func (m *morphAPEChainCache) ListTargetsIterator(targetType engine.TargetType) (uuid.UUID, result.Iterator, error) {
return m.source.ListTargetsIterator(targetType)
}
func (m *morphAPEChainCache) RemoveMorphRuleChainsByTarget(name chain.Name, target engine.Target) (util.Uint256, uint32, error) {
m.cache.Remove(morphAPEChainCacheKey{name: name, target: target})
return m.source.RemoveMorphRuleChainsByTarget(name, target)
}
func newAccessPolicyEngine(
morphChainStorage engine.MorphRuleChainStorage,
morphChainStorage engine.MorphRuleChainStorageReader,
localOverrideDatabase chainbase.LocalOverrideDatabase,
) *accessPolicyEngine {
return &accessPolicyEngine{
@ -98,8 +75,6 @@ func newAccessPolicyEngine(
localOverrideDatabase,
),
morphChainStorage: morphChainStorage,
localOverrideDatabase: localOverrideDatabase,
}
}
@ -111,13 +86,6 @@ func (a *accessPolicyEngine) IsAllowed(name chain.Name, target engine.RequestTar
return a.chainRouter.IsAllowed(name, target, r)
}
func (a *accessPolicyEngine) MorphRuleChainStorage() engine.MorphRuleChainStorage {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.morphChainStorage
}
func (a *accessPolicyEngine) LocalStorage() engine.LocalOverrideStorage {
a.mtx.Lock()
defer a.mtx.Unlock()