Skip to content

[Bug]: HashBuild spill bundle drops file ownership after RemoveFile error #30103

Description

@Ariznawlll

Description

HashBuild producer-side spill cleanup drops a physical file after a temporary RemoveFile failure: spillFileBundle.release marks the bundle released, clears its entries and releases its disk reservation even though the file still exists. A later cleanup cannot retry. This is a separate owner path from JOIN probe writer #30097 and handed-off consumer #30100.

Environment

  • Branch: official main
  • Commit: 21f19ae06305ca2acd253d15123f851899d6b6a1
  • Deployment: isolated local Go test using the production HashBuild spill bundle and local mutable file service.

Steps to reproduce

  1. Create one physical spill file and reserve its exact disk bytes in an ExecutionResourceGeneration.
  2. Install the file as a created spillFileBundle entry. Wrap only RemoveFile so deletion fails while all other file operations remain normal.
  3. Call HashBuild.cleanupSpillFiles, then inspect the file, SpillDiskUsed, and the bundle ownership. Clear the injected error and call cleanup again.

The reproducer is in PR #30102, pkg/sql/colexec/hashbuild/spill_bundle_cleanup_test.go.

Actual behavior

  • The file remains openable after cleanup, while SpillDiskUsed becomes zero and the operator loses its bundle pointer.
  • A second cleanup has no file name or reservation to retry.
  • The fault path reproduced 3/3 on official main; the identical healthy control removed the file and returned disk usage to zero.

Expected behavior

Keep the failed entry and disk reservation until removal succeeds. A later Reset, Free, or Prepare should retry instead of overwriting the pending cleanup owner.

Code analysis

pkg/sql/colexec/hashbuild/types.go: spillFileBundle.release discarded the RemoveFile result and unconditionally released the disk token. HashBuild.cleanupSpillFiles then cleared the bundle pointer. The same ownership loss was possible in the build failure defer.

Regression coverage

PR #30102 adds the fault/control Go test. The fix passed the six related Go package suites and the new test with -race -count=20 locally.

Related

#30097 covers probe-side BucketWriter; #30100 covers already handed-off SpillFile. This issue covers producer-side HashBuild.spillFileBundle before handoff.

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。实际 SQL 的 JOIN spill 在创建和删除同时受阻、并发取消后出现临时文件残留;该现象与本 issue 的 HashBuild 清理路径相关,但尚未单独隔离删除失败。

    关键证据

    • 版本:main@bbfe55669a1440424914d45a283a1d0e36f722fa;本地隔离双 CN、单 TN。
    • 对已有约 28.8 万行数据的 JOIN 设置 join_spill_mem=1000;观察到 170 个 spill 文件后,临时移除 spill 目录写权限并发出 KILL QUERY。查询返回 20101,具体原因是创建 join_hb_*_build 文件时 permission denied;恢复权限后仍有 181 个文件,连接的 SELECT 1 正常。该混合注入目前观察 1 次。
    • 正常对照:相同数据在 4 个客户端、约 3 分钟内执行 70 次,结果均与独立预期一致,结束后 spill 目录为空。独立的目录创建失败测试在恢复权限后可重试成功。
    • 白盒线索:spillFileBundle.release 忽略 RemoveFile 返回值;文件名前缀和故障时机与该路径相符,但这次 SQL 现象不能单独证明具体所有权阶段。

    待解决点

    • 在只让 RemoveFile 失败、其他文件操作正常的条件下,重复验证具体清理路径和权限恢复后的重试;现有 SQL 故障同时阻断文件创建与删除。
    • 补充更长时间、多次取消及跨 CN 场景,确认残留文件与磁盘资源计量是否最终恢复。
  6. Ariznawlll commented on Nov 4, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。仅注入 spill 文件删除失败时,HashBuild 丢失文件清理所有权并提前释放磁盘记账;文件系统恢复后再次清理仍无法删除残留文件。

    关键证据

    • 2026-11-04 官方 main@0f6c07639604c40d7ca880cb63d1d282239def08,macOS arm64,独立 Go 测试进程;使用生产 HashBuild bundle 和真实本地 spill 文件,仅对 RemoveFile 注入错误,不阻断文件创建、写入和读取。
    • 参考 PR #30102 的早期 fault/control 测试,在最新 main 运行验收断言:正常删除对照 3/3 成功;删除失败 3/3 在“文件仍存在时应保留磁盘记账”的断言失败,实际 SpillDiskUsed=0。
    • 补充观察测试在相同注入下 3/3 确认文件仍可打开、HashBuild 的 bundle 指针已清空;恢复文件系统并再次调用清理后文件仍存在且记账为 0。无故障对照 3/3 删除文件并释放记账。测试结束后显式删除诊断文件。
    • 本轮针对单个 bundle 的确定性错误路径;没有将其说成已复现生产并发取消或创建失败场景。已有相关修复 PR #30102 尚未合入且当前有冲突。

    待解决点

    • 请研发处理失败删除后的所有权、重试和磁盘计量,并在修复合入后重跑物理文件、记账及故障恢复断言;再按需要覆盖并发取消和跨 CN。该内部故障注入应由 Go 回归覆盖,不应把当前错误结果录成通过型 SQL 预期。
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