Repository navigation
[Store] Fence the local disk tier on the first unrecoverable disk error - #4490
Conversation
A dead offload disk today keeps being used: every failed read or write returns a FILE_* error code that cannot tell a dead device from a short write or a full disk, the errno is dropped, and the heartbeat keeps taking offload work and re-mounting the LOCAL_DISK segment. Keep the errno and decide at the first failure: - StorageFile records the errno of its first failed syscall (sys_errno()); PosixFile sets it for write/pwritev/read/preadv/ fdatasync. Short reads and writes stay logical (errno 0). - StorageBackendInterface gains SetDiskErrorObserver (default no-op). BucketStorageBackend reports open/pwritev/fdatasync/write/read/preadv failures with their errno. - FileStorage classifies the errno inline on the failing thread: ENODEV/ENXIO/EROFS/ESHUTDOWN fence; EIO and the block-layer and corruption errnos run one filesystem check (syncfs to force the XFS log, then fstat on a held offload-dir fd, which fails with EIO exactly when XFS is shut down) and fence only if it fails; everything else (ENOSPC, ENOENT, ...) is ignored. No counters or time windows. - A fence is latched for the process lifetime: reads short-circuit and offload stops at once; the heartbeat (woken immediately) disables offloading and unmounts the segment through the drain latch. - The drain latch is no longer reset when the unmount RPC fails. While draining, each heartbeat retries the unmount until the master acknowledges it (the master treats an already-unmounted segment as success) and never re-mounts. - New gauge mooncake_ssd_disk_fenced (0/1).
|
End-to-end results on a rig (master + 3 stores on loop/device-mapper disks with XFS, RDMA, paced writers and readers; faults injected on store
In every fence case:
Two notes:
|
Follow-up to the disk fence, from review: - ApplyDiskFence now sends one OffloadObjectHeartbeat with offloading disabled before the unmount (skipped if a drain already unmounted). The unmount drops the master's offload queue for this store but not the source-replica references its tasks hold, so those memory replicas stayed pinned until the master's TTL reaper (600 s). The heartbeat makes the master release them and stop enqueuing; it is best effort. - The filesystem check runs syncfs only after a write-path failure (pwritev, fdatasync, write, open). A failed read leaves the log nothing to write (read failures alone never shut XFS down on the rig), and one bad file otherwise caused a whole-filesystem flush on every failed read. Read failures check with fstat only. - If the offload dir fd could not be opened, the check falls back to stat on the path instead of silently never fencing. - mooncake_ssd_disk_fenced is set to 0 at construction, so the series exists before a fence. - The unmount retry logs failures at WARNING; the vector_read and vector_write failure logs carry the errno; disk_error_not_fenced names the check that ran (fstat or syncfs+fstat). Tests: the fenced scenarios now queue a real offload task and check that the master released it (Upsert succeeds) instead of checking a local flag; the fenced OffloadObjects assertion uses a key with a memory replica, so it fails without the fence; read failures are checked without syncfs and write failures with it; the gauge is exported before any failure.
|
Pushed a follow-up commit, 75fe664, from an internal review:
|
he-yufeng
left a comment
There was a problem hiding this comment.
Read the full diff against main and walked the new paths. The design holds up, and the test matrix is unusually complete: dead-fs fences, live-fs control, ENOSPC/ENODEV boundaries, concurrent-check dedup, drain retry, fenced offload never reaching the backend.
What I verified on the mechanism side:
- Errno really is dropped on main today. The
StorageFile::record_sys_errnoplumbing covers every PosixFile failure point, andOpenFilereporting"open"closes the FILE_OPEN_FAIL case from the incident. - The fence abort in
OffloadObjectscomposes with the existing sweep correctly: buckets after the break never enterall_bucket_keys, so the end-of-cycle sweep pushes their tasks tofailed_tasksandNotifyOffloadSuccessreleases them together with their source replica refs. No task is stranded. UnmountLocalDiskIfPending's retry is safe against the master:master_service.cpp:8527returns success for an unregistered client, so a first response that was lost followed by a retry is benign.- The heartbeat wake (state change under
heartbeat_wake_mutex_, thennotify_all, predicate re-checked inwait_for) cannot lose a wakeup. ApplyDiskFencereleasing the queued offload tasks viaOffloadObjectHeartbeat(false)before the unmount is the right order: the unmount sweep alone would leave those tasks pinning their memory replicas until the TTL reaper.
Two things to address, the first one real:
-
The io_uring build never fences.
UringFilehas norecord_sys_errno(uring_file.cpp is untouched), andWriteBucket'swrite_alignedfailure returns before the datasync step that carries that path's onlyNotifyDiskError. The BatchLoad read leg likewise reports nothing whenOpenFileyields an UringFile. So under USE_URING a dead device is silent on every leg except a failed fdatasync after a successful write. If posix-only coverage is the intended scope here, please say so in the description and file the uring half as a follow-up; otherwise UringFile needs the same errno plumbing plus a notify on thewrite_alignedfailure. -
The drain contract from #3316 changes here: on main, a failed
UnmountLocalDiskSegmentRPC unlatchesdraining_and the store resumes; with this PR the latch stays and the heartbeat retries until the master acks. Fail-closed is the right call andDrainUnmountFailureKeepsLatchAndRetriespins it, but it is a shipped-behavior change beyond fencing, so it deserves a line in the PR description for whoever owns that path.
One small question, not a blocker: CheckFilesystem runs syncfs inline on the failing I/O thread. On dm-error that fails fast, as you measured; on a device that errors the triggering syscall quickly but wedges writeback, syncfs could park that thread for a while. That thread is already doomed in that world, so I would not gate on it, but a comment stating the assumption would save the next reader a wonder.
Overall the right shape: judge each failure once, fail closed, and reuse the drain path instead of inventing a second deregistration.
PosixFile::vector_write treated a short pwritev as a failure with no errno. When an XFS shutdown landed in the middle of a bucket write, the kernel returned a partial count, errno stayed 0, and the disk fence classified the failure as logical: it fenced only on the next disk access, 9.7 s later in a production drill. vector_read had the same shape (a buffered read over a bad block comes back short, no errno). A short count is not an error. Both functions now continue with the remaining bytes at the advanced offset (on a copy of the caller's iovecs), retry EINTR, and record errno from the call that really fails, which on a dead disk is EIO. vector_write fails without errno only on a 0-byte return, so it cannot loop forever. vector_read still returns a short count, but now only at EOF, so callers' size checks are unchanged.
With use_uring, the disk fence saw nothing from io_uring: UringFile kept no errno, and the BatchLoad read leg and the WriteBucket write_aligned leg reported no failure to the observer. - The ring records the errno of the first failed CQE of each call (-cqe->res); UringFile keeps it as sys_errno() after a failed call, as PosixFile does for a failed syscall. - A short completion is continued, as pwritev/preadv now are: io_uring completes a read or write short, without the errno, when it fails after moving some bytes. Chunked and vector reads/writes and batch_read track each SQE's result and submit the rest of a short one. A read ends at EOF (0 bytes, or a stop off a 4 KiB boundary, where an O_DIRECT read could not resume). - BatchLoad's io_uring read failure reports "read" and WriteBucket's write_aligned failure reports "write" to the disk-error observer. LoadBucketMetadata already reported its read; it now has the errno. (BucketStorageBackend opens bucket files for writing as PosixFile even with use_uring, so its writes already reported pwritev.) Error codes returned by the ring are unchanged.
|
Thanks for the careful read. All three points are addressed in new commits on top of 75fe664 (head is now 4ab8d5c); each new test fails on 75fe664.
One more fix from a production fire drill — 8e7acd4. An XFS shutdown in the middle of a bucket write first showed up as a short
Unit suites: 247/247. |
Review fixes for the short I/O and io_uring errno commits. - The iovec helpers that continue a short pwritev/preadv move to src/iovec_cursor.h (mooncake::detail) and get direct tests: a stop inside an iovec, at a boundary, across several boundaries, and empty iovecs, plus a fake-pwritev loop over every short count. The kernel test that stops inside the second iovec could not see where the continuation resumed (it writes nothing at the limit), so it is renamed to what it checks: the real errno and unchanged caller iovecs. PosixFile's loop is unchanged. - io_uring: a short completion is continued in a loop of single SQEs instead of recursing through submit_rw. Each call resets the CQE errno before the ring check, so a call on a ring that failed to reinitialize does not inherit the previous call's errno. - Tests: the vector_read EBADF check uses a new file (the first errno wins, so it could not fail); batch_read and vector_read short completions are covered; the page-size and io_uring RLIMIT_FSIZE tests skip where their premise does not hold; a stale comment is corrected.
|
Pushed ad3dc7d (review follow-up, no behavior change on the posix path):
|
typos reads 'wronly' as a misspelling of 'wrongly' and fails CI. Rename the write-only descriptors in posix_file_test to write_only*, and drop an internal scenario label from a file_storage_test comment.
The comment said syncfs runs only for write-path failures, but the code skips it only for reads (preadv, read); open, which may be creating a file, still syncs. Describe what the code does.
Add a troubleshooting entry for action=disk_fence: which errnos fence, what a fence stops, the mooncake_ssd_disk_fenced gauge, that it lasts until restart, and that only bucket_storage_backend reports disk errors.
|
Pushed bdb8c54:
Merged with current main, the branch passes the same 9 suites, 252/252. @ykwd @Aionw would you have time to take a look? No code owner has reviewed yet. |
# Conflicts: # mooncake-store/include/file_storage.h # mooncake-store/tests/file_storage_test.cpp
A failure that found a filesystem check running returned without a check of its own. If a read failure's fstat-only check was running when a write failed, the write's syncfs never ran: XFS was still up, fstat passed, and neither failure fenced, although syncfs could have forced the failing log write that shuts XFS down. Now such a failure is queued, and the thread running the check checks it next. Queued failures share one check, which runs syncfs if any of them needs it. The checking slot is released under the same lock that queues, so no failure is left behind.
kvcache-ai#3006 (merged from main) keeps the tasks of keys the bucket backend deferred to its ungrouped pool, and consumes them on the next offload cycle. A fenced store runs no further cycle, the master's queue no longer holds those tasks, and the unmount does not release them, so their memory replicas stayed pinned until the master's TTL reaper. ApplyDiskFence now NACKs them after handing back the queued work, and clears the pool, the same way the key-count limit does when it stops offloading.
DiskFenceQueuedCheckReleasesTheCheckingSlot used private FileStorage members in its TEST_F body. FileStorageTest is a friend, but a TEST_F body is a subclass of the fixture and friendship is not inherited, so the test did not compile. Go through static helpers on the fixture, as IsDraining does.
|
Pushed
Verification on the merged branch (amd64 container): the nine suites in the description pass, except 7 io_uring tests from |
…al deferral Replaces the carried-task release of c2263fa with the version that has run on our fork since kvcache-ai#3006 was backported there: - NackCarriedOffloadTasks() runs before the queue hand-back, and clears the ungrouped pool even when no task is carried. - The OffloadObjects fence abort comment says that carried keys stay carried until that NACK. - DiskFenceNacksCarriedOffloadTasks defers a real key to the pool (bucket limit 2, one key) before the fence, instead of planting a task in the carry map, and checks that the task is released and that the carry map and the pool are empty.
|
Pushed
On a real kernel the nine suites in the description pass, 267/267. |
|
CI note on |
# Conflicts: # mooncake-store/include/file_storage.h # mooncake-store/src/file_storage.cpp
|
Merged current @fcczzz @ykwd when you have time, could you take another look? |
# Conflicts: # mooncake-store/tests/file_storage_test.cpp
kvcache-ai#4988 (merged from main) added FileStorage::BatchLoadSpans, a second disk read path next to BatchLoad. Its failures already reach the fence (both go through BucketStorageBackend::ReadBucketValues, which reports the errno), but after a fence it still read the dead disk, while BatchLoad fails at once. Fail it the same way.
|
Thanks for the approval, @fcczzz. Merged current @ykwd could you take a look as a |
ykwd
left a comment
There was a problem hiding this comment.
LGTM. Could you resolve the conflicts?
# Conflicts: # mooncake-store/include/storage_backend.h # mooncake-store/src/file_storage.cpp # mooncake-store/src/uring_file.cpp # mooncake-store/tests/posix_file_test.cpp # mooncake-store/tests/storage_backend_test.cpp
…isks kvcache-ai#4231 (merged from main) lets storage_filepath list several disk roots. The filesystem check opened and stat-ed storage_filepath as one directory, so with "a,b" it got ENOENT, which never fences: a dead disk went unfenced. The client now holds one directory fd per root (ResolveOffloadDiskPaths) and the check runs syncfs (for write failures) and fstat on each, with a stat fallback for a root whose fd did not open. A failure does not say which disk it came from, and the master has one LOCAL_DISK segment per client, so any dead root fences the whole disk tier. An errno that does not mean a dead filesystem (ENOENT on a missing root) no longer hides one that does on another root. Test: two live roots get one fd each and the real check passes; with the list stat-ed as one path it returns ENOENT. Docs: one dead disk fences the whole SSD tier.
|
@ykwd thanks, conflicts resolved: merged
Built and tested in an amd64 container: everything in the description's suites passes except 8 io_uring tests that cannot create a ring there ( |
* upstream/main: (28 commits) [Store] Remove unreachable dead code in reserved OpLog paths (kvcache-ai#5043) [Store][BUGFIX]: Avoid repeated NoF cleanup for unregistered buffers (kvcache-ai#5301) [Store] Fence the local disk tier on the first unrecoverable disk error (kvcache-ai#4490) [Store] Add opt-in aligned O_DIRECT bucket writes (kvcache-ai#4820) [Store] posix support Read DFS replicas straight into host buffers (kvcache-ai#5201) [TENT] Pipeline RDMA slice preparation with worker posting (kvcache-ai#5277) [TE] HipTransport: submit copies asynchronously, one stream and event per device (kvcache-ai#4953) [Misc] Add staryxchen as a HIP transport code owner (kvcache-ai#5351) [Doc] nvlink_intra works over PCIe P2P, not only NVLink (kvcache-ai#5266) [Bugfix][TENT] Propagate io_uring staging copy failures (kvcache-ai#5335) [Bugfix][TENT] Make UB batch submission all-or-nothing (kvcache-ai#5274) Add store rs tone tests (kvcache-ai#5282) [EP] Validate XPU Buffer constructor arguments (kvcache-ai#5329) [EP] Decouple PG builds and add TCPStore bootstrap (kvcache-ai#5312) [Bugfix][PG] Serialize RPC socket operations and drain shutdown (kvcache-ai#5098) [EP] Enable the native XPU EP over RDMA (kvcache-ai#5207) [Store] Use the AWS default credential chain when S3 static keys are unset (kvcache-ai#5303) [Bugfix][Store] Register dummy query RPC handlers in mooncake_client (kvcache-ai#5200) [Store] Preserve variadic RPC compatible fields with NDEBUG (kvcache-ai#5269) [TransferEngine] Avoid false CQ timeout diagnostics after idle periods (kvcache-ai#5281) ...
Description
Problem. When the SSD offload disk dies, the store keeps using it. Every disk failure is reduced to
FILE_OPEN_FAIL/FILE_READ_FAIL/FILE_WRITE_FAILand the errno is dropped, so the store cannot tell a dead device from a full disk or one bad file. Writes fail again on every offload cycle, reads keep failing on every request, and the master keeps handing out the dead disk replicas. In our production incident one NVMe failure (XFS shut down after a log I/O error) causedFILE_OPEN_FAILfor every reader of that store's disk replicas for 52 minutes, until someone drained it by hand.Fix. Keep the errno and decide at the first failure whether retrying can ever help. If it cannot, fence this store's disk tier only.
ENODEV,ENXIO,EROFS,ESHUTDOWNEIO(and block-layer / corruption errnos)ENOSPC,ENOENT, ...)Both I/O paths keep the errno:
PosixFilefrom the first failed syscall,UringFilefrom the first failed io_uring completion. A short read or write (pwritev/preadvor an io_uring completion) is not treated as a failure: the rest is submitted again, so the errno comes from the call that really fails. (Found in a production fire drill: an XFS shutdown in the middle of a bucket write first showed up as a shortpwritevwith no errno, and the fence waited 9.7 s for the next disk access.)The filesystem check is
syncfs()followed byfstat()on a directory fd held open since start-up. We measured this on a 6.8 kernel with XFS on device-mapper (dm-error, XFS shutdown, one bad block under one file, ENOSPC, a 6-leg stripe with one dead leg):EIOusually arrives while XFS is still up.syncfs()forces the log write, and on a dead device that write fails and shuts XFS down.fstat()returnsEIO, does no I/O and never blocks. With one bad file, XFS stays up andfstat()succeeds, so there is no fence.statfs()cannot be used: it still succeeds after a shutdown. A small sentinel write cannot be used either: on a striped volume it misses the dead leg.With several offload disks (
storage_filepathas a list, #4231) the check covers every disk; a failure does not say which disk it came from, and the master has one LOCAL_DISK segment per store, so one dead disk fences the whole disk tier.No counters or time windows are involved: each failure is judged on its own against the filesystem's current state. Checks run one at a time; a failure that arrives while one runs is queued and checked right after it, with
syncfsif any queued failure needs it, so a write failure'ssyncfsis not lost behind a read'sfstat-only check.What a fence does (latched until the store restarts):
BatchLoad, and the byte-windowBatchLoadSpansfrom [Store] Read only the byte window a layer transfers from disk #4988) short-circuit without touching the device, and offloading stops;Related fix in the same path.
DrainLocalDiskSegmentused to reset the drain latch when the unmount RPC failed (for example, a timeout while the master is still sweeping a large index). The next heartbeat then gotSEGMENT_NOT_FOUND, re-mounted the segment and re-registered every object while the master's sweep was still running. On a rig with about 2.9M keys and a 1 s RPC timeout this happened in both rounds and the master lost the index of 62,597–75,840 disk objects. Now the latch stays set, and while draining each heartbeat retries the unmount until the master acknowledges it (the master already treats an already-unmounted segment as success). The heartbeat never re-mounts while draining. This changes the drain contract of #3316: a failedUnmountLocalDiskSegmentno longer unlatches the drain, and the store does not resume until the master acknowledges the unmount (pinned byDrainUnmountFailureKeepsLatchAndRetries).New gauge:
mooncake_ssd_disk_fenced(0/1). Each fence logs one line with the op, the errno, the check result and the path.Scope: errnos are reported by
bucket_storage_backend(the default backend). The file-per-key and offset-allocator backends do not report them yet, so they never fence; this is noted in the docs.Docs: a troubleshooting entry for
action=disk_fenceindocs/source/deployment/ssd/ssd-offload.md.Out of scope: per-key recovery from a single bad file (#3889; this PR does not fence in that case), and a device that hangs without returning an errno.
Module
mooncake-store)docs)Type of Change
How Has This Been Tested?
Test commands:
Test results:
mainat52f989e0, in an amd64 container: every test in the suites above passes except 8 io_uring tests, which cannot create a ring there (io_uring_setupreturnsENOSYS); CI covers them on a real kernel. Before the last merge, on a real kernel: 277/277.New tests:
PosixFile;ENODEV, and onEIOwhen the filesystem check fails;EIOwhen the check passes, and none onENOSPC;InProcMasterand the heartbeat does not re-mount;syncfs), and the checking slot is released afterwards;ENOENT);pwritev/preadvand short io_uring completions continue to the real errno (RLIMIT_FSIZEgivesEFBIG, an inaccessible page givesEFAULT); a failed io_uring completion keeps its errno, and the io_uring read leg reports it to the observer.The latch test fails on
mainas is. The other new tests use the new API and do not compile onmain. The short-I/O and io_uring tests each fail on75fe664c. The queued-check and carried-task tests each fail with their fix reverted.Manual: the errno behavior above was measured with deterministic fault injection (dm-error / dm-flakey / XFS shutdown / dm-stripe) on a 6.8 kernel. End-to-end results with master + 3 stores on fault-injected disks are in the comments.
Checklist
./scripts/code_format.sh(clang-format 20)AI Assistance Disclosure
Claude (Anthropic) helped trace the code paths, run the kernel errno measurements, write the change and its tests, and run the verification. The submitter is responsible for the change.