Repository navigation
Revert "Fix logical error when fetched part has newer metadata version than table" - #97301
Merged
alesapin merged 1 commit intoFeb 19, 2026
Merged
Conversation
Contributor
|
Workflow [PR], commit [8534e13] Summary: ❌
|
alesapin
deleted the
revert-96008-fix-mutation-part-metadata-version-mismatch
branch
February 19, 2026 16:15
1 task done
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.
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.
Reverts #96008
This PR replace LOGICAL_ERROR with potential dataloss.
Version info
26.2.1.939