Skip to content

Revert "Fix logical error when fetched part has newer metadata version than table" - #97301

Merged
alesapin merged 1 commit into
masterfrom
revert-96008-fix-mutation-part-metadata-version-mismatch
Feb 19, 2026
Merged

alesapin merged 1 commit into
masterfrom
revert-96008-fix-mutation-part-metadata-version-mismatch

Conversation

@alesapin

@alesapin alesapin commented Feb 18, 2026 •

Copy link
Copy Markdown
Member

Reverts #96008

This PR replace LOGICAL_ERROR with potential dataloss.

Version info

  • Merged into: 26.2.1.939

@clickhouse-gh

clickhouse-gh Bot commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8534e13]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_msan, 2/6) failure
test_hedged_requests/test.py::test_stuck_replica FAIL cidb, issue ISSUE CREATED
Performance Comparison (amd_release, master_head, 1/6) failure
Select historical data failure IGNORED
Performance Comparison (amd_release, master_head, 2/6) failure
Select historical data failure IGNORED
Performance Comparison (amd_release, master_head, 3/6) failure
Select historical data failure IGNORED
Performance Comparison (amd_release, master_head, 4/6) failure
Select historical data failure IGNORED
Performance Comparison (amd_release, master_head, 5/6) failure
Select historical data failure IGNORED

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 18, 2026
@alesapin
alesapin added this pull request to the merge queue Feb 19, 2026
Merged via the queue into master with commit e0dea43 Feb 19, 2026
137 of 143 checks passed
@alesapin
alesapin deleted the revert-96008-fix-mutation-part-metadata-version-mismatch branch February 19, 2026 16:15
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 19, 2026
@serxa serxa added the post-approved Approved, but after the PR is merged. label Mar 18, 2026
pull Bot pushed a commit to Haofei/ClickHouse that referenced this pull request Jul 31, 2026
A part stores its metadata version on disk in metadata_version.txt and keeps it
verbatim when it is fetched from another replica (DataPartsExchange.cpp:264-266).
A replica's table metadata version, in contrast, only advances through
setTableStructure (StorageReplicatedMergeTree.cpp:1822), whose only caller is
executeMetadataAlter (:6731), so it advances only when that replica executes its
own ALTER_METADATA queue entry.

A replica can therefore hold a fetched part at metadata version 1, containing a
column the replica does not know about yet, while its own snapshot is still at
version 0. A plain data mutation such as ALTER DELETE carries alter_version = -1,
so isAlterMutation() is false and the alter_sequence gating in
shouldExecuteLogEntry does not apply to it. splitAndModifyMutationCommands then
iterates the part's columns, finds one that is absent from the table snapshot and
throws LOGICAL_ERROR at MutateTask.cpp:510, which aborts the server in debug and
sanitizer builds. The soft path just above it only covers the opposite ordering,
where the part is older than the table and the column was genuinely dropped.

This is a gap between the two subclasses of ReplicatedMergeMutateTaskBase.
MergeFromLogEntryTask::prepare already refuses to run in exactly this state
(MergeFromLogEntryTask.cpp:186-196, "ALTER_METADATA is still in progress"); the
mutation path had no equivalent. Add the same rule for MUTATE_PART entries in
ReplicatedMergeTreeQueue::shouldExecuteLogEntry, so such an entry is postponed
until the pending ALTER_METADATA is applied, after which the mutation runs
normally.

The queue predicate is used rather than MutateFromLogEntryTask::prepare so that
nothing is reserved or locked before bailing out: prepare would already have
built a FutureMergedMutatedPart, reserved disk, taken a table lockForShare,
inserted a MergeListEntry and, under zero-copy replication, possibly taken a
zero-copy lock. Writing the reason through LogToStr also surfaces it in
system.replication_queue.postpone_reason.

MutateTask.cpp is deliberately unchanged. The assertion keeps its full meaning
and the equal-versions case still throws, so this is not the soft-keep direction
of ClickHouse#96008, which was reverted in ClickHouse#97301 as a data-loss risk. ClickHouse#102349 reached the
same placement and was closed by its own author.

The guard is unconditional, matching the merge sibling, so it inherits that
guard's liveness assumption that some ALTER_METADATA eventually applies. Every
producer of the mismatch keeps or plants one, including the dummy_alter entry
that the recovery path synthesizes (StorageReplicatedMergeTree.cpp:3966-3976).

Closes: ClickHouse#91015

Co-Authored-By: Claude Fable 5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 15, 2026
`splitAndModifyMutationCommands` tolerated a part column that the table no
longer has only when the part was behind the table's metadata version, or when
it carried no metadata version on disk at all. `ATTACH`/`REPLACE PARTITION FROM`
and `MOVE PARTITION TO TABLE` stamp the destination's metadata version on a part
that keeps the source's `columns.txt` (`metadata_version_to_write` in
`executeReplaceRange`, `replacePartitionFromImpl` and `movePartitionToTable`)
and require matching structures, so a partition cloned out of a table that had
dropped the column arrives with `part_metadata_version ==
table_metadata_version` and a column that is in no schema at all. That reached
the logical error, which is an abort on a debug or sanitizer build, and the
`MUTATE_PART` entry replays from Keeper after the restart.

The throw is kept for `part_metadata_version > table_metadata_version`, where
the replica is behind an `ALTER ADD COLUMN` and the column is real data: that is
the case ClickHouse#96008 turned into a logical error and ClickHouse#97301 reverted as "replace
LOGICAL_ERROR with potential dataloss", and `ReplicatedMergeTreeQueue` now
postpones the mutation before it can get here.

The test gains a `ReplicatedMergeTree` arm and a cloned-partition arm, and drops
`no-shared-merge-tree`: with the change every arm takes the version comparison,
which does not consult `supportsReplication()`. Measured on debug builds, per
arm (`MergeTree` / `ReplicatedMergeTree` / cloned by `ATTACH PARTITION FROM`):

    master @ 45efaa4  FAIL / FAIL / FAIL   Code: 47, retried forever
    this branch, no fix     OK   / OK   / ABORT  signal 6, split... -> prepare
    this branch             OK   / OK   / OK     part-vs-table mv 0/0, 1/2, 0/0

Reported on the PR, with the repro and the one-line diff, by Avogar.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-approved Approved, but after the PR is merged. pr-not-for-changelog This PR should not be mentioned in the changelog 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