Repository navigation
Conversation
In a workload with fewer CPU slots than an `INSERT` into `Distributed` / `remote()` or a `file()` read needs at once (e.g. `max_concurrent_threads = 1`), the query hung until `max_execution_time`: a lease that cannot progress keeps its slot, so the pipeline it waits for never gets one. - A nested `executeUntil` executor that starts inside another executor's step on the same thread (`writeToLocal` of a background insert, the reader of `file()` and other sources) runs on that step's lease (`GrantedAllocation`, the outer lease stays published), instead of taking a second slot on the same thread. Its CPU is reported once, by the outer lease. - `DistributedSink` parks the inserting thread's lease while it waits for the writing jobs (`waitForPool`), and a writing job's executor stays parked while the job is idle in the pool between blocks (new `IExecutor` / `PushingPipelineExecutor` park API; `executeUntil` unparks on entry, the destructor unparks before the release). - `RemoteInserter::onFinish` parks while it waits for the shard's EndOfStream. - `TCPHandler` publishes the 1-thread insert executor's lease while it receives the next packet and parks it only around the blocking poll. Each park scope contains only a wait, never CPU work of the lease's pipeline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GLOBAL IN` / `GLOBAL JOIN` fill their external table by a nested `PushingPipelineExecutor` (`CreatingSetsTransform`) on the planning thread, so on master both queries wait for a second CPU slot until `max_execution_time`. Sized on a release build of master: 10M rows in the subquery hang 5/5, 5M do not; the test uses 15M. Without the nested-executor change both hang 3/3. Also write the `TCPHandler` lease publication as an optional `ScopedCPULease` (same scope, no behaviour change). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The CI profile tests/config/users.d/limits.yaml sets max_rows_to_read to 20M. The initiator of Q6/Q7 counts 30.1M rows (the 15M-row subquery, the same rows again when the shard reads the external table back, and 100k), so both queries failed with TOO_MANY_ROWS in every lane. A query-level max_rows_to_read = 0 overrides the profile; master still hangs on both queries with it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove a comment duplicating the runs_on_caller_lease field comment and one narrating the TCPHandler receive lambda. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; round 1 on
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261018-054400 |
|
cc @serxa @devcrafter, could you review this and add the |
|
Workflow [PR], commit [27064c7] Summary: ❌
AI ReviewSummaryPR #126572 parks CPU leases around inter-pipeline waits and lets nested pipelines share their caller's lease. Review of head Findings❌ Blockers
Tests
Missing context / blind spots
Performance & SafetyKeep the declared merge prerequisite on PR #126336. The description reports that repeated parking otherwise exceeds Final Verdict❌ Block. Propagate shared-lease shutdown and add the cancellation regression. Merge PR #126336 first and obtain completed CI results for the final head. |
A nested `executeUntil` runs on the lease that the outer executor published on its thread, but it never renewed it: a long nested call (for example the aggregation of a view read by `loop`) reported its whole CPU time to the scheduler only after it returned, so `max_cpus` and `max_burst_cpu_seconds` did not throttle it and a competing query of a one-slot workload waited for the whole call. The nested executor now renews that lease at its own processor boundaries with `ISlotLease::renewInTask`. It reports the consumption and blocks on preemption like `renew`, but the thread is inside a task of the outer executor, so the outer executor is not notified (`ExecutorTasks::preempt` would hand the running task to another thread) and the thread is never stopped: a worker that waits longer than the preemption timeout continues on a borrowed slot, and the outer executor downscales it at its next `renew`. Measured on a release build, `SELECT * FROM loop(v) LIMIT 1` over a 2.2 s single-thread aggregation: with `max_cpus = 0.5` it took 2.2 s with 0 preemptions (one 2.13 s report), now 4.2-4.3 s with ~180 preemptions and ~2 ms reports, as on master; in a one-slot workload a 90 ms competing query waited 1.97 s, now 0.145 s. Co-Authored-By: Claude Opus 5.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 units1609 translation units recompiled, 10535 s compile time in total, 1608 of them have a recent master baseline. Translation units without a recent master baseline:
|
A nested pipeline renews the lease of the outer executor's thread with `renewInTask`. On a worker thread, a preemption wait that hit `cpu_slot_preemption_timeout_ms` resumed the thread without a grant, and every following report could do the same, so the nested work ran far above `max_cpus` until the call returned. Such a thread now waits for a grant without a timeout, like the master thread; the outer executor can still downscale it at its own `renew` after the task. Measured on a release build with `cpu_slot_preemption_timeout_ms = 1` and a workload with `max_cpus = 0.1`, `max_burst_cpu_seconds = 1`: one query reads a 1.8 s aggregating view twice through `loop()` with `max_threads = 2`. In runs where a worker took one of the reads, it used 0.50 CPU for ~3 s (1205-1384 preemptions of ~1 ms on the worker) and then the master stalled ~10 s to repay it; now the query uses 0.10 CPU in every second after the burst (113 preemptions, the worker waits 23 s for grants). The new unit test fails without the change: the worker stops waiting after ~3 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the sanitizer flaky checks q8 either timed out (asan, 5 of 5: 12.5 s of CPU in 60 s on an overloaded runner, so 300M rows did not finish) or was never preempted (tsan, 2 of 20: the thread got less CPU than `max_cpus = 0.5`, so the limit never applied). The aggregation now reads an unbounded `numbers()` and stops after 1 s (`timeout_overflow_mode = 'break'`) under `max_cpus = 0.05`, below what any build gets in that time: 3-6 preemptions on debug and release builds, also with the server's cores overloaded 5x, and 0 without the nested renewal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`RemoteQueryExecutor` sends external tables from its read context coroutine: `Connection::sendExternalTablesData` runs a pipeline on the coroutine stack, and its `WorkloadResources` hides the executor's lease (`current_cpu_lease = nullptr`, restoring the previous lease on destruction). When the socket is full the coroutine suspends inside that pipeline, and with a plain `thread_local`: - the executor thread keeps the hidden (null) lease, so its wait for the shard does not park the slot; in a one-slot workload the shard then waits for that slot forever (05406 q6 hung to `max_execution_time` in the flaky checks); - when the query is cancelled, the suspended coroutine is unwound on the connection thread, and the destructor writes the executor's lease into that thread; the lease is freed with the query, and the next query on the thread renews it (segfault in `WorkloadResources::renewCPULease` from `TCPHandler::processInsertQuery`, STID 4530-4efa). Both variables become coroutine-local `FiberLocal` slots, which `StackfulCoroutine` swaps on resume, suspend and unwind. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With random `compile_expressions = 1` and `min_count_to_compile_expression = 0` the expression is compiled before the aggregation starts. In the asan flaky check this took 1.07 s (`CompileExpressionsMicroseconds`) of the 1 s time limit, so the aggregation never ran long enough to be preempted (`05406_q8 1 0`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
| lease->renewInTask(); // The outer executor stops the thread at its own `renew` | ||
| return true; |
There was a problem hiding this comment.
❌ [P1] Propagate shared-lease shutdown to the nested pipeline
Cancelling the outer executor calls ExecutorTasks::finish, which frees its CPU allocation. The next CPULeaseAllocation::renew returns false and resets the lease, but renewInTask discards that result and this branch always returns true. Subsequent renewals do nothing, so the nested pipeline can continue without CPU accounting or throttling until the outer task returns.
This is reachable through the new test's loop over an aggregating view: LoopSource::initLoop constructs the inner QueryPipeline from getPipe without a process-list element, so cancellation of the outer executor does not cancel that inner executor. For example, run this with a query ID in a workload capped having max_cpus = 0.1 and max_burst_cpu_seconds = 0.01, then issue KILL QUERY from another connection:
CREATE VIEW v AS SELECT sum(cityHash64(number)) AS s FROM numbers(100000000000);
SELECT * FROM loop(v) LIMIT 1
SETTINGS workload = 'capped', max_threads = 1,
compile_expressions = 0, compile_aggregate_expressions = 0
FORMAT Null;On the ARM release binary for revision 81c3852d (the renewal/shutdown code is unchanged at the current head), server CPU consumption rose from 0.44 CPU-seconds per three seconds before cancellation to 3.08 afterward, while the query remained active with is_cancelled = 1. With cpu_slot_parking = 0, the same control stayed throttled at 0.43 before / 0.41 after. Delayed cancellation already exists in that control; losing CPU throttling is the regression here.
Please propagate allocation shutdown through the in-task renewal and unwind/cancel the nested pipeline, rather than waiting for the outer renewal. Add a focused cancellation regression that verifies the nested work stops and cannot continue on the revoked lease.
|
@serxa one design decision before I fix the cancellation finding (#126572 (comment)). It is real: after
Which do you prefer? |
CI finish ledger - 27064c7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261019-120004 |
|
Dear @serxa, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Related: #117711
Related: #126336
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a hang of
INSERTintoDistributedtables andremote(), ofGLOBAL IN/GLOBAL JOINover them, and of queries readingfile(), in a workload with fewer CPU slots than the query needs at once (for examplemax_concurrent_threads = 1): a thread that waits for another pipeline of its query now parks its CPU slot, and a nested pipeline runs on the slot of its thread instead of taking a second one.Description
On 26.10.2.9, with
CREATE RESOURCE cpu (MASTER THREAD, WORKER THREAD)and a workload withmax_concurrent_threads = 1,INSERT INTO <Distributed> SELECT ...andINSERT ... FORMAT Nativeinto it run untilmax_execution_time; master also hangs forremote(),SELECT ... FROM file()withmax_threads = 1, andGLOBAL IN/GLOBAL JOINoverremote()orDistributed.Four holders keep their executor's CPU slot while blocked:
DistributedSinkwaiting for its writing jobs; a writing job's executor idle between blocks;RemoteInserter::onFinishwaiting for the shard's EndOfStream; the shard'sTCPHandlerwaiting for the next packet. A nestedexecuteUntilexecutor (writeToLocalof a background insert, the reader offile(),CreatingSetsTransformfilling aGLOBAL INset) took a second slot on a thread whose outer lease was running. This PR parks the lease around those waits (as #117711 does for I/O), runs a nestedexecuteUntilexecutor on its caller's lease, renewing it at its own processor boundaries, and keeps the published lease private to the coroutine sendingGLOBAL INtables.Merge after #126336: each park/unpark otherwise extends a lease by a quantum (#126133). With
max_cpus = 0.5: a 20M-row distributed insert uses 1.03-1.12 CPU with this PR alone and 0.56 with #126336 (master with #126336: 0.54); afile()read parsed on the query thread runs at 0.51 instead of 0.39.Validation: the new test times out on master and passes 50/50 with random settings; each of the five changes has a query that hangs without it. No slowdown above noise in an 8-slot workload or without one.
Not covered:
max_threadsabove the workload's slots (#126512);INSERT ... SELECTinto a local table with the defaultasync_insert = 1and multi-threaded shard inserts (both wait inPushingAsyncPipelineExecutor, a separate fix); nested executors run withexecute(); a writing job blocked inRemoteInserter::writeon a full socket.Workflow [PR]
Sync PR [sync-upstream/pr/126572]