Repository navigation
Fix: filesystem cache disk IO error must not mark MergeTree parts as broken - #99386
alexey-milovidov merged 3 commits into
Conversation
…broken When reading part metadata files (e.g. `checksums.txt`) at startup via `CachedOnDiskReadBufferFromFile`, a local cache disk IO failure was propagated up through `writeCache()` as a raw `ErrnoException`. This caused `loadDataPart()` to treat it as data corruption and mark the part as broken, even though the underlying S3 data was intact. Fix the read path by: - Adding a new `CACHE_CANNOT_WRITE_TO_CACHE_DISK` (code 771) error code that wraps cache disk IO errors from `writeCache()`. - Adding a new `skip_cache_on_disk_failure` (Bool, default false) setting to `FileCacheSettings`. When true, cache write failures are silently bypassed (LOG_ERROR logged); when false (default), they are wrapped as `CACHE_CANNOT_WRITE_TO_CACHE_DISK` and propagated. - Registering `cache_filesystem_failure` failpoint in `FileSegment::write` to enable injection-based testing. - Adding `fs::filesystem_error` catch in `FileSegment::write` to ensure state machine consistency if `std::filesystem::file_size()` throws. - Marking `CACHE_CANNOT_WRITE_TO_CACHE_DISK` as retryable in `isRetryableException()` so that `loadDataPart()` rethrows instead of marking the part broken, propagating the error to `loadDataPartWithRetries` which exhausts retries and causes a clear startup failure. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Workflow [PR], commit [152482f] Summary: ✅ AI ReviewSummaryThis PR correctly targets a real issue ( Missing context
Findings❌ Blockers
💡 Nits
ClickHouse Rules
Performance & Safety
Final Verdict
|
| throw ErrnoException(e.code().value(), | ||
| "Filesystem error in cache write ({}), current cache state: {}", | ||
| e.what(), getInfoForLogUnlocked(lk)); | ||
| } |
There was a problem hiding this comment.
Wrong ErrnoException constructor loses filesystem error code
Medium Severity
The fs::filesystem_error catch block creates ErrnoException(e.code().value(), fmt, args...) which matches the constructor ErrnoException(int code, FormatStringHelper, Args...). Here the POSIX errno (e.g. EIO=5) becomes the ClickHouse error code, while saved_errno is set to the ambient thread-local errno, not e.code().value(). When this exception reaches writeCache(), e.getErrno() returns the wrong value. If the ambient errno happens to be 28 (ENOSPC) or 122 (EDQUOT), a real disk IO error gets silently swallowed instead of propagating as CACHE_CANNOT_WRITE_TO_CACHE_DISK. The four-argument constructor ErrnoException(clickhouse_code, e.code().value(), fmt, args...) is needed to explicitly set both the ClickHouse error code and the errno.
| fiu_do_on(FailPoints::cache_filesystem_failure, | ||
| { | ||
| throw ErrnoException(EIO, "Failpoint: simulated cache disk IO failure"); | ||
| }); |
There was a problem hiding this comment.
Failpoint ErrnoException doesn't set errno to EIO
Medium Severity
ErrnoException(EIO, "Failpoint: ...") matches the constructor ErrnoException(int code, T&& message) where EIO (5) becomes the ClickHouse error code and saved_errno captures the ambient thread-local errno — not EIO. So getErrno() returns a nondeterministic value. In FileSegment::write()'s catch handler, is_no_space_left_error could be incorrectly true if the ambient errno is 28 or 122, and writeCache() could silently swallow the error instead of throwing CACHE_CANNOT_WRITE_TO_CACHE_DISK. This makes all four integration tests nondeterministic. The four-argument constructor with explicit with_errno parameter is needed.
| DECLARE(Bool, write_cache_per_user_id_directory, false, "Internal ClickHouse Cloud setting", 0) \ | ||
| DECLARE(Bool, allow_dynamic_cache_resize, false, "Allow dynamic resize of filesystem cache", 0) \ | ||
| DECLARE(Double, max_size_ratio_to_total_space, 0, "Ratio of `max_size` to total disk space", 0) \ | ||
| DECLARE(Bool, skip_cache_on_disk_failure, false, "If true, bypass filesystem cache operations silently on disk IO errors. If false (default), disk IO errors are propagated as startup failures.", 0) \ |
There was a problem hiding this comment.
Nit: the setting description says disk I/O errors are propagated as startup failures, but this code path is also hit during runtime reads (for example SELECT on cache miss). Please reword it to avoid implying this is startup-only.
| { | ||
| auto lk = lock(); | ||
| setDownloadFailedUnlocked(lk); | ||
| throw ErrnoException(e.code().value(), |
There was a problem hiding this comment.
ErrnoException(e.code().value(), ...) passes OS errno as the ClickHouse code and does not preserve e.code().value() as saved_errno (it captures ambient errno). As a result, downstream handling that relies on e.getErrno() can become incorrect. Please use the overload with explicit errno, e.g. ErrnoException(<ch_error_code>, e.code().value(), "...").
|
|
||
| fiu_do_on(FailPoints::cache_filesystem_failure, | ||
| { | ||
| throw ErrnoException(EIO, "Failpoint: simulated cache disk IO failure"); |
There was a problem hiding this comment.
ErrnoException(EIO, ...) uses EIO as the ClickHouse exception code, while saved_errno is taken from ambient errno. That makes e.getErrno() nondeterministic here and can misclassify errors (for example as no-space) depending on unrelated thread-local errno. Please construct with explicit errno: ErrnoException(<ch_error_code>, EIO, "...") (or throwWithErrno).
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 74.80% (95/127, 0 noise lines excluded) |
|
Thanks! Just resolve the last review comments, and we can merge... |
|
Backporting to fix 26.3 CI |
Resolve the three conflicts of the #99386 cherry-pick against 26.3. `FailPoint.cpp` and `FileSegment.cpp` conflict only because 26.3 still has `file_segment_pause_before_write`, which master removed: keep it and add the new `cache_filesystem_failure` next to it. `02344_describe_cache.reference` conflicts because `DESCRIBE FILESYSTEM CACHE` prints one column per `FileCacheSettings` entry and 26.3 has a setting master lacks (`dynamic_resize_lock_wait_ms`). Rebuild the row from 26.3's, inserting the new `skip_cache_on_disk_failure` at the position the merged declaration list gives it, between `max_size_ratio_to_total_space` and `use_split_cache`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cherry pick #99386 to 26.3: Fix: filesystem cache disk IO error must not mark MergeTree parts as broken
… mark MergeTree parts as broken
Backport #99386 to 26.3: Fix: filesystem cache disk IO error must not mark MergeTree parts as broken


Problem
When starting a
MergeTreetable backed by S3 with a local filesystem cache, a disk IO error during cache write causes the part to be incorrectly marked as broken — even though the data in S3 is intact. ref #83823Root cause:
loadDataPart()callsisRetryableException()to decide whether tomark_brokenor rethrow. Cache write IO errors were not recognized as retryable, so they fell into themark_brokenbranch instead of propagating.Core call chain:
Fix
CACHE_CANNOT_WRITE_TO_CACHE_DISK: thrown when local cache disk write failsisRetryableException()now recognizesCACHE_CANNOT_WRITE_TO_CACHE_DISK→ rethrows instead of marking broken → propagates to startup failure with a clear error messageskip_cache_on_disk_failure(defaultfalse) in cache disk config: whentrue, cache write failures are silently bypassed and the read falls back to S3 — suitable for degraded-mode operationcache_filesystem_failureadded for testingBehavior
skip_cache_on_disk_failure=false(default)skip_cache_on_disk_failure=trueIntegration Tests
4 scenarios in
tests/integration/test_cache_bypass_on_disk_failure/:test_skip_cache_on_disk_failure_select:skip=true, failpoint during SELECT → succeeds, no broken partstest_noskip_cache_on_disk_failure_select:skip=false, failpoint during SELECT → raisesCACHE_CANNOT_WRITE_TO_CACHE_DISKtest_skip_cache_on_disk_failure_attach:skip=true, failpoint duringATTACH TABLE→ part loads successfully,system.detached_partsemptytest_noskip_cache_on_disk_failure_attach:skip=false, failpoint duringATTACH TABLE→ ATTACH fails, butsystem.detached_partsremains empty (core assertion of the bug fix)Modified Files
src/Common/ErrorCodes.cppCACHE_CANNOT_WRITE_TO_CACHE_DISKsrc/Common/FailPoint.cppcache_filesystem_failurefailpointsrc/Interpreters/Cache/FileCacheSettings.cppskip_cache_on_disk_failure(Bool, default false)src/Interpreters/Cache/FileCache.h/.cppskipCacheOnDiskFailure()src/Interpreters/Cache/FileSegment.cppnext()+fs::filesystem_errorcatchsrc/Disks/IO/CachedOnDiskReadBufferFromFile.h/.cppwriteCache()with skip logic + CACHED read fallbacksrc/Storages/MergeTree/checkDataPart.cppisRetryableException()handlesCACHE_CANNOT_WRITE_TO_CACHE_DISKtests/integration/test_cache_bypass_on_disk_failure/Changelog category (leave one)
Bug Fix (MergeTree)
Changelog entry
Fix: filesystem cache disk IO error during
MergeTreepart loading no longer incorrectly marks parts as broken when S3 data is intact. Addskip_cache_on_disk_failurecache disk setting to control error propagation behavior.🤖 Generated with Claude Code
Note
Medium Risk
Changes how filesystem cache write failures are surfaced/handled during MergeTree reads/part loading, which can affect startup/query behavior under cache-disk faults. Adds a new config flag to silently bypass cache writes, so misconfiguration could mask underlying storage issues.
Overview
Prevents filesystem cache disk write failures from being treated as non-retryable MergeTree part load errors by introducing new error code
CACHE_CANNOT_WRITE_TO_CACHE_DISKand classifying it as retryable incheckDataPart.cpp.Adds cache-level control via new setting
skip_cache_on_disk_failure(defaultfalse) exposed onFileCacheand plumbed throughCachedOnDiskReadBufferFromFileso cache write IO errors can either fail fast with a clear exception or silently bypass cache writes and fall back to remote reads.Improves testability/robustness by adding failpoint
cache_filesystem_failure, hardeningFileSegment::write()error handling (convertfilesystem_errortoErrnoException), and adding integration tests covering SELECT/ATTACH behavior for both skip modes to ensure parts are not moved tosystem.detached_parts.Written by Cursor Bugbot for commit ff7f9ff. This will update automatically on new commits. Configure here.
Version info
26.4.1.240(included in26.4and later)26.3.33.45