Repository navigation
Write a patch part at the table's metadata version - #119144
Conversation
The synthetic metadata that describes a patch part's own structure carries no metadata version, so the part was written at version 0 - behind every metadata mutation there has ever been. The replicated queue hands a part every metadata command with a greater alter version, so a `RENAME COLUMN` whose materialization was still pending was applied to a patch written after it: the patch was then looked up under the column's old name, the new name is what it stores, and the lightweight update it carries was silently missing from the result until the rename materialized. Closes: #116733
|
Workflow [PR], commit [a3549b1] Summary: ✅
AI ReviewSummaryThis PR propagates the correct metadata version through foreground patch writes, patch-part compaction, and empty patch-part builders, so pending Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit a3549b1.
Changed lines: Changed C/C++ lines covered: 37/38 (97.37%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (+43.30 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units242 translation units recompiled, 2659 s compile time in total, 242 of them have a recent master baseline. |
A merge of patch parts took the metadata of the merged patch from the first source part's `getMetadataSnapshot`, which for a patch part is the synthetic metadata of the patch's structure, shared by every patch of that structure and carrying no metadata version. The merged patch was therefore written at version 0 again, and on `ReplicatedMergeTree` a `RENAME COLUMN` that had not materialized yet was re-applied to it on read, so the lightweight updates it carried became invisible until the rename materialized: the same failure this pull request fixes for a freshly written patch, brought back by the first background compaction of the patches. The merged patch is now stamped with the lowest metadata version among its sources. A rename of a column that a patch stores puts the patches written before and after it in different partitions, so the sources of one merge are all on the same side of every such rename, and the lowest of their versions is also what the mutations snapshot of the merge takes for `min_part_metadata_version`. The test gains a third table: a pending rename, two updates, an explicit `OPTIMIZE` of the patch partition, and the sum checked before and after the rename materializes. `max_replicated_mutations_in_queue = 0` keeps the merge selector from scheduling the rename's mutation while the `OPTIMIZE` still goes through, so no failpoint and no `no-parallel` tag is needed. Without the fix the case reads 0 instead of 600 while the rename is pending. The test is renumbered to `05227` after the merge with master. Addresses the review thread on the compaction path: #119144 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]>
A patch of the old `a` and of a re-added `a` after `RENAME COLUMN a TO b, ADD COLUMN a` share a patch partition, so the claim that all sources of a patch merge are on the same side of every rename did not hold. That case is already wrong for ordinary parts (#122146) and is not made worse here. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…their source `createEmptyPartInsteadOfLost`, the empty covering part of `DROP`/`REPLACE PARTITION`, and the empty parts of `StorageMergeTree` built a patch empty from `IMergeTreeDataPart::getMetadataSnapshot`, whose synthetic patch-part metadata carries version 0. Once such an empty patch compacted with real patches, the `min` in `mergePartsToTemporaryPart` dropped the merged patch back to version 0 and a pending `RENAME COLUMN` was applied to it on read again. Take the version of the source part instead, through the new `MergeTreeData::getMetadataSnapshotForEmptyPart`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@alexey-milovidov, the opposite order still loses the update with this PR: an CREATE TABLE t (x UInt32, v UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/t', '1') ORDER BY tuple()
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1, apply_patches_on_merge = 0, max_replicated_mutations_in_queue = 0;
INSERT INTO t VALUES (1, 1);
UPDATE t SET v = 5 WHERE 1;
ALTER TABLE t RENAME COLUMN v TO w SETTINGS alter_sync = 0;
SYSTEM SYNC REPLICA t;
SELECT w FROM t; -- 5
OPTIMIZE TABLE t FINAL;
SELECT w FROM t; -- 1, expected 5
ALTER TABLE t MODIFY SETTING max_replicated_mutations_in_queue = 16;
-- once the RENAME mutation is done:
SELECT w FROM t SETTINGS apply_patch_parts = 0; -- 1, the update is gone from disk
The merged part is written at metadata version 1, while the patch stays at 0 and stores Should this go into this PR, or should I send it as a follow-up once this PR is merged? |
|
🕵 @groeneai, thanks for the reproducer. The analysis looks right to me: once the merged base part is at version 1, the snapshot's Please send it as a follow-up after this PR is merged, and keep this PR scoped to #116733. Your case also fails on master, so it is a separate bug, and the fix has an upgrade problem that deserves its own review:
A test along the lines of your reproducer (with |
|
Acknowledged. I'll send it as a separate follow-up PR after this one is merged, handling the legacy version-0 patches and the merge path, and link it here. |
|
Follow-up as requested in #119144 (comment): #124653. A version-0 patch gets a finished rename only if its data predates the rename mutation, and the merge path passes its patch versions to the snapshot. |
…ses the rename On ReplicatedMergeTree, a merge writes the merged part at the current metadata version. Every mutations snapshot took its ALTER bound from the base parts only, and ReplicatedMergeTreeQueue::getMutationsSnapshot dropped every ALTER entry at or below that bound. A patch part written before a RENAME COLUMN still stores the old name and needs the rename, but once every base part had passed it the snapshot no longer carried it: reads looked the new name up in the patch and found nothing, and the rename's own MUTATE_PART skipped the patch column, after which the patch was dropped as unused. With apply_patches_on_merge = 1 a merge of parts already at the new version consumed the patch the same way. The snapshot now lowers its ALTER bound by the metadata versions of the patch parts it is applied with: those fetched in getMutationsSnapshot (read path, MutateTask) and the patches of a merge (MergeTask, new Params::min_patch_metadata_version). ALTERs that every base part has passed are kept with their RENAME and DROP COLUMN commands only and are given to a patch only when the patch has not passed them. Patches written before patches carried a metadata version are all at version 0, also those written after the rename (they already store the new name), so for a patch at version 0 the rename applies only if the patch's data predates the rename's mutation version; block numbers of patches and mutation versions come from the same per-partition sequence. Entries above the base bound are handled exactly as before. The test also covers an UPDATE by the old name on a replica that has not applied the rename yet, whose patch carries the metadata version from before the rename. Follow-up of ClickHouse#119144 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
On
ReplicatedMergeTree, a lightweightUPDATEof a column whoseRENAME COLUMNmutation is still unmaterialized was acknowledged and then silently invisible: reads returned the pre-update values until the rename finished materializing on every part of the snapshot.RENAME COLUMNreturns before that (defaultalter_sync = 0), so any update issued in that window lost read-your-writes, with no error and nothing in the log.A patch part is written with the synthetic metadata that describes the patch's own structure, which carries no metadata version, so the part landed at version 0 - behind every metadata mutation there has ever been.
ReplicatedMergeTreeQueue::MutationsSnapshot::getOnFlyMutationCommandsForPartgates a metadata command onalter_version > part_metadata_version, so the still-queuedRENAME COLUMNwas applied to a patch written after it:AlterConversions::getPatchesForColumnsthen mapped the new name back to the old one, the patch (which physically stores the new name) had no such column, and the patch was skipped for it. PlainMergeTreegates its on-fly commands by data version, which is why it was unaffected.The patch part is written against the table as it is at that moment, so it is now stamped with the table's metadata version. A rename that predates the patch is no longer applied to it, and one that follows the patch still is.
The compaction of patch parts rewrote them from the same synthetic metadata and lost the version again, so a background merge of the patches brought the updates' invisibility back. A merged patch is now stamped with the lowest metadata version among its sources: they all share the patch's structure, so they are on the same side of every rename of a column the patch stores, and that is also the version the merge's mutations snapshot already uses.
Closes: #116733
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed an acknowledged lightweight
UPDATEbeing invisible onReplicatedMergeTreewhen it targets a column whoseRENAME COLUMNmutation has not materialized yet.Workflow [PR]
Sync PR [sync-upstream/pr/119144]
Version info
26.10.1.1781-master(included in26.10and later)