Repository navigation
Fix crash on corrupt txn_version.txt in assertHasValidVersionMetadata - #99025
alexey-milovidov wants to merge 1 commit into
Conversation
…ata` The `txn_version.txt` file can become corrupt on DiskObjectStorage (Azure/S3) because append operations are simulated via read-modify-write of metadata, which is not atomic. Concurrent appends (e.g., transaction rollback clearing removal_tid + new transaction setting removal_tid + commit writing CSN) can race, causing the metadata to lose the original blob containing the file header (`version: 1\ncreation_tid: ...`). This caused two crashes: 1. `assertHasValidVersionMetadata` returned false on corrupt file → `chassert` terminated the server in sanitizer builds. 2. After restart, `loadVersionMetadata` failed to parse the corrupt file → `loadOutdatedDataParts` called `std::terminate`. Fix both: - In `loadVersionMetadata`: catch parse errors for corrupt files and treat the part as prehistoric, allowing the server to start normally. - In `assertHasValidVersionMetadata`: distinguish between actual metadata mismatches (in-memory vs on-disk, return false) and file corruption (unparseable file, return true with warning), since file corruption is not a logic error in version tracking. Closes #94142 https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=54911410bd8f61f5421394491d091f041ebc01d4&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29 https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=06598f27ab378120683ccf2cc08c0632aca84f0c&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%2C%202%2F2%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
|
||
| version.setCreationTID(Tx::PrehistoricTID, nullptr); | ||
| version.creation_csn = Tx::PrehistoricCSN; | ||
| } |
There was a problem hiding this comment.
Incomplete version metadata reset after corrupt file parse
Medium Severity
When version.read(*buf) partially parses a corrupt file before throwing, the catch block only resets creation_tid and creation_csn but does not reset removal_tid, removal_tid_lock, or removal_csn. VersionMetadata::read() can successfully set removal_tid and removal_tid_lock before failing on a later field, leaving the metadata in an inconsistent state where the part appears prehistoric for creation but has non-empty removal fields. This can cause wasInvolvedInTransaction() to return true due to a non-zero removal_tid_lock, leading to unexpected behavior downstream.
|
Almost sure this is wrong. |
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 21.28% (10/47) |
|
Created a new PR#99129 to fix it. |


Summary
txn_version.txtfile is corruptloadVersionMetadata: catch parse errors and treat the part as prehistoric, allowing the server to startassertHasValidVersionMetadata: distinguish between actual metadata mismatches (assertion fails) and file corruption (warning only, no crash)Closes #94142
CI reports:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
🤖 Generated with Claude Code
Note
Medium Risk
Touches MergeTree transactional version-metadata loading/validation; incorrect fallback could hide real metadata issues or change part visibility/cleanup behavior, though changes are largely scoped to corruption handling and logging.
Overview
Prevents crashes/restart loops when a part’s
txn_version.txtis unreadable (e.g., due to non-atomic append semantics on object storage):loadVersionMetadata()now catches parse failures, logs a warning, and falls back to prehistoric version metadata so the server can start and the part can be cleaned up normally.Adjusts
assertHasValidVersionMetadata()to distinguish corruption from real mismatches: metadata mismatches still fail the assertion, but parse/validation errors consistent with file corruption now only warn (with expected vs actual content) and do not fail the assertion.Written by Cursor Bugbot for commit f604696. This will update automatically on new commits. Configure here.