Repository navigation
Raise the per-type task limit of a background schedule pool when its size is increased at runtime - #128899
Conversation
`BackgroundSchedulePool` lets at most `max_parallel_tasks_per_type` tasks of one callable type run at once (ClickHouse#84008). The limit was fixed at construction: 0 meant the startup pool size, and the main schedule pool got `startup_size * background_schedule_pool_max_parallel_tasks_per_type_ratio` from `Context`. `increaseThreadsCount`, which `SYSTEM RELOAD CONFIG` calls for the five resizable pools, raised the thread cap but never the per-type limit. Every consumer of every Kafka table runs the same closure, so they form one group: once that group hit the old limit it was dropped from `runnable_task_types`, the eager spawn counted no demand for it, and the extra threads were never used until a restart (ClickHouse#128878). The pool now stores the ratio (0 = no limit beyond the pool size) and derives the limit from the current size with the formula `Context` used. On a resize the limit becomes the larger of the current and the recomputed value: a truncated product maps to the pool size, so the recomputed value can be lower (ratio 0.4: size 2 -> 2, size 3 -> 1), and lowering it while a group already runs more tasks would break the `num_running < max_parallel_tasks_per_type` invariant. When the limit grows, groups paused at the old limit are put back into `runnable_task_types` and parked workers are woken, so idle workers and the existing eager spawn both see that demand. The startup limit of every pool is unchanged. Closes ClickHouse#128878 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A group can already be in `runnable_task_types` when `increaseThreadsCount` raises the limit: a worker that has just finished one of its tasks re-adds it with `notify_one` and is not yet idle. The eager spawn then counts every parked worker as a taker, so with the old conditional `notify_all` some of them stayed asleep and the group ran below the new limit. Notify on every raise. `IncreaseThreadsCountNeverLowersPerTypeLimit` now schedules a second wave after the first one has finished and requires it to run two tasks at once, so a lowered limit fails the test instead of being seen only by `chassert`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ype limit test The task body counts a task as finished before the pool decrements the group's running count after the function returns, so the second wave could be scheduled while the first one was still accounted. A lowered limit could then pass in a release build or abort on the chassert in a debug build. Waiting until getTasks() is empty (running_tasks.erase and the running-count decrement share one tasks_mutex section) makes the assertion the only way a lowered limit can fail the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten two comments in increaseThreadsCount to bare invariants. 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; 3 runs, 4 findings; the last run on the final head found none) plus my own review of the same tree.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261103-080300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261103-050900 |
|
cc @tavplubix @antaljanosbenjamin, could you review this and add the |
|
Workflow [PR], commit [1ff5c9a] Summary: ✅
AI ReviewSummaryThe PR fixes runtime increases of background schedule pools by raising their per-type concurrency limits, restoring paused task groups, and waking parked workers. No actionable findings remain in the current diff or prior discussion. Missing context / blind spots
Final Verdict✅ Approve based on code review and existing regression evidence, subject to required current-head CI. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units125 translation units recompiled, 1372 s compile time in total, 125 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
@groeneai can you add the integration test for the kafka engine scenarios |
…hedule_pool_size The server starts with a message broker pool of 2, four Kafka tables with materialized views over empty topics keep their streaming tasks busy, and the test raises the pool to 8 with SYSTEM RELOAD CONFIG. All four tasks must then run at once. It covers both the old Kafka engine and Kafka2. On master both cases stay at 2 running tasks after the reload (BackgroundMessageBrokerSchedulePoolSize already reports 8); with the fix both reach 4. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Added in 78fd44f: Locally it passed 10/10 with the fix. With a master binary both cases fail at 2 running tasks, while |
The previous run on 78fd44f was cancelled by a CI-wide cancellation before most jobs ran. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 6a30f01Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261105-190008 |
|
@groeneai since this issue is a bug , it needs to be backported to the 26.4 and all later major versions. |
|
I can't add labels on this repo, so the backport label has to come from a maintainer. 26.3 (LTS, still supported) also contains #84008; |
Backport #128899 to 26.8: Raise the per-type task limit of a background schedule pool when its size is increased at runtime
Backport #128899 to 26.10: Raise the per-type task limit of a background schedule pool when its size is increased at runtime
Backport #128899 to 26.9: Raise the per-type task limit of a background schedule pool when its size is increased at runtime
…nd schedule pool when its size is increased at runtime
…nd schedule pool when its size is increased at runtime
…und schedule pool when its size is increased at runtime
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
SYSTEM RELOAD CONFIGnot taking full effect for an increasedbackground_message_broker_schedule_pool_sizeor anotherbackground_*_schedule_pool_sizesetting: the streaming consumers ofKafka,RabbitMQ,NATSandFileLogtables kept running at most as many at once as the startup pool size allowed, until a restart. This was a regression in 25.9.Description
Closes: #128878
Related: #84008
Since #84008 (25.9) a schedule pool runs at most
max_parallel_tasks_per_typetasks of one callable type at once. That limit was computed once from the startup pool size (timesbackground_schedule_pool_max_parallel_tasks_per_type_ratiofor the main pool, the pool size for the others), andincreaseThreadsCount, whichSYSTEM RELOAD CONFIGcalls for the fiveIncreaseOnlypool sizes, raised only the thread cap. All consumers of all Kafka tables share one closure type, so after a reload they stayed capped at the old size; a group already at the limit was not even counted as demand for new threads.On 26.8.34.13 and 26.10.2.103, with
background_schedule_pool_size4 and the ratio 1, raising the size to 16 and runningSYSTEM RELOAD CONFIGis reported bysystem.server_settings, but only 4 of 6 FileLog tables whose streaming tasks each hold a worker ingest until a restart; 25.3.14.14 ingests all 6 right after the reload.The pool now keeps the ratio and derives the limit from its current size with the same formula as at startup, so startup limits do not change. On a resize the limit is only ever raised (a truncated product can come out lower while groups already run that many tasks); groups paused at the old limit become runnable again and parked workers are woken.
Validation: three new gtests in
gtest_BackgroundSchedulePool.cpp.IncreaseThreadsCountRaisesSameTypeLimitfails on master (2 of 4 tasks run afterincreaseThreadsCount(4)); the other two use the newdoubleparameter and do not compile on master. End to end (6 FileLog tables, pool 8 -> 16, ratio 0.5), all 6 ingest within 1 s of the reload with the fix, while master stays at 4. The integration testtest_storage_kafka/test_message_broker_pool_resize.py(Kafka and Kafka2, pool 2 -> 8) runs 4 streaming tasks at once after the reload; master stays at 2.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128899]
Version info
26.11.1.1643-master(included in26.11and later)