mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #3034] [RFC]: Collision-safe file-per-key paths and legacy migration #778
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#778
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @feichai0017 on GitHub (Jul 21, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/3034
Changes proposed
This RFC extends the fix for #2980 and the implementation in #2984. The current file-per-key path uses a sanitized raw key as its filename, so different keys can alias after sanitization or path normalization, and long keys can exceed filesystem filename limits. Backward-compatible migration must also preserve eviction, accounting, and recovery invariants, so the implementation exceeds 500 non-test lines.
Design
ResolvePathFromKey()retains the existing sanitized-key layout because master replica metadata stores those paths. Only the file-per-key backend usesResolveFilePerKeyPathFromKey().ENAMETOOLONG, or./..resolving to a directory) are treated as absent; other filesystem errors fail closed..stagingdirectory and committed with a same-filesystem rename. Canonical and legacy paths are protected from quota and watermark eviction for the transaction. A matching legacy file is removed only after validation; path locks, FIFO records, and used-space accounting are updated together.ScanMeta()accepts only the observed canonical or validated legacy layout, rejects symlinks and unexpected entries, and leaves recovery gated after traversal, status, decoding, callback, or cleanup failure.Implementation split and merge order
ScanMeta()state machine, strict traversal/path binding, exact configuredfsdir, and atomic recovery reconciliation.Ordering and failure contract
After the staged write is complete and closed, a successful same-filesystem
rename()makes the canonical entry namespace-visible before the matching legacy shadow is unlinked. This is a namespace-ordering guarantee, not anfsync-backed power-loss durability guarantee.Compatibility and operational behavior
ScanMeta()..stagingnamespace is owned by the file-per-key backend and is cleaned after an interrupted write.ScanMeta()callbacks must not synchronously re-enter adaptor mutation or watermark-eviction APIs while the exclusive recovery lock is held.Alternatives considered
./..normalization remain problematic.Validation
Exact Ubuntu head
1714b3d88bccae1b1ffbac5bf31d384e512766fapasses:storage_backend_test: 110/110master_service_ssd_test: 18/18utils_test: 20/20file_storage_test: 23/23client_storage_backend_test: 3/3Coverage includes constructed legacy-path collisions, long and dot keys, canonical/legacy traversal, malformed and unexpected entries, callback failure and full retry, crash staging cleanup, legacy-shadow retirement, FIFO/space transfer, tight-quota rollback, exact
fsdirhandling, and unchanged master DISK descriptor paths.Out of scope
This RFC does not claim hostile-filesystem containment, protection against ancestor symlink/hard-link/TOCTOU mutation, or a reliable tenant-scoped
RemoveAllacknowledgement protocol. Those authority and cleanup concerns are tracked in #3231.Related: #2980, #2982, #2984, #2987, #3231
Before submitting a new issue...
@github-actions[bot] commented on GitHub (Jul 21, 2026):
Thanks for opening this issue, @feichai0017!
132118805A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide
@feichai0017 commented on GitHub (Aug 2, 2026):
@he-yufeng, I updated the RFC to make the ordering boundary explicit: the staged canonical file is closed and renamed into place before a validated legacy shadow is unlinked. This guarantees namespace ordering, not
fsync-backed power-loss durability.The RFC now also documents the failure matrix and the implementation split: #2987 provides fail-closed scan/reconciliation, while #2984 layers digest paths and legacy migration on top.
Could you confirm whether this direction and the proposed merge order (#2987 first, then #2984) match what you had in mind?