Repository navigation
Fix flaky 03518_alter_logical_race: unthrottle the MODIFY COLUMN mutation - #108060
Conversation
…tion
The test stresses concurrent `ALTER`/`INSERT` against a `ReplicatedMergeTree`
table. Its `MODIFY COLUMN ... UInt64` step is a data-rewriting mutation, and on a
busy CI host that mutation gets starved by the two MergeTree throttles that defer
mutations in favour of merges: `max_replicated_mutations_in_queue` (default 8) and
`number_of_free_entries_in_pool_to_execute_mutation` (default 20). Under the test's
heavy concurrent `INSERT` load there are always merges to do, so the data part of
the very first `MODIFY` never gets a turn.
Replicated metadata alters must finish in strict version order, and an alter does
not leave the alter-version chain until its data mutation completes. So a starved
data mutation at the head of the chain blocks every later `MODIFY`'s metadata
change, which then waits (with the default `alter_sync = 1`) until the table is
dropped at teardown. The `timeout` wrapping each statement fires first and fails
the test with a spurious `TIMEOUT` / `NO ALTER PROGRESS`, even though nothing is
hung - the mutation just never gets scheduled.
The server log of the failing run shows this exactly: mutation `0000000000` (alter
version 3) is created but never executes ("won't select new parts to merge or
mutate" because queued mutations reached `max_replicated_mutations_in_queue (8)`),
and the next `MODIFY`'s metadata entry is rejected 309044 times with "Cannot
execute alter metadata ... because another alter 3 must be executed before".
Raise `max_replicated_mutations_in_queue` and set
`number_of_free_entries_in_pool_to_execute_mutation = 0` on the test table so the
data mutation is no longer deferred. The two `ALTER` workers issue their `MODIFY`s
synchronously, so in-flight mutations stay naturally low; this only removes the
head-of-chain stall. Verified by running the test repeatedly under saturating CPU
load: it now completes real `ALTER` cycles in ~12-15s instead of hanging to the
180s hard cap.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2a3a502d2ed0af65bb0a5c91223c91c1b2e28047&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [823f09f] Summary: ✅ AI ReviewSummaryThis PR is a test-only CI fix for Final VerdictStatus: ✅ Approve No inline findings to post. I did not run the stateless test locally because this checkout has no |
| $CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS alter_table" | ||
| $CLICKHOUSE_CLIENT -q "CREATE TABLE alter_table (a UInt8, b UInt8, c UInt8, d UInt8, e UInt8, f UInt8, g UInt8) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_03518/alter_table', 'r1') ORDER BY a PARTITION BY b % 10 SETTINGS old_parts_lifetime = 1" | ||
| # `max_replicated_mutations_in_queue` and `number_of_free_entries_in_pool_to_execute_mutation` | ||
| # both defer the data-rewriting mutation that `MODIFY COLUMN ... UInt64` creates, in favour of |
There was a problem hiding this comment.
It's a comment pretty much from the AI to AI.
A short description would be more useful. Nobody reads such comments.
There was a problem hiding this comment.
Done in 823f09f — replaced the long explanation with a short description (kept the CI report link).
| # `MODIFY`s synchronously, so in-flight mutations stay naturally low; disabling these throttles only | ||
| # removes the head-of-chain stall, it does not let mutations pile up. See | ||
| # https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2a3a502d2ed0af65bb0a5c91223c91c1b2e28047&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 | ||
| $CLICKHOUSE_CLIENT -q "CREATE TABLE alter_table (a UInt8, b UInt8, c UInt8, d UInt8, e UInt8, f UInt8, g UInt8) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_03518/alter_table', 'r1') ORDER BY a PARTITION BY b % 10 SETTINGS old_parts_lifetime = 1, max_replicated_mutations_in_queue = 100000, number_of_free_entries_in_pool_to_execute_mutation = 0" |
There was a problem hiding this comment.
A nice trick is structured SQL heredoc
Easier to understand diffs in long queries
| $CLICKHOUSE_CLIENT -q "CREATE TABLE alter_table (a UInt8, b UInt8, c UInt8, d UInt8, e UInt8, f UInt8, g UInt8) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_03518/alter_table', 'r1') ORDER BY a PARTITION BY b % 10 SETTINGS old_parts_lifetime = 1, max_replicated_mutations_in_queue = 100000, number_of_free_entries_in_pool_to_execute_mutation = 0" | |
| $CLICKHOUSE_CLIENT << SQL | |
| CREATE TABLE alter_table (a UInt8, b UInt8, c UInt8, d UInt8, e UInt8, f UInt8, g UInt8) | |
| ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_03518/alter_table', 'r1') | |
| ORDER BY a | |
| PARTITION BY b % 10 | |
| SETTINGS old_parts_lifetime = 1, | |
| max_replicated_mutations_in_queue = 100000, | |
| number_of_free_entries_in_pool_to_execute_mutation = 0 | |
| SQL |
There was a problem hiding this comment.
Done in 823f09f — rewrote the CREATE TABLE as a structured SQL heredoc as suggested. Thanks!
Per @Felixoid's review on PR #108060: - Replace the long explanatory comment above the `CREATE TABLE` with a short description (the verbose version read as "AI to AI"; nobody reads it). - Rewrite the `CREATE TABLE` as a structured SQL heredoc so the settings and clauses produce a readable diff. No behavior change: the `ReplicatedMergeTree` definition and the `max_replicated_mutations_in_queue` / `number_of_free_entries_in_pool_to_execute_mutation` settings are identical. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 523 line(s), 30 function(s) across 135 file(s) · Details Top files
|
The test fails on Stateless tests (amd_debug, parallel) with TIMEOUT: ALTER TABLE alter_table DROP COLUMN h NO ALTER PROGRESS: completed zero full ALTER ADD/MODIFY/DROP cycles i.e. its own progress guard firing because no ALTER worker completed a cycle. DROP COLUMN and MODIFY COLUMN on a physical column require a data mutation (AlterCommands.cpp isRequireMutationStage), and StorageReplicatedMergeTree::alter waits for it. A replicated mutation only advances when the merge-selecting task creates a MUTATE_PART entry per part, but try_assign_merge attempts a regular merge FIRST and returns AttemptStatus::EntryCreated at StorageReplicatedMergeTree.cpp:4505, before control reaches the mutation selection block at :4531-4560, then reschedules immediately at :4590-4591. This test's concurrent INSERT stream keeps mergeable ranges permanently available, so every selector pass is spent on a merge and the mutation is starved. In the failing run 2471 MERGE_PARTS entries were created against 44 MUTATE_PART, with the mutation rate decaying from 41 to 0 entries per minute as the part population grew. Strict alter-version ordering (ReplicatedMergeTreeAltersSequence::canExecuteMetaAlter) then prevented the second worker from applying even its DROP's metadata, which is why zero cycles completed rather than one. PR ClickHouse#108060 chased this one layer too shallow: it unpinned the mutation count throttles (max_replicated_mutations_in_queue, number_of_free_entries_in_pool_to_execute_mutation), but a mutation that never reaches the selection block never consults them. Neither limit fired in this run. Disable regular merges for the table instead. max_bytes_to_merge_at_max_space_in_pool = 0 short-circuits getMaxSourcePartsBytesForMerge, so can_assign_merge is false and control falls through to mutation selection on every pass. Mutations are unaffected: that path reads getMaxSourcePartBytesForMutation, a different function. With merges off parts accumulate unmerged, so parts_to_delay_insert and parts_to_throw_insert are raised above the per-partition defaults (1000/3000) to keep the test's INSERT side from being delayed or rejected, which would break the INSERT progress guard. max_parts_in_total (100000, whole-table) is left alone. 04652_mutate_part_ahead_of_table_metadata_version.sh uses the same setting on ReplicatedMergeTree for the same purpose. SYSTEM STOP MERGES is table-scoped and would not need no-parallel, but it is still not usable here: it takes the merges_blocker action lock, and ReplicatedMergeTreeQueue::shouldExecuteLogEntry applies that lock to MUTATE_PART as well as MERGE_PARTS, so it would block the mutation this needs to let through. No assertion is weakened: the test asserts ALTER cycle progress, INSERT progress and an empty reference, and nothing reads system.parts, part counts or merge state. The trade is narrower than "no coverage lost": with merges off this test no longer exercises the merge-side column resolution path (MERGE_PARTS 33152 to 0 over the two 50x arms), while the mutation-side path is exercised 5.7x more (MUTATE_PART 4958 to 28249). The merge arm under concurrent ADD/DROP COLUMN stays covered by 01079_parallel_alter_add_drop_column_zookeeper.sh and 03144_parallel_alter_add_drop_column_zookeeper_on_steroids.sh, which keep merges enabled and additionally force them with OPTIMIZE TABLE ... FINAL. The ALTERs still carry no IF [NOT] EXISTS, so NOT_FOUND_COLUMN_IN_BLOCK or DUPLICATE_COLUMN would still fail the run, and the progress guard keeps full strength. Raising MAX_TIMEOUT was rejected: the starved mutation was decelerating with no bound, and the healthy amd_debug p50 is 11.7s against this run's 182s. Validated on one box under identical load, with only the test file differing: pristine master fails 5/50 under tests/clickhouse-test --test-runs 50, carrying the exact signature above; with this change 50/50 pass on debug and 50/50 on ASAN. p95 drops from 77.5s to 32.7s and no run reaches the 180s hard deadline. Confirmed the settings took effect rather than being silently ignored (0 MERGE_PARTS and 28249 MUTATE_PART entries across the 50 debug runs, 0 and 23359 on ASAN) and that no Too many parts or insert delay line appeared in either. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111534&sha=b8c37b85647510a9b374b77fadaeeddd8ab957f5&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
Per @Felixoid's review on PR ClickHouse#108060: - Replace the long explanatory comment above the `CREATE TABLE` with a short description (the verbose version read as "AI to AI"; nobody reads it). - Rewrite the `CREATE TABLE` as a structured SQL heredoc so the settings and clauses produce a readable diff. No behavior change: the `ReplicatedMergeTree` definition and the `max_replicated_mutations_in_queue` / `number_of_free_entries_in_pool_to_execute_mutation` settings are identical. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…mutation-starvation Fix flaky 03518_alter_logical_race: unthrottle the MODIFY COLUMN mutation
…erges `PARTITION BY b % 10` with a per-row `rand(2)` made every 1000-row INSERT write 10 parts. ClickHouse#114028 disabled regular merges for this table so that merges stop starving the ALTER's mutation, which removed the only bound on the part count: each later ALTER mutation then has to rewrite every part inserted before it, at one MUTATE_PART entry per merge-selecting pass, and the last one of the chain can exceed the 120 s client timeout (`TIMEOUT: ALTER TABLE alter_table DROP COLUMN i` on arm_binary, with 2419 and 1178 parts to rewrite in the two failing runs). Both failure modes come from the 10-parts-per-INSERT rate, so cut it at the source: `randConstant(2)` puts every INSERT into one partition (one part per INSERT) while successive INSERTs still spread over all 10 partitions, and regular merges are re-enabled by dropping max_bytes_to_merge_at_max_space_in_pool, parts_to_delay_insert and parts_to_throw_insert. The ClickHouse#108060 throttle overrides stay, as do the deadlines and the progress guards. Local server with the CI test config, master file vs this change: 10.0 vs 1.0 parts per INSERT; slowest ALTER p95 66.5 s vs 5.6 s at -j4; on the release build at -j10, 1/100 TIMEOUT vs 0/100 and 107 s vs 6.6 s. The pre-ClickHouse#114028 file fails 14/50 at -j24 with NO ALTER PROGRESS; this change passes 50/50 there and 50/50 on ASAN. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flaky test
03518_alter_logical_racestresses concurrentALTER/INSERTagainst aReplicatedMergeTreetable. ItsMODIFY COLUMN ... UInt64step is a data-rewriting mutation. On a busy CI host (it fails onStateless tests (arm_binary, parallel), ~7 times/day on master) that mutation gets starved by the two MergeTree throttles that defer mutations in favour of merges:max_replicated_mutations_in_queue(default 8) andnumber_of_free_entries_in_pool_to_execute_mutation(default 20). Under the test's heavy concurrentINSERTload there are always merges to run, so the data part of the very firstMODIFYnever gets a turn.Replicated metadata alters must finish in strict version order, and an alter does not leave the alter-version chain until its data mutation completes. So a starved data mutation at the head of the chain blocks every later
MODIFY's metadata change, which then waits (with the defaultalter_sync = 1) until the table is dropped at teardown. Thetimeoutwrapping each statement fires first and fails the test with a spuriousTIMEOUT/NO ALTER PROGRESS, even though nothing is hung — the mutation just never gets scheduled.The server log of the failing run shows this exactly: mutation
0000000000(alter version 3) is created but never executes (won't select new parts to merge or mutatebecause queued mutations reachedmax_replicated_mutations_in_queue (8)), and the nextMODIFY's metadata entry is rejected 309044 times withCannot execute alter metadata ... because another alter 3 must be executed before.The fix raises
max_replicated_mutations_in_queueand setsnumber_of_free_entries_in_pool_to_execute_mutation = 0on the test table so the data mutation is no longer deferred. The twoALTERworkers issue theirMODIFYs synchronously, so in-flight mutations stay naturally low; this only removes the head-of-chain stall, it does not let mutations pile up. Verified by running the test repeatedly under saturating CPU load: it now completes realALTERcycles in ~12–15s instead of hanging to the 180s hard cap.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2a3a502d2ed0af65bb0a5c91223c91c1b2e28047&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not for changelog — fixes flakiness of the stateless test
03518_alter_logical_race.Documentation entry for user-facing changes
🤖 Generated with Claude Code