Repository navigation
Conversation
…s on write failure Two gaps in BatchOffload's handling of a bucket's on-disk footprint. Admission reserved nothing for the .meta file. BatchOffload admits a bucket with PrepareEviction(file_bytes + bucket->meta_size), but meta_size was only set by StoreBucketMetadata after the write, so it was 0 at admission. PrepareEviction checked max_total_size, max_physical_bytes and the free space floor as if the bucket had no metadata, while the commit then added the metadata to total_size: an admitted bucket could overshoot both caps by the size of its .meta (tens of KiB for a full bucket of 500 keys). BatchOffload now encodes the metadata once, before admission, sets meta_size from it so that PrepareEviction reserves the real size, and passes those same bytes to StoreBucketMetadata, which no longer needs the bucket. A failed write could leave the bucket's data file behind. WriteBucket relies on the file to unlink itself when a write fails, which PosixFile does for FILE_WRITE_FAIL. The packed direct write path with io_uring does not: UringFile::write_aligned returns the ring's error without recording it, and that branch's size-mismatch and staging-buffer allocation failures return without touching the file either. Nothing indexes the partial file, so eviction never reclaims it, and it counts against max_physical_bytes until the next start removes it as an orphan. BatchOffload now calls CleanupOrphanedBucket for the bucket id when the write fails, before it releases the reservation. The id is not shared and the bucket was never committed, so this cannot touch another bucket or a pending registration, and a file the failed write already removed is skipped. Tests: - StorageBackendTest.BucketAdmissionReservesMetadataSize: the footprint is taken from a first offload with room to spare; a quota of footprint - 1 or a physical cap of footprint - 1 rejects the bucket, a quota of exactly footprint admits it. - StorageBackendTest.UringPackedBucketWriteFailureRemovesPartialFile (USE_URING; skipped without io_uring): a packed direct write cut short by RLIMIT_FSIZE leaves no file and no reservation behind. - StorageBackendTest.BucketWriteFailureRemovesPartialFiles: the same on the buffered path, with the data file and then the .meta file cut short. That path already cleaned up; the test keeps the extra cleanup harmless there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Zhewen Li <zhewenli@inferact.ai>
zhewenl
requested review from
Aionw,
XucSh,
YiXR,
stmatengss and
ykwd
as code owners
November 25, 2026 04:03
Contributor
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes two gaps in how
BucketStorageBackend::BatchOffloadaccounts for and cleans up a bucket's files.1. Admission does not reserve the
.metafile.BatchOffloadadmits a bucket withPrepareEviction(file_bytes + bucket->meta_size, ...).meta_sizeis only set byStoreBucketMetadata, which runs after the data write, so at admission it is still 0:PrepareEvictionchecks the incoming bucket againstmax_total_size,max_physical_bytesand the free-space floor (required_size + 256 MiB) as if the bucket had no metadata.total_size(committed_data_sizestarts atbucket->meta_size), and the.metafile takes real disk blocks.So after each admission,
total_sizeand the bytes on disk can exceed the caps by that bucket's.metasize: with the defaultbucket_keys_limitof 500 and keys of ~100 bytes, about 50 KiB. Onmainthe offload runs on the store's single heartbeat thread, one bucket at a time, so the overshoot is at most one.metaper disk at a time; it does not accumulate, because the next admission sees the committed size. It grows with the number of buckets in flight if parallel bucket writes (#5339) land.max_physical_bytesis meant to be a hard cap that keeps the store within its disk quota (cgroup / emptyDir), so it should hold exactly.2. A failed packed io_uring write leaves its data file behind.
WriteBucketrelies on the file object to unlink itself when a write fails:PosixFiledoes this when the write fails withFILE_WRITE_FAIL(delete_on_write_fail_). The packed direct write path with io_uring (use_uring+MOONCAKE_OFFLOAD_BUCKET_DIRECT_WRITE=packed) goes throughUringFile::write_aligned, which returns the ring's error without recording it (make_erroris not called), so the file is not unlinked. The size-mismatch and staging-buffer allocation failures on that branch also return without removing the file.BatchOffload's failure branch then only releases the reservation, and never callsCleanupOrphanedBucket. Nothing indexes the partial file, so eviction never reclaims it, and it counts againstmax_physical_bytesuntil the next start, whenInitremoves it as an orphan. A review probe reproduced this onmain: withuse_uring=true,packed,RLIMIT_FSIZE= 128 KiB and a ~512 KiB bucket, the write fails withEFBIGand<id>.bucket(131072 bytes) stays in the directory. The buffered path with the same limit leaves nothing (posix_file.cpp: Deleted corrupted file).Fix.
BuildBucketand before admission. Setmeta_sizefrom the encoded length so thatPrepareEvictionreserves the real size, and pass the same bytes throughWriteBuckettoStoreBucketMetadata, so the reserved size and the written size always match.meta_sizeis not serialized (YLT_REFL(BucketMetadata, data_size, keys, metadatas)), so setting it does not change the encoding.StoreBucketMetadatano longer needs the bucket, so it takes only the id, the disk and the encoded bytes.WriteBucketfails,BatchOffloadcallsCleanupOrphanedBucket(bucket_id, disk_index)before releasing the reservation, so the space stays reserved until the files are gone. This is safe on every failure path: the bucket id is unique to this call, and the bucket was never committed tobuckets_orobject_bucket_map_, so no reader, eviction or pending registration ([Bugfix][Store] Protect pending bucket registrations during concurrent offload #5337'soffload_notification_pending_is only set on committed buckets) can refer to it. On the paths that already unlinked their files (buffered writes, datasync and.metafailures),CleanupOrphanedBucketfinds nothing and ignoresENOENT. The commit-time failures after the write already clean up (CleanupOrphanedBucketfor an all-duplicate bucket,RollbackCommittedBucketwhen the completion handler fails).Related open PRs.
StoreBucketMetadatato write a temp file, fsync it and rename it. The two overlap in one hunk, the write section ofStoreBucketMetadata. When both land, [Store] Add V6 object write generations, SSD task fencing, and HA durable retirement #5791's version should write theserialized_metapassed in rather than encode*metadataagain (itsto_pbcall refers to the parameter this PR removes), so the reserved and written sizes keep matching.Suggested Merge Priority
Module
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
How Has This Been Tested?
New tests:
StorageBackendTest.BucketAdmissionReservesMetadataSizeoffloads one 64-key bucket (long keys, one-byte values, so the.metais a large part of it). A first offload into an empty backend with room to spare gives the footprint: the committedtotal_size, which equals the sizes of the.bucketand.metafiles. Then, each in a fresh backend:max_total_size = footprint - 1: must be rejected, with no files and nothing committed.max_total_size = footprint: must be admitted, withtotal_size == footprint. This shows the reservation is exactly the metadata size, not more.max_physical_bytes = footprint - 1: must be rejected.StorageBackendTest.UringPackedBucketWriteFailureRemovesPartialFile(built withUSE_URING; skipped if io_uring cannot be initialized or the packed path does not work on the test filesystem): the review probe as a regression test. A packed io_uring write of a 512 KiB bucket cut short byRLIMIT_FSIZE= 128 KiB must fail, leave no file and no committed size, and the same batch must go through once the limit is lifted (the reservation was released).StorageBackendTest.BucketWriteFailureRemovesPartialFiles: the same on the buffered path, with the data file and then the.metafile cut short.mainalready passes it; it checks that the new cleanup is harmless where the file was already removed.Test commands:
Before (this branch with the
meta_sizeassignment moved back after the write, as onmain, and the newCleanupOrphanedBucketcall removed): both "short" cases are admitted and overshoot the cap, and the failed packed write leaves its file.After:
Test results:
Results on this branch (aarch64, Linux 6.17 with 64 KiB pages,
USE_CUDA=OFF, io_uring available):storage_backend_test --gtest_filter='-*OffsetAllocatorReadPath*': 144/144 passed, including the three new tests (the uring one ran, not skipped).file_storage_test(67 passed, 1 skipped:UringStagingBufferUnpinnedOnDestruction, environment),bucket_direct_write_test(60/60),local_ssd_test,file_storage_config_test: passed.ctest --test-dir build/mooncake-store --parallel 8: 235/237 passed. The two failures fail identically on unmodifiedmainon this host and are environmental:storage_backend_testaborts inOffsetAllocatorReadPath_*: the test's guard page uses a 4 KiBmprotecton a 64 KiB-page kernel, so it throwsbad_alloc.transfer_task_testfails inBatchGetOffloadObjectCopiesPinnedHostToGpu: there is no pinned host buffer in a CPU-only build.Revert check: as shown under "Before",
BucketAdmissionReservesMetadataSizeandUringPackedBucketWriteFailureRemovesPartialFilefail without the fix;BucketWriteFailureRemovesPartialFilespasses either way.Checklist
Signed-off-bytrailer certifying the DCO./scripts/code_format.shAI Assistance Disclosure
Claude Code (Claude Opus 5.5) ported the reservation fix from our fork to
main, turned an io_uring write-failure probe into a regression test and added the cleanup, confirmed that the new tests fail before the fix, and ran the test suites.🤖 Generated with Claude Code