Skip to content

Retry a part load after an I/O error instead of detaching the part as broken - #127381

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-load-part-transient-io-error
Oct 24, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-load-part-transient-io-error

Conversation

@groeneai

@groeneai groeneai commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #127233
Related: #114180

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a data part being detached as broken-on-start (its rows disappearing from the table) after a single transient I/O error (EIO) while reading the part's metadata at server startup or ATTACH TABLE. The load is now retried, and an I/O error marks the part broken only when the load has failed on all 3 attempts. Closes #127233.

Description

On 26.9.19.9, one EIO while reading checksums.txt of a part at startup (strace fault injection, as in the issue) renames the part to detached/broken-on-start_all_1_1_0, and SELECT count() returns 0 instead of 300 with no error.

loadDataPart marks a part broken on any error that isRetryableException rejects, and EIO is rejected, so loadDataPartWithRetries never retries it. Now an I/O error (ErrnoException with EIO, or std::filesystem::filesystem_error with io_error from stat) is rethrown while attempts remain, so the existing 3 attempts (shared with the other retryable errors) absorb a transient one; the last attempt marks the part broken as before, so a persistent error still detaches it and the server still starts. isRetryableException is unchanged. When checksums.txt is missing or empty, checkDataPart recalculates it and reads serialization.json again; it reported an EIO there as CORRUPTED_DATA and now rethrows it, so that path is retried too.

Validation, real syscalls with strace: one EIO on checksums.txt, columns.txt, count.txt, serialization.json (its read, or its second open with checksums.txt removed) or on a stat of the part: master detaches the part, the fix keeps all 300 rows. A persistent EIO still detaches the part after 3 attempts; a garbage checksums.txt or serialization.json is still reported as corruption. The new test injects one EIO with a once-only failpoint, checks that it fired, and fails without the retry; the persistent and missing-checksums.txt cases are covered by the strace runs only.

#114180 (open) proposes the same retry-then-mark-broken shape for an object store not-found on the same lines of loadDataPart; whichever merges second is rebased.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127381]

Version info

  • Merged into: 26.11.1.701-master (included in 26.11 and later)

groeneai and others added 2 commits October 22, 2026 10:38
… broken

At server startup and on ATTACH TABLE, one failed read (EIO) of a part
metadata file (checksums.txt, columns.txt, count.txt, serialization.json,
...) made loadDataPart mark the part broken on the first attempt, so it
was renamed to detached/broken-on-start_<name> and its rows disappeared
from the table until manual repair. loadDataPart marks a part broken on
any error that isRetryableException rejects, and EIO is rejected, so the
retries of loadDataPartWithRetries never engaged.

An I/O error (ErrnoException with EIO, or std::filesystem::filesystem_error
with io_error from stat) is now rethrown by loadDataPart while attempts
remain, so the existing three attempts absorb a transient error. On the
last attempt the part is marked broken as before: a persistent error
still detaches the part instead of failing the whole table load, which
keeps the behaviour chosen in ClickHouse#49430. isRetryableException itself is not
changed, because its other callers (readers, part check, fetch) must keep
treating a persistent I/O error as a broken part. The "needs manual
correction" log line is not printed for an I/O error.

The regression test uses a new once-only failpoint that throws EIO while
loading part metadata. It is tagged no-parallel, no-fasttest as required
for failpoint tests by the style check.

