Repository navigation
Wait unfinished rename column alter mutation - #112783
Conversation
|
Workflow [PR], commit [531388a] Summary: ✅
AI ReviewSummaryThis PR serializes later Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code |
| disable_failpoint | ||
| ${CLICKHOUSE_CLIENT} --query="DROP TABLE t_rename_no_default_dynamic" | ||
|
|
||
| # Phase 3: the opposite direction - the keep-alive must not over-apply. The old name is re-added |
There was a problem hiding this comment.
this will not work after this patch, because the second alter
ALTER TABLE t_rename_no_default_reuse ADD COLUMN a String DEFAULT 'reused_default' SETTINGS alter_sync = 0;
will hang since for regular MT we do not have an alter sequence materialized on disk.
| int64_t mutation_to_wait = 0; | ||
| { | ||
| std::lock_guard lock(currently_processing_in_background_mutex); | ||
| for (const auto & [version, mutation_entry] : current_mutations_by_version | std::views::reverse) |
There was a problem hiding this comment.
This only serializes separate ALTERs. The original invariant is still violated inside one multi-command ALTER, so the stale-column path from #109957 stays reachable.
AlterCommand::tryConvertToMutationCommand applies each subcommand to the working metadata as it goes, so ALTER TABLE ... RENAME COLUMN a TO b, DROP COLUMN b, ADD COLUMN b UInt64 SETTINGS alter_sync = 0 is accepted and produces the same RENAME_COLUMN a -> b + DROP_COLUMN b sequence that used to come from multiple statements (src/Storages/AlterCommands.cpp:1357). AlterConversions then keeps rename_map = { b <- a } and dropped_columns = { b } (src/Storages/MergeTree/AlterConversions.cpp:167), but the reader rewrites logical b back to physical a before checking isColumnDropped, so the drop of b no longer hides the old a bytes (src/Storages/MergeTree/IMergeTreeReader.cpp:355, src/Storages/MergeTree/MergeTreeBlockReadUtils.cpp:105).
So this wait closes the two-statement reproducer, but the same rename/drop/re-add sequence is still legal in one statement. We need either to reject/rewrite same-statement reuse of the rename target as well, or to propagate DROP COLUMN b backwards through the rename map so the source a is treated as dropped when b is re-added.
|
Hi @Michicosun, does this PR also fix this #109860? |
…me-mutation barrier Since ClickHouse#112783, any `ALTER` on `StorageMergeTree` waits for a pending `RENAME COLUMN` barrier mutation regardless of `alter_sync`, so keeping the rename mutation pending with `SYSTEM STOP MERGES` and then issuing `MODIFY COLUMN` deadlocks until `max_execution_time` (the `Fast test` timeout). Wait for the rename synchronously instead, and keep only the `Nullable` to non-`Nullable` type-conversion mutation pending, which is the part of the scenario that exercises the matcher-expanded `DEFAULT` conversion on reads and mutations.
Hi! @RinChanNOWWW, no, it should not; we need both fixes. |
… as a single ALTER Since ClickHouse#112783, a metadata ALTER on plain MergeTree waits for a pending barrier (`RENAME COLUMN`) mutation to finish, so the sequential `RENAME`/`DROP`/`ADD` statements under `SYSTEM STOP MERGES` blocked forever and the pending on-the-fly state could never be observed. Issue the three commands as a single ALTER instead: it creates the same pending rename map and drop set without a preceding barrier mutation to wait for. Co-Authored-By: Claude Fable 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
This pr fixes an alter application for regular merge tree storage. Now, alter will not be applied while there is an incomplete rename-column alter-mutation, because it may update storage metadata in an incompatible way, which will block mutations completely.
The solution is similar to RMT but less strict, because RMT does not execute alters unless there is another non-complete alter-mutation with a smaller metadata version.
Fixes: #109957