Skip to content

[Bug]: DiskCache can exhaust a single ext4 directory's htree capacity (ENOSPC) while isDiskFull() ignores ENOSPC #30167

Done

Description

@loveRhythm1990

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main (also observed on a production 4.2 release build at commit d2393868a)

Commit ID

5a0570ea70083c9365719009a5ed8d7618f9ed91

Other Environment Information

  • Hardware parameters: ext4 data volume (local SSD), large_dir feature not enabled
  • OS type: Linux (production Kubernetes node, ext4 local volume)
  • Others: analysis only, not field-observed for the exact per-directory entry count; the ext4 kernel warning below is field-observed.

Actual Behavior

DiskCache.writeFile persistently fails with no space left on device (ENOSPC) on os.Rename into a single DiskCache sub-directory, even though:

  • the filesystem has hundreds of GB of free space (df/node_filesystem_avail_bytes),
  • free inodes are plentiful,
  • the application-level disk-cache usage is well under its configured capacity (mo_fs_cache_bytes{type="inuse"} far below type="cap").

Root cause, confirmed in a production deployment with read-only access (kernel log, dmesg//var/log/messages):

EXT4-fs warning (device nvme0n1): ext4_dx_add_entry:2412: Directory (ino: <N>) index full, reach max htree level :2
EXT4-fs warning (device nvme0n1): ext4_dx_add_entry:2416: Large directory feature is not enabled on this filesystem

This is an ext4-level directory-capacity exhaustion: without the large_dir feature, a single directory's htree index tops out at level 2, independent of overall filesystem free space/inodes. Two code issues compound this:

  1. DiskCache stores every cached object for a given path prefix flat in one directory with no sharding. pathForFile/pathForIOEntry (pkg/fileservice/disk_cache.go) build the on-disk path by concatenating the entire object-store relative path under d.path, so e.g. all query_result/* and query_result_meta/* cache entries for a CN's whole lifetime land in two single flat directories. A sustained or bursty high-churn cache (e.g. periodic jobs that save many query results) can drive one of these directories' entry/htree-block count to the ext4 ceiling well before the filesystem's actual byte or inode budget is exhausted.
  2. isDiskFull() (pkg/fileservice/error.go:188-194) only matches the string "disk quota exceeded" (EDQUOT semantics). It does not match "no space left on device" (ENOSPC), which is exactly the error os.Rename/os.CreateTemp return in this scenario. As a result, the self-healing path in writeFile (d.cache.ForceEvict(ctx, d.capacityFunc()/10), guarded by isDiskFull(err)) is never triggered for this failure mode, so the cache never attempts to shrink in response to a real ENOSPC condition. The error is otherwise swallowed as a WARN log (err = nil), so the condition can persist indefinitely with no automated mitigation.

In the observed production instance, this produced a recurring, roughly hourly burst of write disk cache error ... no space left on device warnings over at least 24h, confirmed still ongoing at the time of investigation.

Expected Behavior

  • DiskCache should not be able to drive a single directory to an OS-level per-directory capacity limit regardless of total cache byte budget — e.g. shard cache files into sub-directories (hash-prefix or similar) so entry count per directory stays bounded independent of cache capacity or filesystem feature flags.
  • isDiskFull() should also recognize ENOSPC ("no space left on device"), not just EDQUOT ("disk quota exceeded"), so the existing ForceEvict self-healing path actually engages for genuine disk-full conditions. (Note: even with this fix, eviction alone cannot resolve a directory-structure-level ENOSPC — sharding is still required — but it should at least engage for byte-budget-driven ENOSPC cases, e.g. on filesystems/paths where there's no per-directory entry-count ceiling.)

Steps to Reproduce

  1. Create (or use) an ext4 filesystem without the large_dir feature (default on many older mkfs.ext4 invocations / kernels).
  2. Point a MatrixOne CN's disk-cache path at that filesystem, with save_query_result enabled, and run a workload that repeatedly executes and saves many distinct query results, so that the DiskCache instance for the SHARED/query_result prefix accumulates a very large number of entries in a short time, with no sub-directory sharding.
  3. Observe write disk cache error ... no space left on device in the CN logs for writes targeting that single cache directory, while df/node_filesystem_avail_bytes on the node still show large amounts of free space and free inodes, and mo_fs_cache_bytes{type="inuse"} is well under type="cap".
  4. Cross-check the node's kernel log (dmesg / /var/log/messages) for ext4_dx_add_entry: ... index full, reach max htree level :2 / Large directory feature is not enabled on this filesystem at the same timestamps.
  5. Separately, confirm isDiskFull() in pkg/fileservice/error.go does not match an ENOSPC-origin error string ("no space left on device"), only "disk quota exceeded", by inspection or a unit test feeding it a *fs.PathError wrapping syscall.ENOSPC.

Additional information

  • This is distinct from [Bug]: DiskCache write failures are swallowed and emit unbounded warning logs #27363 (DiskCache write failures are swallowed and emit unbounded warning logs), which is about log-volume amplification for a different underlying failure (cache directory replaced by a regular file) and does not address the ext4 per-directory capacity mechanism or the isDiskFull()/ENOSPC gap.
  • This is distinct from fileservice: reserve disk-cache quota for temp and in-progress writes #25764 (fileservice: reserve disk-cache quota for temp and in-progress writes), which is about byte-level accounting/reservation gaps for concurrent writes, not per-directory entry-count/filesystem-structure limits.
  • This is distinct from [Bug]: disk cache write disk cache error:no space left on device #21658 (disk cache write disk cache error: no space left on device, closed), which was about leftover .tmp files accumulating in the data path, a different mechanism already fixed in that issue.
  • Evidence strength: the isDiskFull() string-matching gap and the flat (unsharded) cache path construction are directly verified by reading pkg/fileservice/error.go and pkg/fileservice/disk_cache.go on current main (commit 5a0570ea70083c9365719009a5ed8d7618f9ed91). The ext4 kernel warning is field-observed in a production deployment via read-only node log access. The exact directory entry count at failure time is analysis only, not field-observed (no write/exec access to count files on the affected node was available during the investigation).

Activity

  1. added
    severity/s2
    on Oct 14, 2026
  2. added a commit that references this issue on Oct 15, 2026
    17a6200
  3. XuPeng-SH commented on Oct 16, 2026

    @XuPeng-SH
    Contributor

    转测 @Ariznawlll。

    已在 main 提交 0723ae37b1183a03bac9eda16669dfc7e474dfb8 对关联修复 #30173 完成本 issue 对应的定向验证,所测场景通过。

    目录分片、路径兼容/删除、ENOSPC/配额错误分类、驱逐、并发生命周期测试通过,含 race。未在生产 ext4 盘上制造目录 htree 耗尽。

    测试入口:

    • TestDiskCacheCloseOwnsAsyncLoaderGeneration
    • TestDiskCacheCurrentReaderReindexesUntrackedPath
    • TestDiskCacheEvictionTransfersToCleanupOwner
    • TestDiskCacheEvictionTransfersToPlainPathOwner
    • TestDiskCachePublicationClaimWinsBeforeClose

    请在目标验收版本复核后决定关闭;本次转测保留 issue 为 OPEN。

  4. Ariznawlll commented on Nov 6, 2026

    @Ariznawlll
    Collaborator

    测试版本

    MatrixOne 官方 main 65b721e1b93c6b9e05db2063b220e0c35916b335,本地 macOS/arm64。Go 测试使用该版本 Go 源码及本机已有的 qa32048-main CGo 依赖/静态库;这是定向测试环境,不等同于重新构建发布镜像。

    原问题验证

    执行 pkg/fileservice 的目录分片、不同布局路径和 ENOSPC 分类测试;15 个选定顶层测试各重复 3 次,共 45/45 通过。其中 TestClassifyDiskFull、TestDiskCacheENOSPCWithFreeSpaceKeepsCache、TestDiskCacheENOSPCEvictsWhenFilesystemIsExhausted 覆盖了注入/模拟的 ENOSPC 和文件系统空间状态分支。

    Happy Path 覆盖

    TestDiskCacheShardIsStable、TestDiskCacheSpreadsFilesAcrossShards 验证分片稳定及分布;路径规范化、新旧布局解析、别名删除和旧布局老化测试均通过。并发缓存生命周期中的加载、删除所有权、路径重建与发布测试也覆盖 3 次。

    Unhappy Path 覆盖

    模拟有剩余空间但报 ENOSPC、文件系统字节或 inode 耗尽以及状态未知等分支,各 3 次通过。本轮没有在真实 ext4 目录中制造 htree 耗尽、配额耗尽或磁盘故障;模拟不能代替 Linux/ext4 现场。

    白盒验证

    检查 pkg/fileservice/disk_cache_shard_test.go、disk_cache_lifecycle_test.go 对分片、路径兼容、错误分类和生命周期的测试入口;本次执行的是当前 main 对应 Go 源码。race 构建因本机可用空间降至约 2.3 GiB 主动停止,本轮没有 race 通过结果。首次普通编译因缺少 CGo 头文件配置失败,配置本机依赖后重试成功,不计为产品缺陷。

    回归测试

    运行现有 pkg/fileservice 定向 Go 回归,无新增 MatrixOne 主库测试 PR。上述为 15 个顶层测试 × 3 次,不是整个 fileservice 测试包或全量 CI。

    测试证据

    日志 test30167-focused.log 含 45 个顶层 PASS、子测试及最终 Go 包结果;test30167-race.log 仅为中止构建的记录。已清理本轮独立 Go 构建缓存,未触碰其他实例数据。

    测试结论

    当前 macOS 定向单元测试通过;真实 Linux/ext4 目录耗尽及本轮 race 尚未验收,保持 Open,不作为完整通过。

  5. Ariznawlll commented on Nov 29, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。本轮补齐此前缺失的 Linux 真实 ext4 目录 htree 耗尽及定向 race 验收。确认目录有剩余字节和 inode 时仍可发生真实 ENOSPC,而修复后的生产 DiskCache 分片路径可继续写入并逐项精确读回;不是用模拟 ENOSPC 代替文件系统故障。

    关键证据

    版本、分支与回归

    • 本次 Linux 实测官方 main:922815d74fe664dc9f4ea7bfc4c4e8ac3b279cd0,包含关联修复 fix(fileservice): shard disk cache directories and classify ENOSPC correctly #30173,merge 17a6200f59e764729e5544908fffd5480ae88279。
    • 专项 CI 46294476882 已完成 SUCCESS。核对附件 mo-sha、文件系统信息、内核日志、真实读写结果和 race 原始输出。
    • 回归在现有 MOTR main PR #374:.github/qa/issue_30167_ext4_test.go 与 qa-diskcache-ext4.yml。本次证据绑定 MOTR commit 3c19635d98081f53fb5a189efc3eeb57f8c57a81;后续追加其他用例未改变此专项。本次没有向 MatrixOne 主库提测试 PR。
    • 此处直接执行该官方源码的生产 DiskCache,并通过 test-only overlay 增加验收入口;不是声称执行了完整 CN 的 24 小时业务负载。没有产品实现替换,也没有在生产磁盘上制造故障。

    1. 建立真实 ext4 故障前提

    专用 2 GiB loop ext4 文件系统,block size=1024、inode count=499712,启用 dir_index、未启用 large_dir。小 block 和长合法文件名用于缩短达到相同 htree 层级上限的时间;不是硬盘容量耗尽。

    在旧布局对照目录持续创建平铺文件,实际第 29,489 项后的 rename 返回:

    rename .../rename-source .../legacy-flat/fullobj-00029489-....mofscache:
    no space left on device
    available_bytes_at_failure = 1876326400
    free_inodes_at_failure = 470208
    

    内核日志同时报告目录索引满、达到 htree level 2,以及 large_dir 未启用。保留原始 kernel.log 和 filesystem.txt。该步只复现旧平铺目录的文件系统机制,并非运行旧版完整 MO。

    2. 修复后生产缓存写读对照

    在同一文件系统、保留已耗尽旧目录的条件下,调用当前生产 DiskCache 写入和读取。实际结果:

    检查 实际结果
    成功分片写入 58,979
    精确内容读回 58,979
    实际使用分片 4,096
    最大单分片条目数 27
    最终状态 PASS

    另外调用20次 evictForDiskFull 处理该“仍有空间的目录结构 ENOSPC”,确认不会误清掉健康缓存;之后全部条目仍可精确读取。最后再次向旧目录 rename,仍为 ENOSPC,排除因旧目录被清空或故障自然消失而得到假通过。整个真实文件系统测试耗时约96.31秒。

    3. 错误分类、驱逐、兼容及并发生命周期

    19个既有顶层测试各3次,race 57/57 PASS,0 FAIL、0 SKIP、无 DATA RACE。包括:

    • 分片稳定性与分布、路径规范化、别名/S3别名删除、新旧布局解析、旧布局老化。
    • 有剩余空间的 ENOSPC 保留缓存;字节/inode真正耗尽触发驱逐;EDQUOT触发驱逐;源数据错误不误驱逐;并发磁盘满失败只触发一次驱逐。
    • eviction/cleanup所有权交接、未跟踪路径重建、Close与异步loader代际、发布claim与关闭并发。

    此前本地 race 构建因磁盘不足中止的记录不计为通过;本次上述57次来自已完成的Linux CI。前一个独立Linux真实ext4 run 46289521447也通过,但目录极限受哈希分布影响,条目数不同,未将两个run的结果混写。

    待解决点

    本 Issue 的目录结构 ENOSPC 和对应错误处理/生命周期验收缺口已补齐,无已执行的未通过项。生产现场24小时业务负载、其他文件系统、完整 fileservice 包性能与全套发布验收未在本专项重跑;这些不作为本次已通过次数或覆盖范围。

    回归已提交现有 MOTR PR,按既有授权在等待 PR 合入期间先关闭;不宣称调度已在默认分支生效,也不推断4.2发布线自动获得本次main验收。

    最终结论:测试通过。真实 Linux/ext4 目录耗尽、58,979次生产缓存写读及57次定向race均通过;未通过项:无。本次关闭 #30167,验收范围限定上述 main 修订与场景。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions