Repository navigation
Add asynchronous query-slot admission for refreshable materialized views - #112808
vanchaklar wants to merge 20 commits into
Conversation
|
@serxa, could you take a look at this when you have a chance? This touches the workload query-slot path and the boundary between the resource scheduler and The main design point is that an RMV with I'd particularly appreciate your thoughts on whether the asynchronous |
|
Friendly follow-up, @serxa. Since the previous ping, I tightened the scheduler boundary:
The PR is mergeable, but CI has not started and there has not been a review yet. Could you confirm whether asynchronous |
|
@al13n321, could you also review the refreshable-MV side of this change? You authored the RMV implementation and have maintained The scheduler-side question is already with @serxa. On the RMV side, the key behavior is that The PR is mergeable, but has not received CI or a formal review yet. |
|
Why not take |
|
@al13n321, good question. I placed The refresh-level workload applies to the complete refresh:
If both settings are present, the refresh-level workload takes precedence: REFRESH ... SETTINGS workload = 'refresh_workload'
AS SELECT ...
SETTINGS workload = 'select_workload'In this case, the complete refresh uses If no refresh-level workload is specified, the SELECT-level workload keeps its existing behavior. It applies to refresh execution, but it does not enable admission before Keeping the setting at the refresh level also allows users to move an RMV to another workload with There are a few possible designs:
I chose the first option because it is explicit, consistent, and easy to change operationally. I agree that the scope and precedence should be documented clearly. |
|
@al13n321, a quick follow-up: I addressed your state-check comments, clarified the refresh-vs-SELECT workload semantics, expanded the related tests, and synced the branch with current master. The PR is mergeable now. When you have a chance, could you take another look and let me know if the RMV side is in better shape? |
|
@serxa , can you please review the scheduling part (ProcessList, QuerySlot)? |
|
Workflow [PR], commit [1ebfd81] Summary: ❌
|
Build profile diff (arm_release)Commit See the job log for details. |
There was a problem hiding this comment.
I like the idea, thanks! A few things before it's mergeable:
-
Don't use a separate refresh-level workload - take one from SELECT. Admission should use the workload that the refresh runs under. The same way memory reservations already do: admission is based on the same workload. Two workload knobs is an ambiguity we'd carry forever. Refreshes now competing for query slots is backward-incompatible, so gate it behind a server setting
use_query_slot_to_refresh_materialized_view(default off, we flip on later once query slots are common). This mirrors the way, e.g.,cpu_slot_preemptionhandled its transition. Server settings can be easily depreciated later, and SQL syntax is almost impossible to change. -
Split QuerySlot's two roles. It currently both holds a granted slot (its real job) and talks to the scheduler. Introduce
IQuerySlot(withusing QuerySlotPtr = std::unique_ptr<IQuerySlot>), keep the existing synchronous QuerySlot as-is, and make the async variant an inner class ofRefreshTaskwired directly to the task's own state; shared bits (metrics) can sit in aQuerySlotBase. That lets you drop thestd::functionthe scheduler thread currently runs.ResourceRequest::execute()is meant to be fast, and arbitrary callbacks don't belong on that thread. -
ProcessList::insertshouldn't callwait(). A slot handed to insert should already be granted. Insert's only job is to adopt it and tie its lifetime to theQueryStatus. Do the waiting (really, the grant/failure resolution) in the refresh path: with the async slot,RefreshExecis dispatched only once the slot is granted, so by the time we reach insert the outcome is known, and a failed or cancelled admission errors out before insert is ever called. That also letsforce_query_slotgo away. It exists only to force insert to acquire a slot for an otherwise-unlimited internal query, but if the refresh pre-acquires and passes an already-granted slot, insert can simply adopt whatever slot it's given and the flag is unnecessary. -
Handle
WaitingForResourceon shutdown. Theis_shutdownpaths still only normalizeRequested. A refresh cancelled while queued for a slot can leaverefresh_running/ the/runningznode uncleared until the Keeper session expires, so other replicas keep treating it as in flight. The failing..._wait_can_be_stoppedtest looks like exactly this. -
Put the docs in
ParserCreateQuery.cpp. Theview.mdxchange is inside an autogenerated block.
Follow the scheduler review: add default-off `use_query_slot_to_refresh_materialized_view`, separate `IQuerySlot` ownership from synchronous admission, and keep asynchronous admission inside `RefreshTask`. Adopt granted slots in `ProcessList` without waiting or a force flag. Preserve current master shutdown fixes, normalize queued refreshes on shutdown, rebuild execution context from current metadata after admission, and retain the old design on `agent/refreshable-mv-workload-refresh-setting-checkpoint`. Move generated view documentation to `ParserCreateQuery.cpp` and add integration coverage for compatibility, admission, cancellation, failure, definition changes and Keeper cleanup. Use CI for ClickHouse build and integration validation. Related: ClickHouse#112808 Review: ClickHouse#112808 (review)
Release a granted slot when `STOP` or `PAUSE` interrupts a refresh before execution starts. Release the refresh query slot before table exchange and error cleanup. Add failpoint coverage for both lifetime boundaries. Record `runtime_workload` in the settings history to unblock the fast test. Related: ClickHouse#112808
Use the refresh-specific name in the setting, implementation, history, documentation, and integration tests. Behavior and defaults are unchanged.
Resolve the `SettingsChangesHistory.cpp` overlap by preserving `refresh_workload` and the new join-order settings. Related: ClickHouse#112808
Yep, the workload for DDL is not addressed yet at all, you are right. I think this should be a separate, wider topic. We will have a new |
|
@serxa |
| - [Workload Scheduling](/concepts/features/configuration/server-config/workload-scheduling) | ||
| )", 0) \ | ||
| DECLARE(Bool, use_query_slot_to_refresh_materialized_view, false, R"( | ||
| When enabled, refreshable materialized views request a query slot before starting refresh execution. The stored SELECT setting `refresh_workload` selects the refresh workload; when empty, the existing `workload` setting is used. This requires a configured QUERY resource for that workload. While queued, the refresh reports `WaitingForResource` in `system.view_refreshes` without occupying a background execution worker. |
There was a problem hiding this comment.
The contract in this doc string is too narrow now. Enabling use_query_slot_to_refresh_materialized_view does not only matter when the workload has a QUERY resource: ProcessList::insert now forces internal RMV refreshes through workload resources in general, so they also wait/fail on a workload MEMORY RESERVATION resource when reserve_memory is set, even if there is no QUERY resource at all. test_refresh_uses_memory_reservation_resource covers exactly that shape.
As written, this tells operators the setting has no effect unless they configure QUERY, but the current code changes refresh behavior for memory-limited workloads too. Please document the broader contract here and then describe the QUERY-slot part as the async pre-start wait.
|
Watch your bot. |
restrictions applied for the bot. |
Consolidate the later compatibility, query-slot deadline, cancellation, initial memory-reservation and shutdown fixes without temporary helper workflows. Keep the earlier implementation history through debb128. Preserve Alexey Milovidov's merge-resolution contributions from 3a4eab9 and b336418. The original history remains at backup/pr112808-before-cleanup-20261011-b3364185. Related: ClickHouse#112808 Co-authored-by: Alexey Milovidov <[email protected]>
b336418 to
ffebb9f
Compare
Use the normal stored `SELECT` setting `workload` for refresh admission and execution. Remove `refresh_workload` and nested setting rewrites; metadata statements follow `metadata_workload` and `use_metadata_workload`. Use `ResourceLink::enqueue` so asynchronous admission carries the query's scheduling context. Cover fair, LAS and priority scheduling, plus append and replacement refreshes in Atomic and Replicated databases with metadata scheduling enabled and disabled. Preserve timeout, cancellation, memory admission and bounded-pool starvation coverage. Clarify the initial memory-reservation contract and move the system-table description into structured documentation instead of generated output. Related: ClickHouse#112808 Related: ClickHouse#118419
…scheduling Remove `refresh_workload` and nested query rewriting. Keep asynchronous admission on the stored `SELECT` workload, with classifier-aware enqueue, query-aware scheduler coverage, cancellation, and the starvation regression. Keep metadata scheduling implementation and its integration-only test matrix out of this branch. It is a separate dependency: ClickHouse#118419 Create test views before installing constrained resources where existing metadata admission would otherwise block setup. Runtime slot limits, memory limits, cancellation assertions, and starvation invariants are unchanged. This corrects dependency inclusion in: ClickHouse#112808 Validation: Python syntax, XML parsing, source and graph checks. C++ builds and integration execution require CI; no runtime pass is claimed.
ffebb9f to
b237d36
Compare
4ca519d to
1ebfd81
Compare
Closes: #85741
Related: #101902
Related: #118419
Depends on #118419 for independent metadata statement scheduling. That dependency's commits and implementation are not included in this PR; this PR continues to target
master. Refresh admission and execution use the normalworkloadsetting from the storedSELECT, with no separate refresh workload setting. Until the dependency lands,CREATEstill participates in the storedSELECTworkload and can wait for its resources; replicated creation with a one-slot workload can also self-block. The dependency provides the separatemetadata_workloadbehavior. This PR does not claim to fix metadata/runtime isolation by itself.The default-off server setting
use_query_slot_to_refresh_materialized_viewmakes refreshes participate in workload query-slot and initial memory-reservation admission. A refresh queues asynchronously for a configuredQUERYresource and reportsWaitingForResourcewithout occupying a background execution worker. Initial memory reservations also apply when configured withreserve_memory, including workloads without aQUERYresource.workload_admission_timeout_msbounds the combined admission wait.IQuerySlotseparates slot ownership from admission. The synchronousQuerySlotkeeps its existing behavior,RefreshTaskowns asynchronous admission, andProcessListadopts the granted slot. STOP, PAUSE, drop and shutdown cancel pending admission and release coordination state. Execution rebuilds the context andSELECTfrom current metadata after admission; a changed workload requires a new admission attempt. Query-aware schedulers receive the classifier-owned scheduling context throughResourceLink::enqueue.Integration coverage includes default-off compatibility, queued and immediate admission, query-aware scheduling and priority ordering, no
QUERYresource, timeout and memory-admission cancellation, stop/pause/drop races, metadata changes while queued, replicated cleanup. Test setup creates views before installing constrained resources where existing metadata admission would otherwise block setup; the refresh-time limits and assertions are unchanged. Metadata/runtime-isolation integration cases are kept separately for validation with the dependency and are not in this PR. The starvation regression uses five background workers, ten long refreshes sharing one slot, and 100 views refreshing every second; it checks each fast view through a slow-refresh slot handoff. Local Python/XML, source and history checks passed. C++ builds and integration execution remain for CI; no runtime pass is claimed.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the default-off server setting
use_query_slot_to_refresh_materialized_viewso refreshable materialized views can participate in workload admission using their storedSELECT'sworkload. Refreshes wait asynchronously for query slots, reportingWaitingForResourcewithout occupying a background execution worker, and pending query-slot or initial memory-reservation admission can be cancelled.Workflow [PR]
Sync PR [sync-upstream/pr/112808]