Repository navigation
Conversation
|
This is yet another attempt (at least 3rd) to have mutations local for partitions they affect. |
|
Note: when you execute
|
1043c4d to
67b259c
Compare
|
This is an automated comment for commit a1053ab with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page
Successful checks
|
|
Note to self (or other reviewers): the ultimate goal is to avoid changing any aspect of parts that would not be affected by a mutation, which means avoiding changing file names too. |
b407fb6 to
615b972
Compare
5aa8dcc to
219f5ee
Compare
|
Hi @ilejn ! I hope this message finds you well. I've been following the progress of this PR and I'm excited about the changes it brings. I was wondering if you could give an estimate on when we might expect these changes to be included in the stable release? Thanks! |
@mrodonnpaw , it is a rather problematic thing, I cannot provide reliable estimations. |
|
Hello @ilejn! Any news about this? |
|
It could probably break some invariants. Ask @tavplubix for details. |
|
Yes, we discussed it with @filimonov and, afair, we found a solution, but it was a long time ago and I forgot the context |
edfe9c8 to
7721f15
Compare
77745cf to
d4703ff
Compare
Hello @tavplubix ,
|
|
🕵 @alesapin, revisiting your concern: this branch still relies on |
The test added in the previous commit timed out in `Fast test` (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=48941&sha=7b425e7b69c94f990b483995c89089cb72375b23&name_0=PR&name_1=Fast%20test), and its reference file contained a literal `\t` instead of a tab. Two hangs: - `ALTER TABLE ... CLEAR COLUMN ... IN PARTITION` goes through `StorageReplicatedMergeTree::alter`, which waits for the created mutation with `alter_sync` (default `1`). With `SYSTEM STOP MERGES` in effect the mutation can never finish, so the statement waited forever. Issue it with `alter_sync = 0`. - `ALTER TABLE ... MODIFY COLUMN p Int8 SETTINGS alter_sync = 2` could not complete either: the replication queue postpones the `ALTER_METADATA` entry with "Cannot execute alter metadata ... because another alter 1 must be executed before", and the data mutation of that previous alter (the pending `CLEAR COLUMN`) is blocked by the stopped merges. A `CLEAR COLUMN` therefore cannot be kept pending across a partition key type change at all, so the test no longer tries to; executing a pending entry across such a change is already covered by `04702` and `04847`. What is left is exactly what the source change does: the entry created by `StorageReplicatedMergeTree::alter` is scoped with `IN PARTITION ID`, which the test now asserts both in `system.mutations` and in the raw `/mutations` znode, before letting the mutation execute and checking the data. Also added the tags required by the fixture (`zookeeper`, `no-replicated-database`, `no-shared-merge-tree`, `no-shared-catalog`): the `SYSTEM STOP MERGES` must hold on the only replica that could execute the mutation, and the znode path is inspected directly.
Build profile diff (arm_release)Comparing commit See the job log for details. |
…n_mutations Resolved against the mutation partition-pruning feature that landed on master: - `MergeTreeData::getPartitionIdsAffectedByCommands` now comes from master (predicate pruning, multi-partition `IN PARTITION p1, p2`, the `analyzed_partition_ids` contract), together with `getPartitionIdsPrunedByPredicate`. The version of this branch is dropped, and `StorageReplicatedMergeTree::allocateBlockNumbersInAffectedPartitions` keeps master's implementation, which already locks only the affected partitions and no longer needs the filtering this branch added. - `resolvePartitionIdsForCommands` (this branch) is kept for the non-replicated per-command scope. A command listing several partitions cannot be pinned to a single `resolved_partition_id`, so it makes the mutation global; it is still executed only in its partitions through the `_partition_id IN (...)` predicate built by `getPartitionAndPredicateExpressionForMutationCommand`. - The per-partition completion check of this branch moved into master's new `StorageMergeTree::markFinishedMutations`, so `finish_time` stamping is preserved: the global minimum part data version cannot bound the finished mutations when a mutation is scoped to a subset of partitions, so every entry is checked against the parts of the partitions it affects (helpers `getSortedPartVersions` and `hasPartsToMutate`, shared with `getUnfinishedMutationCommandsUnlocked`).
…nged The persisted partition scope was stored in an extra `partition ids:` line of `mutation_*.txt` while `format version: 1` stayed the same, and `loadMutations` rewrote legacy files into that shape. A binary without this feature reads `commands` and then expects `tid:`/EOF, so after such a file was written or upgraded, downgrading made the table unloadable. The scope is now pinned into the command text itself, exactly like on the `ReplicatedMergeTree` path: `rewritePartitionScopeToIds` rewrites `IN PARTITION <value>` into `IN PARTITION ID '<id>'` and returns the affected partitions of the entry, so `resolvePartitionIdsForCommands` is gone and the file keeps the shape it always had. A partition id is decoded without the partition key, so re-parsing the file after a key-safe partition key type change still works, and the upgraded file remains readable by an older binary. `MergeTreeMutationEntry` therefore no longer writes or parses the extra line (neither on disk nor in the backup entry), and it recognizes a legacy file by a command that still carries an `IN PARTITION <value>` literal (`MergeTreeData::hasUnresolvedPartitionScope`). Tests `04846` and `04701` now check the pinned command text instead of the removed line, and the `02241` reference is back to the master value: the mutation file is no longer 20 bytes larger.
…`clang-tidy` `Style check` failed on `server_data_manipulation_in_stateless_tests`: `04846_legacy_partition_mutation_file_upgrade.sh` fetched the table data path from `system.tables` and ran `sed -i` on the real `mutation_*.txt` file. The stateless suite runs against arbitrary server configurations (object storage, shared MergeTree, encrypted disks) where that file either does not exist or does not mean what the test assumes, so the scenario is moved verbatim to `test_mutations_in_partitions_of_merge_tree` as `test_legacy_mutation_file_partition_scope_upgrade`. `Build (arm_tidy)` failed with `modernize-loop-convert` on the iterator loop in `StorageMergeTree::markFinishedMutations`; it is now a range-based loop over structured bindings.
# Conflicts: # src/Storages/StorageMergeTree.cpp
… master The PR changed its parameter from `MutationCommand::Type` to `const MutationCommand &` for a `CLEAR COLUMN` distinction that is no longer made in the body, while master added two new callers with the original signature in `StorageMergeTree::getMutationVersionForMergedPart`. Restore the original signature (the comment is kept) instead of touching the new callers. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…, p2` carrier too `ALTER TABLE ... UPDATE/DELETE ... IN PARTITION p1, p2 WHERE ...` stores its partitions in `ASTAlterCommand::partitions`, which `rewritePartitionScopeToIds` ignored: such a mutation was treated as global (so on plain `MergeTree` every unrelated part was still cloned to the new mutation version) and its partition literals were never rewritten to `IN PARTITION ID`, so a pending multi-partition mutation could not survive a key-safe partition key type change. `MutationCommand::resolved_partition_id` becomes `resolved_partition_ids`, a set covering both carriers. `rewritePartitionScopeToIds` rewrites every listed partition to its id and returns the union for `partition_ids`; `hasUnresolvedPartitionScope` and `pinPartitionScopeOfLegacyCommands` recognize the multi-partition carrier as well; `canSkipMutationCommandForPart`, `isStorageTouchedByMutations` and `getPartitionAndPredicateExpressionForMutationCommand` use the pinned set instead of decoding the literals again. Tests: `05218_partition_mutation_multi_partition_scope` (plain `MergeTree`: the part of the unlisted partition keeps its name, and a pending multi-partition mutation survives `Enum8 -> Int8` across `DETACH`/`ATTACH`) and `05219_partition_mutation_multi_partition_scope_replicated` (the `ReplicatedMergeTree` counterpart). Co-Authored-By: Claude Fable 5.1 <[email protected]>
…tion-scoped mutations exist New mutation entries pin their `IN PARTITION` scope as partition ids at creation, and legacy entries (written before that) are upgraded at load where possible: a plain `MergeTree` file is rewritten, and a single-partition `ReplicatedMergeTree` entry recovers its scope from its block numbers. Two legacy shapes have no such path: a file on a read-only / write-once disk, and a replicated entry spanning several partitions (its znode stores no per-command scope, so every replica that loads it later has to decode the literals through the current partition key). After a key-safe partition key type change (e.g. `Enum8 -> Int8`) their literals become undecodable, which can make the table unloadable. Enforce a fail-closed compatibility policy instead: `MergeTreeData::checkAlterIsPossible` rejects a type change of a partition key column with `ALTER_OF_COLUMN_IS_FORBIDDEN` while such entries exist (`getMutationsWithLegacyPartitionScope`, implemented for both engines), naming the entries and telling the user to wait for them or `KILL MUTATION`. Entries with a recoverable scope do not block the change (`04847` keeps passing). Test: `05220_partition_mutation_legacy_multi_partition_znode_key_change` fabricates a legacy multi-partition znode, checks the change is refused while the entry is pending, and accepted again after the mutation is killed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Status update, 2026-09-15 (head
|
…n_mutations Conflicts: - MergeTreeMutationEntry.cpp: master replaced TransactionLog.h with TransactionManager.h; kept that plus the PR's ASTAlterQuery.h. - test_transactions/test.py: master changed the removal TID format to include a trailing ',0'; kept the PR's expectations (no _7 parts in partition 0) with the new TID format.
`05218`: `SYSTEM STOP MERGES` does not survive `DETACH`/`ATTACH`, so the pending `DELETE` could already be done when `system.mutations` was queried with `NOT is_done`. Select it by its command instead. `05219`: the block numbers in the part names depend on insert retries (Keeper fault injection), e.g. `3_1_1_0` instead of `3_0_0_0`. Check only whether each partition's part carries a mutation version. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=48941&sha=ffe59a5e0cf8d2c6f77449b2bcaee76ec0e63c43&name_0=PR Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
With partition-scoped mutations a later mutation of one partition can finish while an earlier mutation of another partition is still pending. `markFinishedMutations` stopped at the first unfinished entry, so such a mutation was never marked done, stayed in `mutation_counters` and could never be removed by `clearOldMutations`. Keep scanning past unfinished entries, and make `clearOldMutations` delete the oldest finished entries instead of the first N entries of the map. Test `05241`: a pending mutation of partition 1 no longer keeps finished later mutations of partition 2 from being cleaned up according to `finished_mutations_to_keep`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…heck `StorageReplicatedMergeTree::getMutationsWithLegacyPartitionScope` only consulted the local mutation set, which is refreshed asynchronously, and `alter` does not pull it for a `MODIFY COLUMN`. A replica with a stale view could accept a partition key type change while a legacy multi-partition znode was already in `/mutations`. Load the new entries from ZooKeeper first (this fails closed with `ABORTED` while log pulling is stopped). Test `05242`: the second replica has not loaded the legacy entry, and still does not accept the change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… parentheses Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Status update (pushed
All 15 PR stateless tests pass locally 3 times each. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/48941/ffe59a5e0cf8d2c6f77449b2bcaee76ec0e63c43/pr/build_profile_diff/job.log ( |
|
Investigated. The cited red is the pre-fix state of this class and the family fix is already merged, so there is no new PR from me for it. One residual defect I did find while checking does need one, and I will send that separately. The cited log is from 2026-09-16 01:30, on head Fix presence,
Fleet-wide, CIDB The 8th run is the one that needs a separate PR. #96662 at head I will send that as a separate PR: one wall-clock budget for a job's cluster reads, sized from the job timeout, so an exhausted budget raises |
|
The separate PR for that residual is open: #121849 (it gives this job's CI logs cluster reads one shared wall-clock budget derived from the job timeout, so a degraded cluster ends in the green |
|
🕵 Superseded by #123506, which carries all commits of this PR with the original authorship. The latest merge of @groeneai, thanks for the investigation of the Thank you @ilejn for this long-running work! |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improved IN PARTITION mutations in MergeTree family to leave unaffected partitions intact. Especially useful for backups and for remote disks.
Note
Medium Risk
Changes how MergeTree mutations are tracked, selected, and considered during merges/cleanup by introducing per-partition mutation scoping. Risk is moderate because it touches background mutation/merge selection and mutation cleanup logic, which can affect data correctness and cluster stability if edge cases are missed.
Overview
Partition-scoped mutations:
IN PARTITIONmutations are now tracked with an explicit set of affected partition IDs (PartitionIds), carried throughMergeTreeMutationEntry(computed on creation and on load) and checked viaaffectsPartition()so unaffected partitions are skipped during mutation selection, failure reporting, and on-the-fly mutation application.Merge/cleanup behavior updated: Merge predicates now treat mutation versions as equivalent when any intervening mutations don’t apply to the partition (
mutationVersionsEquivalent()), and mutation cleanup (clearOldMutations) avoids deleting entries that are still unfinished for any partition. Partition ID handling is unified across components by replacing variousunordered_set/setusages withPartitionIds(flat_set) and adding new tests covering partition-scoped mutations, merges, and cleanup.Written by Cursor Bugbot for commit f5ade70. This will update automatically on new commits. Configure here.
Workflow [PR]
Sync PR [sync-upstream/pr/48941]