meta: fix sustained inode accounting in volume stats#7104
meta: fix sustained inode accounting in volume stats#7104Xuyuchao-juice wants to merge 9 commits into
Conversation
|
扫描过程仍然可能不一致, 只是降低概率, 需要其他方式保证. |
|
testSustainedInodeQuotaDecrement 中的test顺序修改下, close放最后 |
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect accounting for sustained inodes (unlinked-but-still-open files) when computing volume statistics and when scanning initial user/group quota usage, addressing the negative quota usage reported in #7079.
Changes:
- Introduces an engine-level
doScanSustainedInodeshelper to iterate sustained inodes and expose(uid, gid, length)to callers. - Refactors volume stat syncing (
doSyncVolumeStat) across KV/SQL/Redis engines to reuse the sustained-inode scan helper. - Extends global user/group quota usage scanning to include sustained inodes so later decrements won’t drive usage negative; updates tests with additional sustained-unlink assertions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/meta/tkv.go | Adds sustained-inode scan helper and refactors volume stat sync to reuse it. |
| pkg/meta/sql.go | Updates sustained-inode query to include uid/gid and adds a scan helper used by volume stat sync. |
| pkg/meta/redis.go | Refactors volume stat sync to use a new sustained-inode scan helper (based on existing session scanning). |
| pkg/meta/quota.go | Includes sustained inodes in global user/group usage scan to avoid negative usage after sustained cleanup. |
| pkg/meta/base.go | Extends engine interface with doScanSustainedInodes. |
| pkg/meta/base_test.go | Adds assertions around quota behavior after unlinking a sustained file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| uidAfterUnlink := getUsedInodes(UserQuotaType, uidKey) | ||
| gidAfterUnlink := getUsedInodes(GroupQuotaType, gidKey) | ||
| if uidAfterUnlink != uidBefore+1 { | ||
| t.Fatalf("user quota inode should remain increased after unlink (sustained): before=%d after_unlink=%d", uidBefore, uidAfterUnlink) | ||
| } |
There was a problem hiding this comment.
Added testSustainedInodeBeforeQuotaEnabled in commit 5ee0acb. The test:
- Ensures
UserGroupQuotais disabled, then creates+opens+unlinks a file (creating a sustained inode while quota tracking is off) - Calls
HandleQuota(QuotaSet)to enable quota for the first time — this triggersScanUserGroupUsage, which now includes the sustained inode - Asserts
UsedInodes > 0after the scan (the sustained inode is counted) - Calls
Closeon the inode and assertsUsedInodes >= 0(no negative — the regression from User/group quota usage can become negative when quota is enabled after sustained inodes already exist #7079)
|
|
close #7079
Adds a regression test (
testSustainedInodeBeforeQuotaEnabled) that reproduces the exact scenario from #7079: a file is created, opened, and unlinked (becoming a sustained inode) whileUserGroupQuotais disabled, then quota is enabled for the first time (triggeringScanUserGroupUsage), and finally the file descriptor is closed. The test asserts thatUsedInodesandUsedSpacedo not go negative after the close.