Skip to content

Handle old VersionInfo metadata format gracefully - #103031

Merged
tuanpach merged 3 commits into
ClickHouse:masterfrom
tuanpach:fix-version-info-old-format
Apr 21, 2026
Merged

tuanpach merged 3 commits into
ClickHouse:masterfrom
tuanpach:fix-version-info-old-format

Conversation

@tuanpach

@tuanpach tuanpach commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

Old format metadata files (before storing_version was introduced) have creation_tid: immediately after version: 1, which caused assertString to throw a parse exception when loading parts on upgraded instances.

Detect old format by checking for creation_tid: at the position where storing_version: is expected. checkString is safe here because the first character differs ('c' vs 's'), so it never partially consumes the buffer on a new-format file. Old-format parts are converted to non-transactional to avoid failure.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.1099

Old format metadata files (before `storing_version` was introduced) have
`creation_tid:` immediately after `version: 1`, which caused `assertString`
to throw a parse exception when loading parts on upgraded instances.

Detect old format by checking for `creation_tid:` at the position where
`storing_version:` is expected. `checkString` is safe here because the
first character differs ('c' vs 's'), so it never partially consumes the
buffer on a new-format file. Old-format parts are converted to
non-transactional to avoid the failure.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@tuanpach tuanpach added the can be tested Allows running workflows for external contributors label Apr 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ed3ff63]

Summary: ✅


AI Review

Summary

This PR adds a fallback in VersionInfo::readFromMultiLineBuffer for legacy metadata without storing_version. The fallback currently rewrites any such record to non-transactional defaults instead of parsing legacy fields. That can change visibility semantics for parts that had meaningful legacy transaction/removal state, so the change is not safe as implemented.

PR Metadata
  • Changelog category is not correct for this change. The PR modifies server correctness/compatibility behavior, but currently uses CI Fix or Improvement.
  • Changelog entry is required once category is corrected, and should describe user-visible upgrade behavior.
  • Suggested replacement:
    • Changelog category: Bug Fix
    • Changelog entry: Fixed parsing of legacy MergeTree version metadata during upgrade to avoid misinterpreting old transaction/removal state.
Findings

❌ Blockers

  • [src/Interpreters/MergeTreeTransaction/VersionInfo.cpp:106-113] When creation_tid: is detected right after the header, the parser returns immediately after assigning default non-transactional values and discards all legacy fields. This can reinterpret a removed/rolled-back part as visible and lead to wrong query results after upgrade.
    • Suggested fix: keep storing_version = 0 for legacy layout, then parse and preserve legacy creation_tid, creation_csn, removal_tid, and removal_csn instead of overwriting with defaults.
Tests
  • ⚠️ Add regression tests for legacy VersionInfo parsing (without storing_version) that preserve non-empty removal_tid/removal_csn and verify malformed legacy input still throws a parse exception.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ⚠️ Legacy format is handled by semantic reinterpretation rather than faithful parsing
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ❌ Legacy metadata may be reinterpreted with different visibility semantics
SettingsChangesHistory.cpp ➖
PR metadata quality ⚠️ Changelog category is CI Fix or Improvement, but this is a correctness/compatibility code change
Safe rollout ⚠️ No regression coverage for legacy + malformed metadata path
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Preserve legacy transaction/removal fields during old-format parsing (do not rewrite to defaults).
    • Correct PR metadata (Changelog category/entry) to match a user-facing bug fix.
    • Add focused regression tests for legacy and malformed-input paths.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 17, 2026
@tuanpach tuanpach mentioned this pull request Apr 17, 2026
1 task
/// after the version header. Convert such metadata to non-transactional instead of throwing a parse exception.
/// `checkString` is safe here because the first character differs ('c' vs 's'), so it never partially consumes.
if (checkString(CREATION_TID_STR, buf))
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback drops all legacy metadata fields after detecting old layout and unconditionally marks the part as non-transactional (creation_tid = NonTransactionalTID, removal_tid = EmptyTID, etc.).

That can silently change semantics for old-format files that still contain meaningful creation_tid / creation_csn / removal_tid / removal_csn values (e.g. rollback/remove state), potentially making an actually removed/rolled-back part look visible.

Please parse the legacy layout instead of replacing it with defaults: keep storing_version = 0 for old files, then read the remaining legacy fields from the buffer (creation_tid, creation_csn, removal_tid, removal_csn) and assign them as-is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to make it compatible, as it is an experimental feature. We just need to handle it without failure

@clickhouse-gh

clickhouse-gh Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 53.85% (7/13) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@tiandiwonder tiandiwonder self-assigned this Apr 21, 2026
@tuanpach
tuanpach added this pull request to the merge queue Apr 21, 2026
Merged via the queue into ClickHouse:master with commit 3d1f7d2 Apr 21, 2026
161 checks passed
@tuanpach
tuanpach deleted the fix-version-info-old-format branch April 21, 2026 09:58
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 21, 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 pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants