Repository navigation
QueryRunner follow-up: do not occupy threads eagerly - #114522
Conversation
|
Workflow [PR], commit [43b3246] Summary: ✅
AI ReviewSummaryThis PR switches Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 93/99 (93.94%) · Uncovered code |
| while (queue.tryPop(job)) | ||
| finishJob(job.batch, job.seq); | ||
|
|
||
| cluster_executors.cancelAll(); |
There was a problem hiding this comment.
Removing queue.finish() here means shutdown no longer closes the admission path. A QueryRunnerSink that is already inside consume can keep calling submit after shutdown_called flips, and submit will still enqueue some of those rows into the pool until it fills. They only become no-ops later in executeJob, so pool.wait() now waits for the producer to stop feeding rows instead of discarding the tail of the batch immediately.
With a large INSERT ... SELECT, DETACH TABLE / server shutdown can therefore stay blocked arbitrarily long on post-shutdown submissions. Please reject/drop new submissions synchronously once shutdown starts, equivalent to the old finished-queue behavior.
There was a problem hiding this comment.
This is still present in the current code. submit still unconditionally enters pool.trySchedule(...) at src/Storages/StorageQueryRunner.cpp:345, and shutdown() only closes the pool at src/Storages/StorageQueryRunner.cpp:363-366. A producer already inside QueryRunnerSink::consume can therefore keep enqueueing rows in that window after shutdown_called flips, so the admission path is not rejected synchronously yet.
There was a problem hiding this comment.
This is still present in the current head. shutdown() only flips shutdown_called at src/Storages/StorageQueryRunner.cpp:363 and closes the pool at line 366, while submit() still enters pool.trySchedule(...) unconditionally at src/Storages/StorageQueryRunner.cpp:343-346 and checks shutdown_called only after scheduling fails. A producer already inside QueryRunnerSink::consume can still enqueue extra no-op jobs in that window, so post-shutdown submissions are not rejected synchronously yet.
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 units370 translation units recompiled, 2652 s compile time in total, 370 of them have a recent master baseline. |
|
Absolutely everything failed in the CI. Please do not merge without fixing it. |
|
Suddenly #109891 hits CI more often, I will take a look |
|
Segfaults are fixed in #114940 - I think we can wait until it's merged. |
| } | ||
|
|
||
| template <typename Thread> | ||
| void ThreadPoolImpl<Thread>::finishNoLock(const std::lock_guard<std::mutex> &) |
There was a problem hiding this comment.
This new ThreadPool::finish() path now carries a shutdown correctness contract, but there is still no focused regression test for it. The exact race here already needed two follow-up fixes in this PR (job_finished.notify_all() and poisoning remaining_pool_capacity), and nothing under src/Common/tests currently exercises a scheduler blocked on a full bounded pool while another thread calls finish().
Without that coverage it is easy to regress back to scheduleOrThrow hanging after finish() or to spawning a stray worker after shutdown. Please add a small gtest that fills a bounded pool, blocks a second scheduler in scheduleOrThrow or trySchedule, calls finish(), and asserts the waiter returns promptly with CANNOT_SCHEDULE_TASK or false and wait() drains without hanging.
|
@mstetsyuk @azat — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
QueryRunner tables now start worker threads on demand and release them once idle, instead of occupying threads for the table's whole lifetime.
Workflow [PR]
Sync PR [sync-upstream/pr/114522]
Version info
26.8.1.1606(included in26.8and later)