Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
davies committed Dec 12, 2024
1 parent 033b7e2 commit 2ef0e4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
5 changes: 0 additions & 5 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -3197,10 +3197,5 @@ func (m *baseMeta) LoadMetaV2(ctx Context, r io.Reader, opt *LoadOption) error {
}
}
wg.Wait()

// insert max acl id
if err := m.en.load(ctx, segTypeAcl, opt, nil); err != nil {
logger.Errorf("failed to insert acl id: %s", err)
}
return nil
}
33 changes: 11 additions & 22 deletions pkg/meta/redis_bak.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,39 +825,28 @@ func (m *redisMeta) loadSliceRefs(ctx Context, msg proto.Message) error {
}

var loadLock sync.Mutex
var maxAclId uint32 = 0

func (m *redisMeta) loadAcl(ctx Context, msg proto.Message) error {
if msg == nil {
loadLock.Lock()
defer loadLock.Unlock()
if val := ctx.Value("maxAclId"); val != nil {
return m.rdb.Set(ctx, m.counterKey(aclCounter), val.(uint32), 0).Err()
}
return nil
}

var maxId uint32 = 0
loadLock.Lock()
if val := ctx.Value("maxAclId"); val != nil {
maxId = val.(uint32)
}
loadLock.Unlock()

batch := msg.(*pb.Batch)
acls := make(map[string]interface{}, len(batch.Acls))
for _, pa := range batch.Acls {
if pa.Id > maxId {
maxId = pa.Id
loadLock.Lock()
if pa.Id > maxAclId {
maxAclId = pa.Id
}
loadLock.Unlock()
acls[strconv.FormatUint(uint64(pa.Id), 10)] = pa.Data
}
if len(acls) == 0 {
return nil
}
loadLock.Lock()
ctx.WithValue("maxAclId", maxId)
loadLock.Unlock()
return m.rdb.HSet(ctx, m.aclKey(), acls).Err()

err := m.rdb.HSet(ctx, m.aclKey(), acls).Err()
if err != nil {
return err
}
return m.rdb.Set(ctx, m.counterKey(aclCounter), maxAclId, 0).Err()
}

func (m *redisMeta) loadXattrs(ctx Context, msg proto.Message) error {
Expand Down
3 changes: 0 additions & 3 deletions pkg/meta/sql_bak.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,6 @@ func (m *dbMeta) loadSliceRefs(ctx Context, msg proto.Message) error {
}

func (m *dbMeta) loadAcl(ctx Context, msg proto.Message) error {
if msg == nil {
return nil
}
acls := msg.(*pb.Batch).Acls
rows := make([]interface{}, 0, len(acls))
for _, pa := range acls {
Expand Down

0 comments on commit 2ef0e4e

Please sign in to comment.