Repository navigation
Fix a hang of a query that lazily loads a dictionary in a CPU workload - #130133
alexey-milovidov merged 2 commits into
Conversation
A lazy dictionary load started by a query runs on an ExternalLoader thread that joins a child of the caller's thread group, so the source query's synchronous executor allocates its CPU lease in the caller's workload. The caller's executor thread meanwhile waits in ExternalLoader::LoadingDispatcher::loadImpl and kept its CPU slot. In a workload with max_concurrent_threads = 1 the source executor is preempted after its first quantum and waits for that slot forever, so the query hangs until max_execution_time or KILL QUERY. Both loadImpl overloads now wait through one helper that parks the waiting thread's CPU lease with CPULeaseParkGuard (ClickHouse#117711) for the duration of the wait. Parking may block until the scheduler thread processes a pending request, so the loader mutex is released around it; unparking never blocks and runs under the mutex, so the predicate result and `info` are read under the lock as before. A NO_WAIT probe and an already loaded object do not park. The regression test uses an aggregating view as the dictionary source: the hang needs the source executor's first pull to use at least one quantum, which a plain table source reaches only sometimes on release builds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fold the waitForLoading doc into one line and drop the NO_WAIT comment. 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; 0 findings), plus my own cold review (3 nits, none in the code path).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261108-121300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261108-110800 |
|
cc @serxa @nihalzp, could you review this and add the |
|
Workflow [PR], commit [db02c66] Summary: ✅
AI ReviewSummaryReviewed PR #130133 at The new Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline. |
|
I found the fix good. |
1013883
Related: #88304
Related: #117711
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a hang of a query in a CPU workload that is the first to use a dictionary with a
ClickHousesource (dictGet,dictHaswith a non-constant key) and runs no more threads than the workload's CPU slots (for examplemax_concurrent_threads = 1withmax_threads = 1). The waiting query kept its CPU slot, which the dictionary load in the same workload needed; now it releases the slot while it waits.Description
On 26.10.2.103, with
CREATE RESOURCE cpu (MASTER THREAD, WORKER THREAD), a workloadonewithmax_concurrent_threads = 1and aHASHEDdictionary over an aggregating view,SELECT count() FROM numbers(1) WHERE dictHas('d', number + 1) SETTINGS workload = 'one', max_threads = 1never finishes (6/6; 5/7 with a plain table source, every time on a debug build). Found while working on #88304.A lazy load runs on an
ExternalLoaderthread in the caller's thread group, so the source query's executor takes a CPU lease in the caller's workload. The caller's thread waits inExternalLoader::LoadingDispatcher::loadImpland keeps its slot; the source executor is preempted after one quantum and waits for that slot forever.Now
loadImplparks the waiting thread's CPU lease (CPULeaseParkGuardfrom #117711) for the wait, in both overloads, which also covers a dictionary whose source query reads another dictionary. ANO_WAITprobe and an already loaded object do not park.Not covered: when the query runs more threads than the workload's CPU slots, parking all of them still frees no slot; #126512 addresses that separately, and this PR does not depend on it;
cpu_slot_parking = 0and separate MASTER / WORKER THREAD resources are unchanged, as in #117711.Tests: a stateless test. It fails on the master release build of the same commit (6/6
TIMEOUT_EXCEEDED) and on a debug build, and passes 50/50 with random settings and in the ParallelReplicas, DBReplicated, distributed plan, s3 storage and AsyncInsert configurations. The aggregating view makes the source query spend several CPU quanta before its first block, which is what makes the hang deterministic on release builds.Workflow [PR]
Sync PR [sync-upstream/pr/130133]
Version info
26.11.1.1680-master(included in26.11and later)