Repository navigation
Report mutation cancellation instead of stopping nested pipelines silently - #114463
Conversation
…ently A mutation whose predicate contains `IN (subquery)` materializes the right-hand side through `FutureSetFromSubquery::buildSetInplace`, which runs a nested `CompletedPipelineExecutor` and polls the mutation's interactive-cancel callback. The callback returned a bare `bool`, so on cancellation the executor called `cancel()` and the poll loop returned normally: `CreatingSetsTransform::generate` and therefore `Set::finishInsert` never ran, leaving the set uncreated while `build()` had already moved the source plan out. `buildSetsForDAG` returns void, so `getMinMaxCountProjectionBlock` went on to evaluate the filter in the same call and `FunctionIn` threw "Not-ready Set is passed as the second argument for function 'in'" - a server abort in debug and sanitizer builds. Reported by @ alexey-milovidov on ClickHouse#112152 (comment) after a Stress test (amd_debug) run aborted this way. `DETACH DATABASE` during a running mutation is the trigger seen in CI; `KILL MUTATION` reproduces it. The callback now throws `ABORTED` on cancellation, mirroring `MergeTask::checkOperationIsNotCanceled`, which reports the merge path the same way and is likewise wired into nested pipelines. `MergeTreeBackgroundExecutor` already treats `ABORTED` as a normal outcome and logs it at DEBUG. Only the mutation installs this callback shape; the two interactive installers in `TCPHandler` and `LocalConnection` are untouched, so client-side cancellation still returns `QUERY_WAS_CANCELLED` quietly. Instrumented measurement of the cancel path before the fix: of three mutating parts, one returned from `execute()` with no exception and an uncreated set, while the other two observed the `UNKNOWN_EXCEPTION` that `~CreatingSetsTransform` sets on the shared promise - so the loud report was a race, not a contract. A readiness guard at the projection site was measured and deliberately not added: with the cancellation reported, no user-runnable input reaches that sink. Related: ClickHouse#107619 Co-Authored-By: Claude Fable 5 <[email protected]>
The test previously checked only side effects that outlive the abort: merges draining to zero, the cancelled UPDATE not applying, and a later mutation succeeding. All four hold on a build where LOGICAL_ERROR is caught rather than fatal, because MutatePlainMergeTreeTask logs and rethrows it and the background executor contains it, while KILL MUTATION has already removed the mutation entry. The oracle was therefore live only on debug and sanitizer builds. Assert instead that the cancelled mutation recorded ABORTED in system.part_log, which is the outcome the fix produces and the unfixed code cannot: a silently stopped set build leaves no such row. Poll for it, since the part log entry is queued asynchronously, and fail loudly on timeout rather than passing vacuously. Measured on the pre-fix binary: no ABORTED row, the poll times out, and the server aborts with two "Not-ready Set" records at getMinMaxCountProjectionBlock via isStorageTouchedByMutations. Scoped by currentDatabase() and the table name so parallel copies of the test cannot observe each other's part log rows. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (2 rounds, 0 open blockers)Reviewed cold at Round 1 -- 1 major, agreed and fixed
The fix round changed test files only; Round 1 -- 1 major, disagreed with evidence ❌ The same finding also asked for "zero non- Round 2 -- Gate B clean 0 findings on the delta, with coverage over both mutation callers, the nested executor and set Verified independently rather than taken from the plan
|
|
Workflow [PR], commit [c2dabd5] Summary: ✅
AI ReviewSummaryThis PR makes the mutation query context throw Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code |
Pre-PR validation gate
Also run: the sibling cancellation test |
|
cc @scanhex12 @tiandiwonder, could you review this? A mutation's interactive-cancel callback returned a bare bool, so cancelling it stopped the nested |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
…nistic The flaky check failed on amd_msan and amd_tsan with `system.merges` reading 1 instead of 0 after `KILL MUTATION`. `StorageMergeTree::killMutation` erases the mutation entry and then calls `MergeList::cancelPartMutations`, which walks the entries present at that instant and sets `is_cancelled` on them. A mutate task's MergeList entry is inserted in `MutatePlainMergeTreeTask::prepare()`, which runs when the background executor gives the task a thread, not when the task is assigned. So a task assigned before the kill but still queued for a pool slot inserts its entry after the scan and never gets cancelled. `KILL MUTATION` does not touch `merges_blocker` either, so both disjuncts of the interactive-cancel predicate stay false for that task and it runs to completion. The test's precondition only waited for one running mutation, which does not establish that every part of the 3-part table already holds an entry. Under the contended msan/tsan pool one task routinely landed after the kill: CI's part_log shows 2 parts ABORTED and the third starting after them and completing in 329 s, so `system.merges` never drained. Locally, constraining the pool reproduces the precondition directly - 2 of 3 parts hold an entry at kill time. Put all rows in one partition, so one part means one mutate task and the task the test waits for is provably the only one `cancelPartMutations` has to find. The `b` values are unchanged, so the reference file is byte-identical and no assertion is removed, relaxed or reordered. The drain wait now exits loudly on timeout like the two sibling waits in the same file, instead of breaking into an assertion that is then guaranteed to fail with an unexplained diff. Verified: 31 runs on the fixed binary all pass, and the fixed test still reddens on the pre-fix binary (server aborts with `Not-ready Set is passed as the second argument for function 'in'`, sink frames getMinMaxCountProjectionBlock / isStorageTouchedByMutations), so the oracle is unchanged.
system.part_log is append-only across DROP TABLE, and currentDatabase() is not
unique per invocation when a database is pinned: ci/jobs/scripts/stress/stress.py
passes --database=test_{i} so one database serves every test in that thread, and
--stress-tests reruns the selection until global_time_limit. A prior run's ABORTED
MutatePart row for the same table therefore satisfied the database/table plus
10-minute predicate, and the assertion that pins the cancellation reporting could
pass without this execution having reached the fixed path.
Measured on identical server state, in a pinned database holding a genuine ABORTED
row from an earlier run, with the table re-created and no cancellation performed:
the old predicate returned 1, the new one 0.
The bound is compared against event_time_microseconds rather than event_time:
04604_async_insert_dedup_prewarm_hash_count.sh records that a second-granularity
column truncates below a sub-second bound and drops the current run's own row.
Verified both ways on one bound - an event a microsecond after it is kept, and
would have been dropped by the second-granularity column.
Verification: fixed test on the fixed binary passes 6/6 in a pinned database while
stale rows accumulate, and once in a fresh random database; on the pre-fix binary
with 7 stale rows present it fails with "Cancelled mutation did not record ABORTED
in system.part_log", so the oracle no longer accepts them. The reference file is
byte-identical and no assertion was removed, relaxed or reordered.
The precondition asserts that the minmax_count projection is chosen for the
predicate shape the cancellation below exercises. It queried the table with
`optimize_trivial_count_query` left at whatever the run had, and under the old
analyzer that shortcut wins: the plan becomes `ReadFromPreparedSource
(Optimized trivial count)` and the assertion reports 0, so the job
`Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated,
WasmEdge, parallel, 1/3)` failed 3 of 3 reruns with a one-line `-1 / +0` diff.
The assertion was wrong, not the scenario. The mutation reads a single part
through StorageFromMergeTreeDataPart, which inherits
IStorage::supportsTrivialCountOptimization() == false, so the shortcut can
never apply on the mutation's own count query and the projection is always
reached there. The probe queried the real table, where MergeTreeData returns
true, so it answered a different question than the one under test. Measured on
the pre-fix binary with the old analyzer active server-side: the precondition
printed 0 while the server still aborted with
"Not-ready Set is passed as the second argument for function 'in'", sink frames
getMinMaxCountProjectionBlock and isStorageTouchedByMutations - the bug was
reachable in exactly the config the probe called uninteresting.
The setting is also randomized by the runner (5% chance of 0), so the probe had
a latent flake under the new analyzer too.
Measured, all four arms of {analyzer on, off} x {trivial count on, off}: the
old probe returns 0 for analyzer off with trivial count on and 1 elsewhere; the
pinned probe returns 1 in all four. End to end with the old analyzer set
server-side: fixed test 6/6 pass, old test reproduces CI's exact one-line diff
on the same server and binary, and the pre-fix binary runs the fixed test to a
line 1 of 1 before dying of the bug. Default new-analyzer shape with
randomization on: 3/3 pass.
CI finish ledger - c2dabd5CI is fully finished on this head and there are no failures to own: 177 check-runs, 160 success / 17 skipped / 0 failure.
Session id: cron:our-pr-ci-monitor:20260813-193000 |
alexey-milovidov
left a comment
There was a problem hiding this comment.
The fix is good. Approved.
Master now carries ClickHouse#114463, which made the mutation interactive-cancel callback throw ABORTED instead of returning a bare bool, so that a nested pipeline stopped mid-build cannot be mistaken for one that completed. This branch had independently rewritten the same lambda to latch a detected cancellation and to install the thread group's cancellation predicates, which is what the S3 retry loop actually polls. Both properties are required and neither subsumes the other, so the resolution keeps both: the latching predicate is shared by the interactive-cancel callback and by the group's predicates, and the throwing wrapper is derived from it once. Keeping only this branch's side would have silently reverted ClickHouse#114463's throw.
`FutureSetFromSubquery::buildSetInplace` materializes the right side of
`IN (subquery)` through a nested `CompletedPipelineExecutor` and polls the
query's interactive-cancel callback. A callback that only returns `true` stops
that pipeline silently: the poll loop cancels the pipeline and returns
normally, so `CreatingSetsTransform::generate` never runs `Set::finishInsert`,
while `build` has already moved the source plan out. A caller that evaluates
its filter in the same call - the `minmax_count` projection, through
`VirtualColumnUtils::filterBlockWithPredicate` - then passes the unbuilt set to
`FunctionIn`, which reports `Not-ready Set is passed as the second argument for
function 'in'`, a `LOGICAL_ERROR`.
`TCPHandler` installs such a callback for `partial_result_on_first_cancel`: the
first cancel only sets `stop_read_return_partial_result` and deliberately does
not cancel through the process list. One cancel of
SELECT count() FROM t WHERE 1 IN (SELECT number FROM numbers(10000000) WHERE sleep(1) = 0)
SETTINGS partial_result_on_first_cancel = 1, optimize_use_implicit_projections = 1,
optimize_trivial_count_query = 0
reproduces it on every run, and a debug or sanitizer build aborts on it. The
other installer, `LocalConnection`, cancels through the process list element,
so its nested pipeline fails rather than stopping silently and the same query
interrupted with `SIGINT` reports `QUERY_WAS_CANCELLED`; it is untouched here.
`buildSetInplace` now records whether the cancel callback fired and reports
`QUERY_WAS_CANCELLED` when the set was left uncreated. Both conditions are
required, so a pipeline stopped for any other reason keeps its behaviour:
`set_overflow_mode`, `transfer_overflow_mode` and `read_overflow_mode = 'break'`
all still reach `generate`, which finishes the set.
Follow-up to ClickHouse#114463, which
reports a cancelled mutation as `ABORTED` from the callback itself and so
covers every nested pipeline a mutation runs, not only `buildSetInplace`.
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):
Fixed a
Not-ready Set is passed as the second argument for function 'in'error when a mutation whose predicate containsIN (subquery)is cancelled, for example byKILL MUTATIONorDETACH DATABASE, while the subquery's set is still being built. Related: #107619.Description
Reported by @ alexey-milovidov on #112152 (comment) after a
Stress test (amd_debug)run aborted this way.buildSetInplacematerializes the right side ofIN (subquery)through a nestedCompletedPipelineExecutorand polls the mutation's interactive-cancel callback. That callback returned a barebool, so on cancellation the executor calledcancel()and the poll loop returned normally:Set::finishInsertnever ran, whilebuild()had already moved the source plan out.buildSetsForDAGreturnsvoid, sogetMinMaxCountProjectionBlockevaluated the filter in the same call andFunctionInthrew. A constant left-hand side (1 IN (...)) makes this the first materialization attempt: it maps to no key column, so primary-key analysis returns first.The callback now throws
ABORTED, mirroringMergeTask::checkOperationIsNotCanceled, which reports the merge path the same way and is likewise used as a nested-pipeline callback.MergeTreeBackgroundExecutoralready treatsABORTEDas a normal outcome and logs it at DEBUG. Only the mutation installs this callback shape, so the installers inTCPHandlerandLocalConnectionare untouched and client cancellation still returnsQUERY_WAS_CANCELLEDquietly.Validation:
KILL MUTATIONandDETACH DATABASEmid-build abort the server before the change and are clean after it, and the table stays mutatable. New test04865_cancel_mutation_in_subquery_minmax_projection, 50 of 50 runs. The other cancellation routes and overflow modes checked are listed in the validation gate comment below.Out of scope: a caller that executes a filter DAG synchronously still does not check set readiness, and
buildSetInplacestill leaves the set unbuildable if some future path stops it silently. I found no input reaching either independently of this cancellation.Note for review: #113939 rewrites the same lambda for the S3 read path but keeps the interactive callback non-throwing, so it does not fix this. The two conflict textually; a resolution must keep both the throw and that PR's cancellation persistence.