Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/meta/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,15 @@ func (m *baseMeta) handleQuotaList(ctx Context, qtype uint32, key uint64, quotas
}
}
for uid, quota := range filterOrAll(userQuotas, UserQuotaType) {
if quota.MaxInodes == -1 && quota.MaxSpace == -1 {
continue
}
quotas[fmt.Sprintf("uid:%d", uid)] = quota
}
for gid, quota := range filterOrAll(groupQuotas, GroupQuotaType) {
if quota.MaxInodes == -1 && quota.MaxSpace == -1 {
continue
}
quotas[fmt.Sprintf("gid:%d", gid)] = quota
}

Expand Down
39 changes: 36 additions & 3 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4195,6 +4195,37 @@ func (m *redisMeta) doDelQuota(ctx Context, qtype uint32, key uint64) error {
return err
}

func (m *redisMeta) cleanupQuota(ctx Context, config *quotaKeys, key string, maxSpace, maxInodes int64) {
if err := m.txn(ctx, func(tx *redis.Tx) error {
usedSpace, err := tx.HGet(ctx, config.usedSpaceKey, key).Int64()
if err == redis.Nil {
usedSpace = 0
} else if err != nil {
return err
}
usedInodes, err := tx.HGet(ctx, config.usedInodesKey, key).Int64()
if err == redis.Nil {
usedInodes = 0
} else if err != nil {
return err
}
if maxSpace < 0 && maxInodes < 0 && usedSpace == 0 && usedInodes == 0 {
_, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
pipe.HDel(ctx, config.quotaKey, key)
pipe.HDel(ctx, config.usedSpaceKey, key)
pipe.HDel(ctx, config.usedInodesKey, key)
return nil
})
if err != nil {
return err
}
}
return nil
}, config.quotaKey, config.usedSpaceKey, config.usedInodesKey); err != nil {
logger.Debugf("cleanup quota %s failed: %v", key, err)
}
}

func (m *redisMeta) doLoadQuotas(ctx Context) (map[uint64]*Quota, map[uint64]*Quota, map[uint64]*Quota, error) {
quotaTypes := []struct {
qtype uint32
Expand Down Expand Up @@ -4227,9 +4258,6 @@ func (m *redisMeta) doLoadQuotas(ctx Context) (map[uint64]*Quota, map[uint64]*Qu
}

maxSpace, maxInodes := m.parseQuota(val)
if maxSpace < 0 && maxInodes < 0 {
continue
}
usedSpace, err := m.rdb.HGet(ctx, config.usedSpaceKey, key).Int64()
if err != nil && err != redis.Nil {
return err
Expand All @@ -4238,6 +4266,10 @@ func (m *redisMeta) doLoadQuotas(ctx Context) (map[uint64]*Quota, map[uint64]*Qu
if err != nil && err != redis.Nil {
return err
}
if maxSpace < 0 && maxInodes < 0 && usedSpace == 0 && usedInodes == 0 {
go m.cleanupQuota(Background(), config, key, maxSpace, maxInodes)
continue
}

quotas[id] = &Quota{
MaxSpace: int64(maxSpace),
Expand Down Expand Up @@ -4265,6 +4297,7 @@ func (m *redisMeta) doFlushQuotas(ctx Context, quotas []*iQuota) error {
}

field := strconv.FormatUint(q.qkey, 10)
pipe.HSetNX(ctx, config.quotaKey, field, m.packQuota(-1, -1))
pipe.HIncrBy(ctx, config.usedSpaceKey, field, q.quota.newSpace)
pipe.HIncrBy(ctx, config.usedInodesKey, field, q.quota.newInodes)
}
Expand Down
Loading