Closes ClickHouse#127233

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Assert that the once-only failpoint `merge_tree_load_part_io_error` is
spent after `ATTACH`, so the test goes red if the injection no longer
reaches the part load path (it would otherwise still print 300 / 0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (3 runs, 1 fix round)
  • ⚠️ The test could pass if the injected error never fired → fixed: it now checks that the once-only failpoint is spent after ATTACH.
  • ❌ (disagreed) Persistent / stat / corruption boundaries unproven → shown with real-syscall strace runs: a persistent EIO is retried twice, then the part is detached and the server starts; one stat EIO keeps all rows; a garbage checksums.txt is detached on the first attempt with no retry.
  • ❌ (disagreed) Two other retryable failures followed by one EIO on the third attempt still detach the part → by design: the 3 attempts are one budget shared with the other retryable errors, and the part is marked broken only when the load failed on all 3 (master detaches on that EIO as well). Rethrowing on the last attempt instead fails the whole table load. The changelog entry states this budget exactly.
  • ⚠️ (disagreed) A persistent EIO from the later modification-time stat escapes the load → not reachable as persistent: the part builder stats the same directory first in every attempt, so a persistent fault there is caught by the guarded block and detaches the part on the last attempt (measured with a directory stat EIO). Only an intermittent fault can reach the later stat; it is now retried twice, where master failed the load on the first.
  • 💡 Noted, not blocking: the SQL test cannot pin the persistent-error path (strace runs cover it); a transient EIO on a projection's metadata still marks only that projection broken until restart (parent rows intact).

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. strace -e inject=read,pread64:error=EIO:when=1 -P <part>/checksums.txt at restart: master detaches the part every run; the SQL test with the failpoint fails every run without the retry.
b Root cause explained? loadDataPart marks a part broken on any error isRetryableException rejects; EIO is rejected, so loadDataPartWithRetries never retries it and the first failed read detaches the part.
c Fix matches root cause? Yes. An I/O error is rethrown while attempts remain, so the existing retry budget absorbs a transient one; the last attempt keeps the old outcome.
d Test intent preserved / new tests added? New 05443_load_part_transient_io_error.sql with a once-only failpoint; red without the retry, green with it. It also asserts the failpoint fired (system.fail_points.enabled = 0 after ATTACH).
e Both directions demonstrated? Yes: real syscalls on master and the official 26.9.19.9 build (0 rows, broken-on-start) vs the fix (300 rows); SQL test 10/10 red on a build without the I/O-error terms, 50/50 green on the fix.
f Fix is general across code paths? All three catch blocks of loadDataPart; active, PreActive refresh and outdated loads all go through loadDataPartWithRetries; read, open and stat errors. isRetryableException and its other callers unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? Measured on checksums.txt, columns.txt, count.txt, serialization.json, a file stat and the part directory stat; transient vs persistent; a truly corrupt checksums.txt is still detached on the first attempt.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; a persistent I/O error still detaches the part and the server still starts, after 300 ms of backoff.
i Invariants and contracts preserved? Every throw precedes the data_parts_indexes insert and each attempt builds a new part, so a retry starts clean, as for the existing retryable errors.

Session id: cron:clickhouse-impl-slot-7:20261022-100400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @hanfei1991, could you review this and add the can be tested label so CI runs? A transient EIO while loading a part's metadata is now rethrown into the existing 3 load attempts of loadDataPartWithRetries instead of marking the part broken-on-start; only the last attempt marks it broken, so a persistent error still detaches the part and the server still starts.

@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4dc04f6]

Summary: ✅


AI Review

Summary

The PR retries transient EIO failures while loading MergeTree parts within the existing three-attempt budget, preserving detachment for persistent failures. Commit 4dc04f6e4d6f also preserves the original I/O exception during checksum reconstruction, addressing the previous inline finding; that thread is resolved. No new actionable findings remain. This review used the current source, the committed regression test, and the author's reported syscall fault-injection results; tests were not rerun locally because this checkout has no build or binary.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Oct 22, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 22, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4dc04f6e4 with master b34a2bfd1 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 7fc386e15; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

251 translation units recompiled, 2887 s compile time in total, 251 of them have a recent master baseline.

Job report

…t as corruption

When `checksums.txt` of a part is missing or empty, `loadChecksums` recalculates the
checksums with `checkDataPart`, which reads `serialization.json` again. Its `catch (...)`
turned every error, including an `EIO` from the read, into `CORRUPTED_DATA`, so
`loadDataPart` did not retry the load and detached the part as broken on the first
transient I/O error. Rethrow I/O errors as is; anything else is still reported as
`CORRUPTED_DATA`. The other callers of `checkDataPart` only distinguish retryable
errors, and an `EIO` was not retryable before either, so their verdicts do not change.

Validated locally with strace fault injection (part without `checksums.txt`, `EIO` on
the second open of `serialization.json`): before, the part was detached as
`broken-on-start` on the first attempt; after, the load is retried and the part keeps
its 300 rows. A persistent error still detaches the part after 3 attempts, and an
invalid `serialization.json` is still reported as `CORRUPTED_DATA`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Oct 23, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 23, 2026
Merged via the queue into ClickHouse:master with commit 9da8403 Oct 24, 2026
178 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

3 participants