Repository navigation
Fix server failing to start on a transient I/O error reading part transaction metadata - #111771
Open
tiandiwonder wants to merge 2 commits into
Open
tiandiwonder wants to merge 2 commits into
tiandiwonder wants to merge 2 commits into
Conversation
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]>
Contributor
|
Workflow [PR], commit [27c41a9] Summary: ❌
AI ReviewSummaryThis PR fixes the startup and Final Verdict
|
`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]>
1 task done
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 91/117 (77.78%) · Uncovered code |
This was referenced Jul 26, 2026
1 task done
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.
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'stxn_version.txt:Consequences:
Root cause
When two block-range-intersecting parts are found during
PartLoadingTree::build,PartLoadingTree::addreads each part's transaction status via theread_txn_statuslambda insrc/Storages/MergeTree/MergeTreeData.cpp. Itscatch (...)collapsed every exception into a singleUnreadablestate, andaddthen threwCORRUPTED_DATA. Becausebuildruns outsideloadDataPartWithRetries, a transient error was neither classified as transient nor retried.Fix
read_txn_statusnow classifies failures by where they occur, inside a bounded retry loop (reusing the existingloading_parts_max_tries/ backoff constants):isRetryableException) → retried; if it outlives the retries, the original exception is rethrown (fail-close with the accurate error, notCORRUPTED_DATA).UnreadableContent, whichaddmaps toCORRUPTED_DATAas before.Hardening: a shared bounded reader
VersionInfo::readMetadataString(reads at mostMAX_METADATA_SIZE + 1bytes; oversize is proven from bytes actually read, not from a possibly-corrupt on-disk file size), used by bothread_txn_statusandVersionMetadataOnDisk::readMetadataUnlocked; strict EOF for the currenttxn_version.txtformat (the legacy pre-storing_versionformat returns early and is exempt).Regression test
04627_startup_txn_metadata_transient_io.shdrives the path viaATTACHbehindONCE/REGULARfailpoints 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, vialoadDataPartWithRetries+isRetryableException(src/Storages/MergeTree/checkDataPart.cpp).PartLoadingTree::build(which callsread_txn_status) simply runs outside that retry wrapper and used a blanketcatch (...); this PR brings the same established treatment to that path (reusing the sameloading_parts_max_tries/ backoff constants).Changelog category (leave one):
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.