Repository navigation
Make the owner wait of cluster_function_wait_for_replica_ms cancellable - #133412
alexey-milovidov merged 3 commits into
Conversation
…able When the file iterator is exhausted, `StorageObjectStorageStableTaskDistributor::getAnyUnprocessedFile` waits on `replica_seen_cv` until `cluster_function_wait_for_replica_ms` passes for a replica that has not asked for tasks yet. The wait runs inside the read-task callback, on an initiator pipeline thread that holds `RemoteQueryExecutor::was_cancelled_mutex`, and nothing checked the query or notified the cv on cancellation: `QueryStatus::cancelQuery` blocks in `RemoteQueryExecutor::cancel` on that same mutex. So `KILL QUERY` and `max_execution_time` waited for the whole interval, and since the deadline saturates for huge values (ClickHouse#130812) such a query never ended. This hung the Stress test (arm_release) on PR ClickHouse#115722 for a fuzzed `icebergLocalCluster('test_cluster_two_shards', ...)` query with `max_threads = 1`. The wait now polls `QueryStatus::checkTimeLimit()` every 100 ms, as the other waits on a query's behalf do (ZooKeeperWaitLimit, DatabaseReplicated, the worker side ReadTaskIterator::next). `cancelQuery` sets `is_killed` before cancelling the executors, so the waiter sees it while the canceller is blocked, throws, and the unwinding releases `was_cancelled_mutex`. With `timeout_overflow_mode = 'break'` the replica gets an empty task. The query status comes from `getProcessListElementSafe()` of the query context; the gtests construct the distributor without one and keep their behaviour. With fewer initiator threads than replicas the owner's request can still sit behind the wait, so the query can still wait until `cluster_function_wait_for_replica_ms`, but that wait now ends on `KILL QUERY` and at `max_execution_time`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261121-140700 |
|
Workflow [PR], commit [f830baa] Summary: ✅
AI ReviewSummaryThe PR makes the replica-owner wait respect query cancellation, execution deadlines, sibling failures, and a satisfied Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units72 translation units recompiled, 672 s compile time in total, 72 of them have a recent master baseline. |
… finished A read task request of a cluster function replica is served under `RemoteQueryExecutor::was_cancelled_mutex`, so while the distributor waits for the files of a replica that has not asked for tasks yet, `cancel` and `finish` of the waiting executor block on that mutex. The pipeline calls them when another branch of the query throws (`cancelWithException`) or a `LIMIT` is satisfied (`onUpdatePorts`). Neither sets `is_killed`, so the `checkTimeLimit` step of the previous commit kept waiting, and the error or the end of the query came only after `cluster_function_wait_for_replica_ms` (never with the saturated value). `cancel` and `finish` now set an atomic flag before they take the mutex. The task iterator receives the flag, and the sliced wait returns an empty task once it is set. Measured with `cluster_function_wait_for_replica_ms = 30000`: a `throwIf` in a `UNION ALL` branch 30.11 s -> 4.62 s, a satisfied `LIMIT` 30.13 s -> 0.93 s. Found by the AI review: ClickHouse#133412 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
887a78e
Related: #125611
Related: #130812
Related: #126101
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
KILL QUERY,max_execution_time, an error in another part of the query and a satisfiedLIMITnow end the wait ofcluster_function_wait_for_replica_msfor a replica of a*Clustertable function or of parallel replicas over object storage. Before, the query and its cancellation waited for the whole interval.Description
Stress test (arm_release)hung on an unrelated PR (report): a fuzzedicebergLocalCluster('test_cluster_two_shards', ...) SETTINGS cluster_function_wait_for_replica_ms = 9223372036854775withmax_threads = 1ran 1484 s withis_cancelled = 1.Once the iterator is exhausted,
StorageObjectStorageStableTaskDistributorwaits for a replica that has not asked for tasks yet, in the read-task callback underRemoteQueryExecutor::was_cancelled_mutex, and nothing checked the query:cancelQueryblocks inRemoteQueryExecutor::cancelon that mutex. Since #130812 such a huge value never ends.The wait now polls
QueryStatus::checkTimeLimit()every 100 ms, like other waits on behalf of a query. It throws onKILL QUERYand onmax_execution_time; withtimeout_overflow_mode = 'break'the replica gets no more tasks. Reverting #130812 would bring back the overflow of #126101; smaller values have waited uncancellably since #125611.RemoteQueryExecutor::cancelandfinishalso set a flag, checked by the wait, before taking the mutex: the pipeline calls them withoutcancelQuerywhen another branch of the query throws or aLIMITis satisfied.With fewer initiator threads than replicas, an owner's request can still sit behind the wait for the whole interval, but
KILL QUERYandmax_execution_timeend it: of 10 runs of the CI query (limit 10 s), 2 ended withTIMEOUT_EXCEEDEDat 10 s and 8 returned the result; master still ran after 52 s.The test reads 20 files with an unreachable second replica (
test_unavailable_shard) and ends the 60 s wait withmax_execution_time = 2,KILL QUERY ... SYNC, and athrowIfor aLIMITin anotherUNION ALLbranch: without the fix each takes 60 s, with it 1-2 s (50/50 randomized runs).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/133412]
Version info
26.12.1.140-master(included in26.12and later)