Repository navigation
Description
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_dirfeature not enabled - OS type: Linux (production Kubernetes node, ext4 local volume)
- Others:
analysis only, not field-observedfor 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 belowtype="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:
DiskCachestores 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 underd.path, so e.g. allquery_result/*andquery_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.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 erroros.Rename/os.CreateTempreturn in this scenario. As a result, the self-healing path inwriteFile(d.cache.ForceEvict(ctx, d.capacityFunc()/10), guarded byisDiskFull(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
DiskCacheshould 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 recognizeENOSPC("no space left on device"), not justEDQUOT("disk quota exceeded"), so the existingForceEvictself-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
- Create (or use) an ext4 filesystem without the
large_dirfeature (default on many oldermkfs.ext4invocations / kernels). - Point a MatrixOne CN's
disk-cachepath at that filesystem, withsave_query_resultenabled, and run a workload that repeatedly executes and saves many distinct query results, so that theDiskCacheinstance for theSHARED/query_resultprefix accumulates a very large number of entries in a short time, with no sub-directory sharding. - Observe
write disk cache error ... no space left on devicein the CN logs for writes targeting that single cache directory, whiledf/node_filesystem_avail_byteson the node still show large amounts of free space and free inodes, andmo_fs_cache_bytes{type="inuse"}is well undertype="cap". - Cross-check the node's kernel log (
dmesg//var/log/messages) forext4_dx_add_entry: ... index full, reach max htree level :2/Large directory feature is not enabled on this filesystemat the same timestamps. - Separately, confirm
isDiskFull()inpkg/fileservice/error.godoes not match anENOSPC-origin error string ("no space left on device"), only"disk quota exceeded", by inspection or a unit test feeding it a*fs.PathErrorwrappingsyscall.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
.tmpfiles 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 readingpkg/fileservice/error.goandpkg/fileservice/disk_cache.goon currentmain(commit5a0570ea70083c9365719009a5ed8d7618f9ed91). 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 isanalysis only, not field-observed(no write/exec access to count files on the affected node was available during the investigation).
Activity
fix(fileservice): shard disk cache directories and classify ENOSPC co…
XuPeng-SH commentedon Oct 16, 2026
转测 @Ariznawlll。
已在 main 提交
0723ae37b1183a03bac9eda16669dfc7e474dfb8对关联修复 #30173 完成本 issue 对应的定向验证,所测场景通过。目录分片、路径兼容/删除、ENOSPC/配额错误分类、驱逐、并发生命周期测试通过,含 race。未在生产 ext4 盘上制造目录 htree 耗尽。
测试入口:
TestDiskCacheCloseOwnsAsyncLoaderGenerationTestDiskCacheCurrentReaderReindexesUntrackedPathTestDiskCacheEvictionTransfersToCleanupOwnerTestDiskCacheEvictionTransfersToPlainPathOwnerTestDiskCachePublicationClaimWinsBeforeClose请在目标验收版本复核后决定关闭;本次转测保留 issue 为 OPEN。
Ariznawlll commentedon Nov 6, 2026
测试版本
MatrixOne 官方 main
65b721e1b93c6b9e05db2063b220e0c35916b335,本地 macOS/arm64。Go 测试使用该版本 Go 源码及本机已有的qa32048-mainCGo 依赖/静态库;这是定向测试环境,不等同于重新构建发布镜像。原问题验证
执行
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,不作为完整通过。
Ariznawlll commentedon Nov 29, 2026
结论
测试通过。本轮补齐此前缺失的 Linux 真实 ext4 目录 htree 耗尽及定向 race 验收。确认目录有剩余字节和 inode 时仍可发生真实 ENOSPC,而修复后的生产 DiskCache 分片路径可继续写入并逐项精确读回;不是用模拟 ENOSPC 代替文件系统故障。
关键证据
版本、分支与回归
922815d74fe664dc9f4ea7bfc4c4e8ac3b279cd0,包含关联修复 fix(fileservice): shard disk cache directories and classify ENOSPC correctly #30173,merge17a6200f59e764729e5544908fffd5480ae88279。mo-sha、文件系统信息、内核日志、真实读写结果和 race 原始输出。.github/qa/issue_30167_ext4_test.go与qa-diskcache-ext4.yml。本次证据绑定 MOTR commit3c19635d98081f53fb5a189efc3eeb57f8c57a81;后续追加其他用例未改变此专项。本次没有向 MatrixOne 主库提测试 PR。1. 建立真实 ext4 故障前提
专用 2 GiB loop ext4 文件系统,block size=1024、inode count=499712,启用
dir_index、未启用large_dir。小 block 和长合法文件名用于缩短达到相同 htree 层级上限的时间;不是硬盘容量耗尽。在旧布局对照目录持续创建平铺文件,实际第 29,489 项后的 rename 返回:
内核日志同时报告目录索引满、达到 htree level 2,以及
large_dir未启用。保留原始 kernel.log 和 filesystem.txt。该步只复现旧平铺目录的文件系统机制,并非运行旧版完整 MO。2. 修复后生产缓存写读对照
在同一文件系统、保留已耗尽旧目录的条件下,调用当前生产 DiskCache 写入和读取。实际结果:
另外调用20次
evictForDiskFull处理该“仍有空间的目录结构 ENOSPC”,确认不会误清掉健康缓存;之后全部条目仍可精确读取。最后再次向旧目录 rename,仍为 ENOSPC,排除因旧目录被清空或故障自然消失而得到假通过。整个真实文件系统测试耗时约96.31秒。3. 错误分类、驱逐、兼容及并发生命周期
19个既有顶层测试各3次,race 57/57 PASS,0 FAIL、0 SKIP、无 DATA RACE。包括:
此前本地 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 修订与场景。