Repository navigation
Check the query cancellation while filling system.parts and its siblings - #113909
Conversation
The tables based on `StorageSystemPartsBase` (`system.parts`, `system.parts_columns`, `system.projection_parts`, `system.projection_parts_columns`) build the whole result eagerly in `initializePipeline`, so a cancelled or timed out query kept building rows over every storage and part until the very end. In a stress test with ThreadFuzzer this took minutes and tripped the hung check: a `SELECT` over `system.parts_columns` stayed in the process list for 252 seconds with `is_cancelled = 1` and `max_execution_time = 10`. Check the query status per storage and per part. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113722&sha=ceedb772f6aa36e221d25ce48f9af71f032a7b08&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29 PR: #113722 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [0d49b37] Summary: ✅
AI ReviewSummaryThis PR makes the eager readers behind Missing context / blind spots
Final Verdict
LLVM Coverage ReportMeasured on commit 0d49b37.
Changed lines: Changed C/C++ lines covered: 343/357 (96.08%) · Uncovered code |
…eak' overflow mode Two changes after the AI review on #113909: - `StoragesInfoStreamBase` now keeps the `QueryStatus` of the query and checks it inside the eager database/table enumeration in `StoragesInfoStream` and in the `next` skip loop, so cancellation works during the storage-discovery prepass too. - All `checkTimeLimit` calls now use the return value: with `timeout_overflow_mode = 'break'` the eager build stops early and returns the rows collected so far instead of running to completion. Co-Authored-By: Claude Fable 5 <[email protected]>
The style check requires `ErrorCodes::LOGICAL_ERROR` to be defined in the same file that uses it. The usage moved from `StorageSystemPartsBase.h` to `StorageSystemPartsBase.cpp` when `next` was moved out of the header, but the definition stayed in the header. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113909&sha=69a9d9df45384afc99967af8f9c44a1677730cea&name_0=PR&name_1=Style%20check Co-Authored-By: Claude Fable 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units689 translation units recompiled, 5508 s compile time in total, 689 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
|
…stem.dropped_tables_parts` - `StoragesDroppedInfoStream` now checks the query status in its eager `getTablesMarkedDropped` scan, so a killed or soft-timed-out query over `system.dropped_tables_parts` stops during the storage-discovery prepass and returns the rows collected so far in the 'break' overflow mode. - The `MergeTreeData` part-enumeration helpers used by the `system.parts` family (`getDataPartsVectorForInternalUsage`, `getAllDataPartsVector`, `getProjectionPartsVectorForInternalUsage`, `getAllProjectionPartsVector`) accept an optional `need_stop` callback that is checked periodically during the walk over the parts set, so cancellation is noticed while the per-storage snapshot is being built, not only after the full vector is materialized. - Add a test for the 'break' overflow mode over the `system.parts` family.
|
🕵 The |
… part The two column-oriented tables of the `system.parts` family polled `QueryStatus` only at the part boundary. On a very wide table, `StorageSystemPartsColumns` and `StorageSystemProjectionPartsColumns` could then spend a long time in the metadata prepass over `getColumns` and in the per-part column-enumeration loop without consulting it, so `KILL QUERY` and `timeout_overflow_mode = 'break'` still could not interrupt building the result of a single storage. Both loops now check `checkTimeLimit` every `COLUMNS_CANCELLATION_CHECK_PERIOD` columns. In the 'break' mode the column loop stops with a partial result, while the metadata prepass gives up the whole storage, because a partially filled `columns_info` would report wrong column defaults. The regression test is rewritten as a shell test with fixtures large enough that the deadline is guaranteed to fire while the result is being built: a table with 1000 parts for the per-part loops and a table with 3000 columns in a single part for the column-enumeration loops. It now asserts that fewer rows than the full result are returned, so it fails if the checkpoints are removed.
|
🕵 Both CI failures on
|
… fixtures The test 04828_system_parts_family_time_limit_break timed out in the flaky check: the fixtures (a 1000-part table and a 3000-column table) were too heavy for repeated runs on the debug and sanitizer builds, while the pre-expired deadline fires before the first storage is processed anyway, so the fixture size added nothing. Worse, the test could not fail on a build without the fix: in the 'break' overflow mode the executor drops the eagerly built result after the deadline regardless of the cancellation checkpoints, so a plain row-count assertion passes on master too, and the Bugfix validation had nothing to validate. Add the `slowdown_system_parts_enumeration` failpoint: when enabled, the per-part loops of the `system.parts` family sleep 100 ms on every enumerated part of the tables named `t_slowdown_system_parts*` (only specially named tables, so concurrently running tests are unaffected). Building the full result for a 100-part table then takes at least 10 seconds, and the test asserts that a query with a 1 second deadline in the 'break' mode finishes well under that - which is only possible by stopping between the parts. Without the per-part checkpoints the elapsed-time assertions fail, and on a build without the fix the test fails at `SYSTEM ENABLE FAILPOINT` already. Also add a deterministic dropped-table fixture (the async-drop pattern from 02698_marked_dropped_tables.sql) so that the `system.dropped_tables_parts` checks assert a partial row count instead of merely not throwing, addressing the review comment. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113909&sha=26a9645138c7dc1dca9a31ab082b1734623d514f&name_0=PR PR: #113909 Co-Authored-By: Claude Fable 5 <[email protected]>
The test `04828_system_parts_family_time_limit_break` exceeded the 180 second limit of the flaky check with the debug build: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113909&sha=a99197d98f2ea59b42bab0b3432b32485105c983&name_0=PR&name_1=Stateless%20tests%20(amd_debug%2C%20flaky%20check) The dominant costs were the fixtures (two 100-part inserts and a 300-column table) and 13 separate client invocations, both of which are much slower with the debug build. The `slowdown_system_parts_enumeration` failpoint now sleeps 500 ms per enumerated part instead of 100 ms, so 20 parts still guarantee the same 10 second full build for the timed checks; the column fixture shrinks to 100 columns, and all the quick checks run in a single client invocation. Local release run: 7.5 seconds instead of 12, with the fixture cost reduced about fivefold.
…imed check The `slowdown_system_parts_enumeration` failpoint now also sleeps 1 second per `COLUMNS_CANCELLATION_CHECK_PERIOD` (128) enumerated columns of a part of the specially named tables, and the test grows a wide fixture (a single part with 1301 columns and a projection over all of them): building its full `system.parts_columns` / `system.projection_parts_columns` result takes at least 10 seconds (measured: 10.6 s), while the timed checks with a 1 second break deadline finish in about 1.6 seconds - which is only possible when the column-enumeration loops poll the query status. The sleep is a statement separate from the checkpoint, so deleting the checkpoints does not delete the slowdown and the elapsed time assertions fail.
|
🕵 CI failures on
|
|
Acknowledged, investigating. One correction on the breadth: only 2 of those 4 CIDB rows are this signature. The 600 s I will follow up here with the PR, or with my findings if it turns out not to be actionable. |
…ts` is exhausted The sliced acquisition in `StoragesInfoStreamBase::tryLockTable` re-threw the `DEADLOCK_AVOIDED` exception of the last 100 ms slice, so a query that really waited the whole `lock_acquire_timeout` reported `... has timed out! (100ms)`. Amend the exception with the total timeout, keeping the original message with the owner query ids of the lock. Addresses the review: #113909 (comment)
…cellation test The suite proved the dropped-table discovery, part-snapshot, metadata-prepass, and per-part / per-column checkpoints, but nothing forced the ordinary database/table discovery walk of `StoragesInfoStream` to cross its `checkTimeLimit` branch. The `slowdown_system_parts_enumeration` failpoint now sleeps 500 ms on every walked table named `t_slowdown_system_parts_discovery*`, and the test adds a 10-table fixture in a dedicated database (the walk enumerates every table of the walked database regardless of the query's table filter, so keeping the fixture next to the others would slow every other check), with the same sleep-count assertion as the other checks. Verified load-bearing: against a binary with the walk's checkpoint disabled, the check reports 10 sleeps and fails, while the rest of the suite stays green. Addresses the review: #113909 (comment)
|
🕵 The Pushed 3af8c41 (master merged) addressing both AI-review findings: the exhausted sliced lock wait now reports the full |
The opening comment still described the pre-`3077f6c3cac1` behavior
("returns the rows collected so far"), contradicting the note before the
second group of checks: a result chunk produced past the deadline never
reaches the rest of the pipeline, so no partial prefix is handed out.
Addresses the review thread.
|
🕵 The Pushed 9560498: |
The test timed out (`Test runs too long (> 180s)`) in the `amd_debug`, `amd_msan` and `amd_binary` flaky checks. Almost all of the time went into the fixture, not into the checks: creating and filling the three tables with 1025 columns each (plus their `SELECT *` projections) took 125 of the 180 seconds in the `amd_msan` run, because writing a part costs time per column. The width of those fixtures is dictated by `COLUMNS_CANCELLATION_CHECK_PERIOD`: the checks need a part with enough columns to cross the checkpoint several times. Lower the period from 128 to 16 columns, which is a better cadence anyway - a poll is a clock read, while filling the row of a single column allocates and copies much more than that - and narrow the fixtures accordingly, from 1025 to 129 columns. A full enumeration still crosses the checkpoints 9 times per part, so the assertion of at most `MAX_SLEEPS` = 4 sleeps keeps its margin. Verified locally against a release build: every check performs 1-2 sleeps, while a probe query without a deadline over the same fixture performs 17, and the test now takes 21 seconds instead of 180+.
|
🕵 Merged The time went into the fixture, not into the checks — in the Verified locally against a release build: the test now takes 21 s instead of 180+, every check performs 1-2 failpoint sleeps (bound: The two |
The `parts_columns_snap_wide` and `projection_parts_columns_snap_wide` checks claimed to cover the per-column checkpoints of `StorageSystemPartsColumns` and `StorageSystemProjectionPartsColumns` that run after the parts snapshot has already stopped. They cannot: the snapshot walk stops only once the deadline has expired, and both column-oriented consumers then break out on the `checkTimeLimit` at the top of the per-part loop, before any per-column work. So both checks stay green even with the inner checkpoints removed. The per-column checkpoints themselves are already covered, by `parts_columns_wide` and `projection_parts_columns_wide` over the `_wide` fixture, where the snapshot is fast and the deadline fires inside the column loop. Removing the `_snap_wide` fixture also drops one 129-column table with its `SELECT *` projection from the fixture, which is what the test spends most of its time creating. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Pushed The only red on Addressed the sole unresolved review thread by removing the Verified locally against an isolated release server: |
…dary The retry loop in `StoragesInfoStreamBase::tryLockTable` used `tryLockForShare` as its 100 ms poll primitive, and `IStorage::tryLockTimed` throws `DEADLOCK_AVOIDED` on every timed-out probe, so a `system.parts` query waiting behind a DDL query with `lock_acquire_timeout = 60` constructed and caught about 600 exceptions before it got the lock or reached the real timeout. Add an `IStorage::tryLockForShare` overload that waits in slices of a given check period and polls a `need_stop` callback between them, on top of `RWLockImpl::getLock`, which returns a nullptr on a timed-out slice instead of throwing. Only the exhaustion of the whole `lock_acquire_timeout` throws `DEADLOCK_AVOIDED`, and the message reports the total wait and the owner query ids, as before. `tryLockTable` becomes a plain call of that overload. Verified with `04869_system_parts_lock_wait_cancellation`: one run now adds exactly one `DEADLOCK_AVOIDED` to `system.errors` (the intended 1 s probe, reporting 1000 ms), and the two deadline queries throw nothing while waiting. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged The only red on ea27451 was |
|
The fix is in progress and it is mine: #116209, open since 2026-08-24. It splits this exact job into The rate is compounding while it waits. At-cap kills of the pair, counting CIDB The runs that do finish are close behind. Their p99 was 7741 s in August and is 8155 s so far in September against the 9000 s limit, so a run that is merely slower than usual now ends at the cap instead of reporting. #116209 has had no review since it opened. It is also |
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is over-done, but I like the change. It is thorough and correct.
The tables based on
StorageSystemPartsBase(system.parts,system.parts_columns,system.projection_parts,system.projection_parts_columns) build the whole result eagerly ininitializePipeline, so a cancelled or timed out query kept building rows over every storage and part until the very end. In a stress test with ThreadFuzzer this took minutes and tripped the hung check: aSELECToversystem.parts_columns(with a filter matching every active part on the server) stayed in the process list for 252 seconds withis_cancelled = 1andmax_execution_time = 10. Check the query status per storage and per part, following the pattern ofsystem.zookeeperandsystem.remote_data_paths.The check also covers the storage-discovery prepass in
StoragesInfoStream(the eager enumeration of all databases and tables), the analogous prepass inStoragesDroppedInfoStream(sosystem.dropped_tables_partsis interruptible as well), the skip loop inStoragesInfoStreamBase::next, and the per-storage part enumeration itself: theMergeTreeDatahelpers (getDataPartsVectorForInternalUsage,getAllDataPartsVector,getProjectionPartsVectorForInternalUsage,getAllProjectionPartsVector) take an optionalneed_stopcallback that is checked periodically while the parts snapshot is being built. The two column-oriented tables additionally check the query status inside their column-enumeration loops and their metadata prepass, so a very wide table does not create a long uninterruptible stretch inside a single storage. The return value ofcheckTimeLimitis honored, so withtimeout_overflow_mode = 'break'the eager build stops at the soft deadline and returns the rows collected so far.The table-lock acquisition in
StoragesInfoStreamBase::tryLockTableis interruptible as well: instead of a single wait insideRWLockImpl::getLockfor the wholelock_acquire_timeout, the lock is acquired in 100 ms slices with a query-status poll between the attempts (the total timeout and theDEADLOCK_AVOIDEDsemantics are preserved, and when the total budget is exhausted, the exception reports the fulllock_acquire_timeoutrather than the last slice), so a killed or soft-timed-out query does not sit in the lock wait while a concurrent DDL query holds the drop lock. The test04869_system_parts_lock_wait_cancellationpins this with a share lock held by a longSELECTand aDROP TABLEin anOrdinarydatabase queued behind it.The test uses the new
slowdown_system_parts_enumerationfailpoint, which only affects the specially named test tables (so concurrently running tests are unaffected). It sleeps 500 ms on every enumerated part, so building the full result for a 20-part table takes at least 10 seconds, and it sleeps 1 second perCOLUMNS_CANCELLATION_CHECK_PERIOD(128) enumerated columns of a part, so building the fullsystem.parts_columns/system.projection_parts_columnsresult over a single part with 1,025 columns (and a projection over all of them) takes at least 8 seconds. The test asserts that queries with a 1 second deadline in thebreakmode finish well under that (the elapsed time is taken fromsystem.query_log, because the startup ofclickhouse-clientalone takes seconds in the debug and sanitizer builds), which is only possible by stopping at the per-part and per-column cancellation checkpoints. Timed assertions are needed because a plain row-count assertion cannot distinguish a build with the fix from one without: in thebreakmode the executor drops the eagerly built result after the deadline in both cases. The test also asserts partial row counts under a pre-expired deadline for all five tables, includingsystem.dropped_tables_partsover a deterministic dropped-table fixture. The pre-expired-deadline checks also run under the failpoint, so the fewer-rows assertion is deterministic even on a machine fast enough to build the whole result in under a millisecond.For tables with the
_snapname marker, the failpoint additionally slows down the parts-snapshot walks insideMergeTreeData(500 ms per enumerated part) and makes them poll the stop callback on every element, and for tables with the_metaname marker it slows down the column-metadata prepass of the column-oriented tables (1 second per 128 enumerated metadata columns), so the timed checks also prove that the snapshot materialization and the prepass are interruptible: all six of these checks fail against a binary with theneed_stoppolls and the prepass checkpoints disabled. For tables with the_discoveryname marker the failpoint slows down the database/table discovery walk ofStoragesInfoStreamitself (500 ms per walked table); the corresponding fixture lives in a dedicated database, because the walk enumerates every table of the walked database regardless of the query's table filter, and its check likewise fails against a binary with the walk's checkpoint disabled.Caught by
Stress test (arm_asan_ubsan, s3): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113722&sha=ceedb772f6aa36e221d25ce48f9af71f032a7b08&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29Related: #113722
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Queries over
system.parts,system.parts_columns,system.projection_parts,system.projection_parts_columns, andsystem.dropped_tables_partsnow react to cancellation andmax_execution_timewhile the result is being built.Workflow [PR]
Sync PR [sync-upstream/pr/113909]