Repository navigation
Description
Description
GROUP and COUNT(DISTINCT) spill cleanup can orphan a physical spill file after a transient RemoveFile error. The operator discards its last bucket reference and releases the disk reservation, so resource accounting reports zero while the file still exists. This is a white-box fault-injection finding, not a claim that a production filesystem has already returned this error.
Environment
- Branch: official
main - Commit:
175a645a85994f2c95992d3aa8d6dacb6d9e167f - Deployment: isolated local Go test process using the production Group and distinct-spill bucket code with a wrapper around
MutableFileService; no cluster configuration change.
Steps to reproduce
- Open a Group spill bucket through
container.openSpillBucket, write a physical record, and confirmSpillDiskUsed > 0. - Wrap
RemoveFileso its first call returns an injected error and every later call delegates to the normal file service. - Put the bucket in
currentSpillBktand callfreeSpillBkts. Repeat with a distinct-spill controller owning a root bucket and callclose. - Inspect the physical spill file,
SpillDiskUsed, and the number of deletion attempts. Call cleanup again.
Actual behavior
- Both Group and distinct-spill cleanup attempt deletion only once and lose the bucket reference.
- The physical file remains after cleanup, but
SpillDiskUsed=0andSpillFDUsed=0. A later cleanup has nothing to retry. - The injected error is transient: a second
RemoveFilecall succeeds.
Expected behavior
Cleanup should remove the file after a transient deletion error. If deletion continues to fail, the bucket and disk reservation must remain owned so a later cleanup can retry, and the failure must be observable.
Stability and controls
- Group and distinct-spill fault paths: reproduced 3/3 ordinary runs and 20/20
-raceruns on the original main code. - No-fault Group control: file removed and disk/FD counters return to zero.
- Failure atomicity/data check: no user table is modified by this unit-level reproducer.
Evidence
- On original main, acceptance tests requiring two deletion attempts failed with
expected: 2, actual: 1for both Group and distinct-spill. - Source:
pkg/sql/colexec/group/types2.go:spillBucket.freedropsfileFSand releasesdiskTokeneven ifRemoveFilefails;freeSpillBktsdiscards its bucket list.pkg/sql/colexec/group/distinct_spill.go: controllercloseignoresfreeerrors and clears its bucket arrays.
Code analysis
This is a cleanup-ownership defect, not an aggregate-result mismatch. The file service was otherwise healthy: its next delete would succeed. A bounded deletion retry plus preserving failed buckets for a later cleanup repairs the reproduced case and keeps accounting aligned with physical file ownership if deletion remains unavailable.
Regression coverage
Add Group Go UTs for normal deletion, one-shot RemoveFile failure, and persistent failure followed by service recovery, covering both generic Group buckets and distinct-spill buckets. Verify file existence, retry count, disk/FD reservations, and -race stability.
Related
#30097 concerns JOIN probe spill cleanup and has a separate writer implementation. The two defects share the same resource-accounting invariant but require separate code changes and tests.
Activity
Ariznawlll commentedon Nov 4, 2026
结论
测试不通过。GROUP 与 DISTINCT spill 清理在删除失败时丢失文件引用并释放磁盘记账,恢复后再次清理不能删除残留文件。
关键证据
main@0f6c07639604c40d7ca880cb63d1d282239def08,macOS arm64,独立 Go 测试进程;通过生产openSpillBucket创建并写入真实本地 spill 文件,关闭写入侧后确认磁盘记账大于零、FD 记账为零,仅对首次RemoveFile注入错误。currentSpillBkt/freeSpillBkts和 DISTINCT 的root/close:两个入口故障各 3/3,物理文件仍可打开,磁盘和 FD 记账均为零,owner 引用已清空;再次清理没有第二次删除。两种入口各 3/3 正常对照均删除文件、释放记账。每轮结束后显式清理诊断文件。spillBucket.free在删除报错后仍清除文件服务并释放磁盘 reservation;上层两个清理入口继续丢弃 bucket。测试中的PASS表示对故障现象的观察断言成功,不表示产品通过。待解决点