Skip to content

Commit

Permalink
feat/acl: add acl key cache for kv meta
Browse files Browse the repository at this point in the history
Signed-off-by: jiefeng <[email protected]>
  • Loading branch information
jiefenghuang committed Mar 8, 2024
1 parent 706955f commit 2ffb5c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
22 changes: 14 additions & 8 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ import (

type redisMeta struct {
*baseMeta
rdb redis.UniversalClient
prefix string
shaLookup string // The SHA returned by Redis for the loaded `scriptLookup`
shaResolve string // The SHA returned by Redis for the loaded `scriptResolve`
rdb redis.UniversalClient
prefix string
shaLookup string // The SHA returned by Redis for the loaded `scriptLookup`
shaResolve string // The SHA returned by Redis for the loaded `scriptResolve`
aclKeyCache map[uint32]string
}

var _ Meta = &redisMeta{}
Expand Down Expand Up @@ -243,9 +244,10 @@ func newRedisMeta(driver, addr string, conf *Config) (Meta, error) {
}

m := &redisMeta{
baseMeta: newBaseMeta(addr, conf),
rdb: rdb,
prefix: prefix,
baseMeta: newBaseMeta(addr, conf),
rdb: rdb,
prefix: prefix,
aclKeyCache: make(map[uint32]string),
}
m.en = m
m.checkServerConfig()
Expand Down Expand Up @@ -636,7 +638,11 @@ func (m *redisMeta) totalInodesKey() string {
}

func (m *redisMeta) aclKey(id uint32) string {
return fmt.Sprintf("%sacl%d", m.prefix, id)
if key, ok := m.aclKeyCache[id]; ok {
return key
}
m.aclKeyCache[id] = fmt.Sprintf("%sacl%d", m.prefix, id)
return m.aclKeyCache[id]
}

func (m *redisMeta) delfiles() string {
Expand Down
16 changes: 11 additions & 5 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ func (tx *kvTxn) deleteKeys(prefix []byte) {

type kvMeta struct {
*baseMeta
client tkvClient
snap map[Ino]*DumpedEntry
client tkvClient
snap map[Ino]*DumpedEntry
aclKeyCache map[uint32][]byte
}

var _ Meta = &kvMeta{}
Expand All @@ -100,8 +101,9 @@ func newKVMeta(driver, addr string, conf *Config) (Meta, error) {
// TODO: ping server and check latency > Millisecond
// logger.Warnf("The latency to database is too high: %s", time.Since(start))
m := &kvMeta{
baseMeta: newBaseMeta(addr, conf),
client: client,
baseMeta: newBaseMeta(addr, conf),
client: client,
aclKeyCache: make(map[uint32][]byte),
}
m.en = m
return m, nil
Expand Down Expand Up @@ -253,7 +255,11 @@ func (m *kvMeta) dirQuotaKey(inode Ino) []byte {
}

func (m *kvMeta) aclKey(id uint32) []byte {
return m.fmtKey("R", id)
if key, ok := m.aclKeyCache[id]; ok {
return key
}
m.aclKeyCache[id] = m.fmtKey("R", id)
return m.aclKeyCache[id]
}

func (m *kvMeta) parseACLId(key string) uint32 {
Expand Down

0 comments on commit 2ffb5c9

Please sign in to comment.