Skip to content

[Bug]: handed-off JOIN spill files remain on disk after transient removal error #30100

Description

@Ariznawlll

Problem

After a JOIN build spill file has been transferred from spillutil.BucketWriter to message.SpillFile, a transient RemoveFile error permanently leaves the physical spill file behind. SpillFile.Close records that error under removeOnce, clears the remover, and releases the disk reservation anyway. A later Close cannot retry removal, while SpillDiskUsed() already reports zero. Repeated failures can therefore accumulate untracked files on disk.

This is the post-handoff owner path in pkg/vm/message/joinMapMsg.go, distinct from the writer cleanup before handoff in #30097 / #30099 and from GROUP/DISTINCT cleanup in #30098. SpillBuildPayload.Close also discards its file handles after a close error, and JoinMap.FreeMemory ignores the error, so the caller has no later recovery path.

Reproduction and actual result

Verified on main 175a645a85994f2c95992d3aa8d6dacb6d9e167f with a real BucketWriter write and handOffSpillFile, wrapping its file service to fail the first RemoveFile call only:

  1. Write a spill bucket and hand its file to SpillFile; SpillDiskUsed() > 0.
  2. Call SpillFile.Close(); the injected removal error is returned.
  3. The file can still be opened, but SpillDiskUsed() == 0.
  4. Call SpillFile.Close() again after the file service is healthy; it returns the cached error without calling RemoveFile again. The file remains.

Normal-path control deletes the file and releases the reservation. The fault/control probe was repeated 20 times with go test -race; all observations were consistent. The probe used a temporary test file and was not committed.

Expected

A failed deletion should not silently lose the last cleanup opportunity while reporting its disk reservation released. Cleanup ownership and accounting should remain coherent until the file has actually been removed, with an actionable error/retry path through payload and JOIN teardown.

Relevant code

  • pkg/sql/colexec/spillutil/join_spill.go: BucketWriter.handOffSpillFile transfers the remove callback and disk reservation.
  • pkg/vm/message/joinMapMsg.go: SpillFile.Close, SpillBuildPayload.Close, and JoinMap.FreeMemory handle teardown after transfer.

Activity

  1. added this to the MO-202610 milestone on Oct 13, 2026
  2. added
    kind/bug
    on Oct 13, 2026
  3. added theissue type on Oct 13, 2026
  4. Ariznawlll commented on Nov 4, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。JOIN spill 文件实际移交给消费端后,第一次删除失败会释放磁盘记账并丢失重试机会,文件系统恢复后文件仍然残留。

    关键证据

    • 2026-11-04 官方 main@0f6c07639604c40d7ca880cb63d1d282239def08,macOS arm64,独立 Go 测试进程和真实本地 spill 文件。使用生产 BucketWriter 写入实际记录,并通过 handOffSpillFile 移交,写入后先确认磁盘记账大于零;只让第一次 RemoveFile 返回注入错误。
    • 故障路径 3/3:首次 SpillFile.Close() 返回删除错误,物理文件仍可打开,但 SpillDiskUsed=0;底层后续删除已恢复时再次 Close,仍返回缓存的原错误,删除调用次数保持 1,文件继续存在。无故障对照 3/3:文件成功删除,记账归零,重复 Close 不报错。
    • 另以直接构造的 SpillFile 和实际磁盘 reservation 复核同一消费端 Close 路径,故障及正常对照各 3/3,结果一致。测试最后显式清理诊断文件。当前实现使用一次性删除和独立释放回调,与观察一致。

    待解决点

    • 请研发修复消费端的清理所有权、可恢复重试及磁盘记账一致性,并在修复后复跑真实 handoff、物理文件和资源计量断言;相关 PR #30102 尚未合入且当前有冲突。本轮未声称覆盖真实生产并发或节点故障。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions