Repository navigation
Move two lightweight-update test rendezvous out of IProcessor::work() - #119069
alexey-milovidov merged 3 commits into
Conversation
Tests that need a lightweight update to hold its locks open while a second statement runs currently park a PipelineExecutor worker inside IProcessor::work(), which the contract in IProcessor.h forbids: synchronous work must only use CPU. BlockIO::onFinish, between releaseQuerySlot() and the pipeline teardown, is the last point at which those locks are still held: the table locks the interpreter moved into the pipeline's resources, and a patch sink's lightweight update lock, are both released by that teardown. A pause there parks the query thread once the pipeline has finished, instead of a worker while it runs. It sits after releaseQuerySlot() so it holds no concurrency slot, and before releaseMemoryReservation() so it does not touch the reservation pipeline threads still read. Every query whose pipeline is completed reaches onFinish, including plain SELECTs, since PullingAsyncPipelineExecutor completes the pipeline it runs, and failpoints are keyed by name only. The pause is therefore gated on a dedicated query-id prefix outside the fiu evaluation, the way QueryMetricLog::finishQuery already is. Ungated, the one-shot arm could be consumed by an unrelated pipeline, and a test could not tell "something parked" from "my query parked". A pipeline that throws goes to onException rather than onFinish, so a failed query never parks holding nothing. Co-Authored-By: Claude Opus 5 <[email protected]>
The test used rmt_pause_before_commit_local_part, which sits in the ReplicatedMergeTree sink's commit path and is therefore reached from ExceptionKeepingTransform::work(), so the park occupied a PipelineExecutor worker. The share lock the test asserts on is taken by the interpreter, moved into the pipeline's resources, and released only when the pipeline is torn down, so it is still held once the pipeline has finished. Parking at completed_pipeline_pause_before_teardown keeps the drop blocked in lockExclusively on the query thread instead, and leaves all three arms, the RWLockWritersWaitMilliseconds oracle and the recorded output unchanged. The updater's query id carries the failpoint's prefix; the drop's deliberately does not, so the drop can never be the query that parks. Parking after the commit rather than inside it makes the assertion a superset of the old one: held after the pipeline finished implies held throughout it. It also drops the dependency on reaching the commit hook, which had already cost one CI run where all three arms reported that the sink never reached it. The pause was rmt_pause_before_commit_local_part's only user, so the failpoint goes. The lambda's sleep_before_commit_local_part_in_replicated_table_ms behaviour, which ATTACH PARTITION and restore also reach, stays. Co-Authored-By: Claude Opus 5 <[email protected]>
The holder took the lightweight update lock and then parked inside sleep() at the infinite_sleep failpoint, which FunctionSleep::execute reaches from ExpressionTransform::work(). That site is before sleep()'s max_microseconds bound check and before its sliced, cancellation-polling wait loop, so it parked a worker unboundedly and un-cancellably. The lock is taken while the pipeline is built and released only when the patch sink is destroyed, so parking at completed_pipeline_pause_before_teardown holds it just as well, on the query thread. The holder no longer needs sleep(0.001) in its WHERE, and its 'auto' mode conflict set is unchanged: it still writes s and reads id. The holder's own update now commits while it is parked, which changes no assertion: every reference line is a status or a counter, and 'auto' mode conflict detection compares the in_progress nodes' affected-column sets rather than committed data. The property that made this test non-flaky is kept: the hold ends when the test disables the failpoint, never after the runtime of real work. Added an armed 1 to 0 bracket around the park, which the query-id prefix upgrades from "something parked" to "this holder parked". All 22 reference lines unchanged. infinite_sleep stays in the tree: 04095_wait_fp_pause_disable.sh depends on it having a real call site. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260909-160400 |
|
Workflow [PR], commit [52b256e] Summary: ✅
AI ReviewSummaryThis PR moves two lightweight-update test rendezvous out of Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit 52b256e.
Changed lines: Changed C/C++ lines covered: 23/23 (100.00%) · Uncovered code |
|
cc @vdimir @scanhex12, could you review this? Two lightweight-update tests parked a |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 22 s compile time in total, 9 of them have a recent master baseline. |
b41474b
…on-cancel Conflicts in `FailPoint.cpp` and `RemoteQueryExecutor.cpp`: master (ClickHouse#119069, after the review request on ClickHouse#110334 that no test may park a pipeline worker inside `IProcessor::work`) removed the `remote_query_executor_receive_packet_pause` reader park and the `in_receive_packet_window` flag that guarded this PR's `finish` and `cancel` holds, replacing 04512's fixture with the inline `remote_query_executor_cancel_and_drain_in_receive_window`. Resolved by taking master's failpoint and dropping the reader park here too. The three holds stay, guarded by a new executor-local pin instead: `remote_query_executor_finish_entry_hold` fires once, and the executor that fires it sets `owns_test_holds`, so the drain hold and the cancel-gate hold can only be consumed by that executor and not by the sibling shard. Every `finish` entry of the pinned executor waits at the entry hold while it is armed, because `work` and `onUpdatePorts` can enter `finish` on different threads and a second one running ahead into the drain would defeat the interleaving. `05076` no longer arms the reader park; scenario A pins through the entry hold and releases it before waiting for the drain hold, scenario B is unchanged apart from the dropped park. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`RemoteQueryExecutor::finish` runs from `RemoteSource::work` (`LIMIT 1` closes the output port, `prepare` returns `Finished`, `need_drain` is set) and also from `onUpdatePorts`. Both are pipeline executor worker threads, so `finish_entry_hold` and `finish_drain_hold` broke the contract in `src/Processors/IProcessor.h` on every run of this test rather than in a corner case: `notifyPauseAndWaitForResume` waits on a condition variable with no timeout that only another client statement can release, and scenario A's assertion depended on `KILL QUERY` not releasing it. ClickHouse#119069 had already dropped the reader park here for the same reason. The defect under test is a state, not an interleaving: `cancel` only has to run while a thread is inside `finish` holding `was_cancelled_mutex`. So the three `PAUSEABLE_ONCE` holds and the `owns_test_holds` pin are replaced by one `ONCE` failpoint that runs `cancel()` inline, on the draining thread itself, in the shape 04512 already uses at the reader. Nothing is parked, so the executor-local pin has nothing left to guard and the `std::atomic_bool` leaves the header. That also removes the flake the pin introduced. The entry hold fired before `++finish_in_progress` and pinned whichever executor entered `finish` first, with nothing keeping that executor's drain outstanding, so any of the three conditions in `if (!isQueryPending() || hasThrownException() || was_cancelled)` could become true under the park, after which the drain hold was unreachable (1 failure in 126 runs at 8d973b2). The predicate ClickHouse#119069 removed, `in_receive_packet_window`, could only be true while a reader was blocked mid-receive, that is, only for a shard that provably still had packets to drain. The fixture now carries that implication positively, through `distributed_push_down_limit=0`: by default each shard applies the `LIMIT` itself and sends `EndOfStream` after a single granule (measured 16384 rows read, against 200000 with the push-down off), so a `finish` that already observed `finished` returned before reaching the drain and the failpoint never fired. That was reproducible at 1 in 25 randomized runs before the pin. Both directions measured on this content, debug build: fixed: 50/50 randomized runs pass (two batches, the second in `--order desc`), plus 25/25 with `use_hedged_requests=1` forced. 1.44 s per run, against 11.3 s before. unfixed: with `cancel` reverted to its pre-PR body, FAIL at 61.5 s reporting `armed 1` and `consumed 0`, so the injection fired and the interleaving was established. `system.stack_trace` then shows the deadlock the gate prevents, including the production victim: `PullingAsyncPipelineExecutor::cancel` -> `ExecutingGraph::cancel` -> `RemoteSource::onCancel` -> `RemoteQueryExecutor::cancel` blocked on `was_cancelled_mutex` on the TCPHandler thread, behind the drain thread holding it. The fix itself, `finish_gate_mutex` and `finish_in_progress`, is untouched. Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Test-only change: two lightweight-update tests no longer park a pipeline worker thread inside
IProcessor::work().Description
Follows a review request on #110334 (#110334 (comment)): no test should park a
PipelineExecutorworker insideIProcessor::work()(IProcessor.h: synchronous work must only use CPU), and to audit the tests I committed over the last four months. Part 2 of 2; part 1 is #119030.Two were left.
04905_lwu_drop_race_table_lockparked in the ReplicatedMergeTree sink's commit path, reached fromExceptionKeepingTransform::work().03100_lwu_57_lock_acquire_timeoutparked insidesleep()atinfinite_sleep, before its bound check and before its sliced, cancellation-polling wait loop, so it held a worker unboundedly and un-cancellably.Both want a rendezvous while a lightweight update's locks are held. Those locks are taken once while the pipeline is built (the table share lock into the pipeline's resources, the lightweight update lock into the patch sink) and released only by the teardown, so both are still held in
BlockIO::onFinish, on the query thread, with nowork()frame. OnePAUSEABLE_ONCEfailpoint goes there, afterreleaseQuerySlot().Every query whose pipeline is completed reaches
onFinish, including plainSELECTs (PullingAsyncPipelineExecutorcompletes the pipeline it runs), and failpoints are keyed by name only. So the pause is gated on a query-id prefix outside thefiuevaluation, asQueryMetricLog::finishQueryalready is.Two costs. 04905 no longer lands the DROP between the patch-part rename and the commit, only after it; since the locks are released only by that teardown, held there implies held throughout, so the assertion does not weaken, but the interleaving is gone. And this is a test hook in
BlockIO, which is query plumbing; the alternatives areTCPHandler(native protocol only) and the end ofCompletedPipelineExecutor::execute()(a step earlier, still holding the query slot). Either is a one-line move leaving both tests unchanged, so say the word if you prefer one.Neither reference file changes.
rmt_pause_before_commit_local_parthad no other user and goes;infinite_sleepstays for 04095.Workflow [PR]
Sync PR [sync-upstream/pr/119069]