Skip to content

meta: fix sustained inode accounting in volume stats#7104

Open
Xuyuchao-juice wants to merge 9 commits into
mainfrom
scan_sustained
Open

meta: fix sustained inode accounting in volume stats#7104
Xuyuchao-juice wants to merge 9 commits into
mainfrom
scan_sustained

Conversation

@Xuyuchao-juice

@Xuyuchao-juice Xuyuchao-juice commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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) while UserGroupQuota is disabled, then quota is enabled for the first time (triggering ScanUserGroupUsage), and finally the file descriptor is closed. The test asserts that UsedInodes and UsedSpace do not go negative after the close.

@Xuyuchao-juice Xuyuchao-juice marked this pull request as ready for review June 3, 2026 02:01
@jiefenghuang

Copy link
Copy Markdown
Contributor

扫描过程仍然可能不一致, 只是降低概率, 需要其他方式保证.

@jiefenghuang jiefenghuang marked this pull request as draft June 5, 2026 07:00
@jiefenghuang jiefenghuang marked this pull request as ready for review June 9, 2026 06:54
@jiefenghuang

Copy link
Copy Markdown
Contributor

testSustainedInodeQuotaDecrement 中的test顺序修改下, close放最后

Comment thread pkg/meta/redis.go Outdated
Comment thread pkg/meta/redis.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 doScanSustainedInodes helper 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.

Comment thread pkg/meta/base_test.go
Comment on lines +5595 to +5599
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)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot add test to cover this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added testSustainedInodeBeforeQuotaEnabled in commit 5ee0acb. The test:

  1. Ensures UserGroupQuota is disabled, then creates+opens+unlinks a file (creating a sustained inode while quota tracking is off)
  2. Calls HandleQuota(QuotaSet) to enable quota for the first time — this triggers ScanUserGroupUsage, which now includes the sustained inode
  3. Asserts UsedInodes > 0 after the scan (the sustained inode is counted)
  4. Calls Close on the inode and asserts UsedInodes >= 0 (no negative — the regression from User/group quota usage can become negative when quota is enabled after sustained inodes already exist #7079)

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Xuyuchao-juice
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@jiefenghuang jiefenghuang changed the title meta: Fix sustained inode accounting in volume stats meta: fix sustained inode accounting in volume stats Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User/group quota usage can become negative when quota is enabled after sustained inodes already exist

5 participants