Skip to content

Commit

Permalink
meta: fix the issue that quota may be updated twice when unlink/renam…
Browse files Browse the repository at this point in the history
…e opened files (#5043)

Signed-off-by: jiefenghuang <[email protected]>
  • Loading branch information
jiefenghuang authored Aug 6, 2024
1 parent 7295525 commit aab30fa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
60 changes: 58 additions & 2 deletions pkg/meta/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,62 @@ func testQuota(t *testing.T, m Meta) {
}
}

getUsedInodes := func(path string) int64 {
m.getBase().doFlushQuotas()
qs := make(map[string]*Quota)
if err := m.HandleQuota(ctx, QuotaGet, path, qs, false, false); err != nil {
t.Fatalf("HandleQuota list: %s", err)
}
return qs[path].UsedInodes
}

// unlink opened file
var nInode Ino
if st := m.Lookup(ctx, parent, "f2", &nInode, &attr, false); st != 0 {
t.Fatalf("Lookup quota/d2/f2: %s", st)
}

if st := m.Open(ctx, nInode, 0, &attr); st != 0 {
t.Fatalf("Open quota/d2/f2: %s", st)
}

if st := m.Unlink(ctx, parent, "f2"); st != 0 {
t.Fatalf("Unlink quota/d2/f2 err: %s", st)
}

if st := m.Close(ctx, nInode); st != 0 {
t.Fatalf("Close quota/d2/f2: %s", st)
}

if used := getUsedInodes("/quota"); used != 5 {
t.Fatalf("used inodes of /quota should be 5, but got %d", used)
}

// rename opened file
if st := m.Lookup(ctx, inode, "f22", &nInode, &attr, false); st != 0 {
t.Fatalf("Lookup quota/d2/d22/f22: %s", st)
}

if st := m.Open(ctx, nInode, 0, &attr); st != 0 {
t.Fatalf("Open quota/d2/d22/f22: %s", st)
}

if st := m.Rename(ctx, inode, "f22", inode, "f23", 0, &nInode, nil); st != 0 {
t.Fatalf("Rename quota/d2/d22/f22 to quota/d2/d22/f23 err: %s", st)
}

if st := m.Close(ctx, nInode); st != 0 {
t.Fatalf("Close quota/d2/d22/f23: %s", st)
}

if used := getUsedInodes("/quota"); used != 5 {
t.Fatalf("used inodes of /quota should be 5, but got %d", used)
}

if st := m.Create(ctx, parent, "f3", 0644, 0, 0, &nInode, &attr); st != 0 {
t.Fatalf("Create quota/d2/f3: %s", st)
}

if err := m.HandleQuota(ctx, QuotaDel, "/quota/d1", nil, false, false); err != nil {
t.Fatalf("HandleQuota del /quota/d1: %s", err)
}
Expand All @@ -3007,8 +3063,8 @@ func testQuota(t *testing.T, m Meta) {
}
}
m.getBase().loadQuotas()
if st := m.Create(ctx, parent, "f3", 0644, 0, 0, nil, &attr); st != syscall.EDQUOT {
t.Fatalf("Create quota/d22/f3: %s", st)
if st := m.Create(ctx, parent, "f4", 0644, 0, 0, nil, &attr); st != syscall.EDQUOT {
t.Fatalf("Create quota/d22/f4: %s", st)
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,6 @@ func (m *redisMeta) doDeleteSustainedInode(sid uint64, inode Ino) error {
if err == nil && newSpace < 0 {
m.updateStats(newSpace, -1)
m.tryDeleteFileData(inode, attr.Length, false)
m.updateDirQuota(Background, attr.Parent, newSpace, -1)
}
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,6 @@ func (m *dbMeta) doDeleteSustainedInode(sid uint64, inode Ino) error {
if err == nil && newSpace < 0 {
m.updateStats(newSpace, -1)
m.tryDeleteFileData(inode, n.Length, false)
m.updateDirQuota(Background, n.Parent, newSpace, -1)
}
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,6 @@ func (m *kvMeta) doDeleteSustainedInode(sid uint64, inode Ino) error {
if err == nil && newSpace < 0 {
m.updateStats(newSpace, -1)
m.tryDeleteFileData(inode, attr.Length, false)
m.updateDirQuota(Background, attr.Parent, newSpace, -1)
}
return err
}
Expand Down

0 comments on commit aab30fa

Please sign in to comment.