Skip to content

quota: atomically set limitation #4158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 13, 2023
9 changes: 4 additions & 5 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3471,19 +3471,18 @@ func (m *redisMeta) doSetQuota(ctx Context, inode Ino, quota *Quota) (bool, erro
var created bool
err := m.txn(ctx, func(tx *redis.Tx) error {
origin := new(Quota)
created = true
field := inode.String()
buf, e := tx.HGet(ctx, m.dirQuotaKey(), field).Bytes()
if e == nil {
created = false
origin.MaxSpace, origin.MaxInodes = m.parseQuota(buf)
} else if e != redis.Nil {
} else if e == redis.Nil {
created = true
} else {
return e
}
if created && quota.MaxSpace < 0 && quota.MaxInodes < 0 {
// limit is deleted, skip
created = false
return nil
return errors.Errorf("limitation not set or deleted")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this into the case for e is redis.Nil

}
if quota.MaxSpace >= 0 {
origin.MaxSpace = quota.MaxSpace
Expand Down
7 changes: 3 additions & 4 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3204,7 +3204,6 @@ func (m *dbMeta) doGetQuota(ctx Context, inode Ino) (*Quota, error) {
func (m *dbMeta) doSetQuota(ctx Context, inode Ino, quota *Quota) (bool, error) {
var created bool
err := m.txn(func(s *xorm.Session) error {
created = true
origin := dirQuota{Inode: inode}
exist, e := s.ForUpdate().Get(&origin)
if e != nil {
Expand All @@ -3213,9 +3212,9 @@ func (m *dbMeta) doSetQuota(ctx Context, inode Ino, quota *Quota) (bool, error)
if exist {
created = false
} else if quota.MaxSpace < 0 && quota.MaxInodes < 0 {
// limit is deleted, skip
created = false
return nil
return errors.Errorf("limitation not set or deleted")
} else {
created = true
}
updateColumns := make([]string, 0, 4)
if quota.MaxSpace >= 0 {
Expand Down
6 changes: 2 additions & 4 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2752,20 +2752,18 @@ func (m *kvMeta) doSetQuota(ctx Context, inode Ino, quota *Quota) (bool, error)
var created bool
err := m.txn(func(tx *kvTxn) error {
var origin *Quota
created = true
buf := tx.get(m.dirQuotaKey(inode))
if len(buf) == 32 {
origin = m.parseQuota(buf)
created = false
} else if len(buf) != 0 {
return fmt.Errorf("invalid quota value: %v", buf)
} else {
created = true
origin = new(Quota)
}
if created && quota.MaxSpace < 0 && quota.MaxInodes < 0 {
// limit is deleted, skip
created = false
return nil
return errors.Errorf("limitation not set or deleted")
}
if quota.MaxSpace >= 0 {
origin.MaxSpace = quota.MaxSpace
Expand Down