Skip to content

Fix server failing to start on a transient I/O error reading part transaction metadata - #111771

Open
tiandiwonder wants to merge 2 commits into
masterfrom
startup-txn-io-classify-retry
Open

tiandiwonder wants to merge 2 commits into
masterfrom
startup-txn-io-classify-retry

Conversation

@tiandiwonder

@tiandiwonder tiandiwonder commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On startup (or ATTACH), a table can fail to load with a spurious data-corruption error when a transient I/O error (an S3, Keeper, or memory hiccup) occurs while reading a data part's txn_version.txt:

Code: 246. DB::Exception ... Part all_5_6_1_0 intersects previous part all_1_5_4_1 and the transaction metadata of at least one of them could not be read. This indicates disk corruption or a partial write.

Consequences:

  • The transient error is mis-reported as disk corruption.
  • The server does not start / the table does not attach, with no retry — a single transient blip during part loading is fatal.

Root cause

When two block-range-intersecting parts are found during PartLoadingTree::build, PartLoadingTree::add reads each part's transaction status via the read_txn_status lambda in src/Storages/MergeTree/MergeTreeData.cpp. Its catch (...) collapsed every exception into a single Unreadable state, and add then threw CORRUPTED_DATA. Because build runs outside loadDataPartWithRetries, a transient error was neither classified as transient nor retried.

Fix

read_txn_status now classifies failures by where they occur, inside a bounded retry loop (reusing the existing loading_parts_max_tries / backoff constants):

  • Transient I/O (isRetryableException) → retried; if it outlives the retries, the original exception is rethrown (fail-close with the accurate error, not CORRUPTED_DATA).
  • Permanent, non-retryable I/O → rethrown as-is (never reported as corruption).
  • Content corruption (file fully read, then parse / strict-EOF / size-cap fails) → UnreadableContent, which add maps to CORRUPTED_DATA as before.

Hardening: a shared bounded reader VersionInfo::readMetadataString (reads at most MAX_METADATA_SIZE + 1 bytes; oversize is proven from bytes actually read, not from a possibly-corrupt on-disk file size), used by both read_txn_status and VersionMetadataOnDisk::readMetadataUnlocked; strict EOF for the current txn_version.txt format (the legacy pre-storing_version format returns early and is exempt).

Regression test 04627_startup_txn_metadata_transient_io.sh drives the path via ATTACH behind ONCE/REGULAR failpoints and covers: transient-retry success, retry exhaustion staying non-corruption, non-retryable propagation (not retried), legacy acceptance, and strict-EOF and oversize rejection.

Scope / precedent

This gap was found by code inspection of the startup part-loading path, not from an observed incident — there is no logged occurrence of a real transient error hitting read_txn_status; this is defense-in-depth / robustness hardening. The justification is structural and consistency-based: the surrounding part-loading code already retries transient I/O and refuses to treat it as a broken part, via loadDataPartWithRetries + isRetryableException (src/Storages/MergeTree/checkDataPart.cpp). PartLoadingTree::build (which calls read_txn_status) simply runs outside that retry wrapper and used a blanket catch (...); this PR brings the same established treatment to that path (reusing the same loading_parts_max_tries / backoff constants).

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):

Fixed a server failing to start (or a table failing to ATTACH) with a spurious "disk corruption" error when a temporary I/O hiccup occurred while reading a data part's transaction metadata during startup. Such transient errors are now retried instead of being reported as data corruption.

At startup / ATTACH, PartLoadingTree::add resolves two block-range-intersecting
parts by reading each part's txn_version.txt via read_txn_status. Its catch(...)
collapsed every exception into a single Unreadable state, so the intersection
resolution threw CORRUPTED_DATA ("... transaction metadata ... could not be read.
This indicates disk corruption or a partial write."). A transient I/O error
(S3/Keeper/memory blip) was therefore (1) mis-reported as disk corruption and
(2) never retried, because PartLoadingTree::build runs outside
loadDataPartWithRetries, so a single transient hiccup permanently failed startup.

read_txn_status now classifies failures by where they occur, inside a bounded
retry loop (reusing loading_parts_max_tries / backoff):
- transient I/O (isRetryableException) is retried; if it outlives the retries,
  the original exception is rethrown (fail-close with the accurate error);
- a permanent, non-retryable I/O error is rethrown as-is (never "corruption");
- only a fully-read-but-unparsable file becomes UnreadableContent, which add
  maps to CORRUPTED_DATA (unchanged genuine-corruption behavior).

Supporting hardening: a shared bounded reader VersionInfo::readMetadataString
(reads at most MAX_METADATA_SIZE + 1 bytes; oversize is proven from bytes read,
never trusting a possibly-corrupt on-disk file size), used by both read_txn_status
and VersionMetadataOnDisk::readMetadataUnlocked; strict EOF in
VersionInfo::readFromMultiLineBuffer for the current format (the legacy
pre-storing_version format returns early and is exempt).

The stateless test drives the code path via ATTACH and covers, behind ONCE/REGULAR
failpoints: transient-retry success, retry exhaustion staying non-corruption,
non-retryable propagation (not retried), legacy acceptance, and strict-EOF and
oversize rejection.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [27c41a9]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
04011_predicate_statistics_log ERROR cidb
Server died FAIL cidb
03707_statistics_cache NOT_FAILED cidb
01010_partial_merge_join NOT_FAILED cidb
01147_partial_merge_full_join NOT_FAILED cidb
02499_monotonicity_toUnixTimestamp64 NOT_FAILED cidb
02345_implicit_transaction NOT_FAILED cidb
Logical error: Got read request from replica A for unknown stream B. (STID: 5217-5b3d) FAIL cidb, issue
Stateless tests (amd_tsan, parallel) FAIL
04367_distributed_plan_merge_scatter_multishard FAIL cidb
Upgrade check (amd_release) FAIL
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb

AI Review

Summary

This PR fixes the startup and ATTACH path where PartLoadingTree::build used to collapse any failure while reading txn_version.txt into CORRUPTED_DATA, which could misreport a transient I/O problem as disk corruption and fail without retry. The current head cleanly separates retryable I/O from genuinely unreadable metadata, shares the bounded metadata read logic with VersionMetadataOnDisk, and adds a focused regression test for the user-visible failure mode. I did not find a remaining correctness, compatibility, or test-coverage issue that warrants a review finding.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 24, 2026
@tiandiwonder tiandiwonder added can be tested Allows running workflows for external contributors pr-ci labels Jul 24, 2026
@clickhouse-gh clickhouse-gh Bot removed the pr-ci label Jul 24, 2026
`cppcoreguidelines-init-variables` (-warnings-as-errors) flagged the loop
variable `char c;` as uninitialized in the arm_tidy build.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 91.90% -0.10%
Branches 78.30% 78.20% -0.10%

Changed lines: Changed C/C++ lines covered: 91/117 (77.78%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot added comp-transactions MergeTree transactions (MVCC): BEGIN / COMMIT / ROLLBACK, the transaction log and manager, part v... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026

This branch has not been deployed

No deployments
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-transactions MergeTree transactions (MVCC): BEGIN / COMMIT / ROLLBACK, the transaction log and manager, part v... pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant