Repository navigation
Saturate the deadline of cluster_function_wait_for_replica_ms instead of overflowing it - #130812
Conversation
…ad of overflowing it `StorageObjectStorageStableTaskDistributor::getAnyUnprocessedFile` computed `steady_clock::now() + wait_for_owner` on the first request of every replica that had no own files left. The setting accepts up to INT64_MAX / 1000 ms, and the sum overflows Int64 nanoseconds at two places: the ms -> ns conversion (for more than INT64_MAX / 1e6 ms) and the addition to `now()` (a bound that moves with uptime). UBSan builds abort; other builds wrap the deadline into the past, so a wait of "practically forever" became no wait. The deadline is now `steady_clock::time_point::max()` whenever `now + wait` is not representable, and `now + wait` (bit-identical to before) otherwise. Its readers are a time point comparison and `wait_until`, which is defined for `max()`. Closes ClickHouse#126101 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; 2 findings; 1 full pass).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20261111-140503 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261111-130900 |
|
Workflow [PR], commit [5e43219] Summary: ✅
AI ReviewSummaryPR #130812 saturates an unrepresentable 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 Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
9b1b6b0
…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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A value of
cluster_function_wait_for_replica_mstoo large for the deadline arithmetic (about 292 years or more) is now honoured as the longest possible wait, instead of overflowing, which skipped the wait. Closes #126101.Description
Closes: #126101
StorageObjectStorageStableTaskDistributor::getAnyUnprocessedFilecomputedsteady_clock::now() + wait_for_owner. The setting accepts up toINT64_MAX / 1000ms, and the sum overflows Int64 nanoseconds in two places: the ms to ns conversion (above ~9.2e12 ms) and the addition tonow()(a bound that moves with uptime, so no clamp constant is exact). UBSan builds abort; other builds wrap the deadline into the past, so the wait is skipped. Results stay correct, so this is anImprovement, not aBug Fix.The deadline is now
steady_clock::time_point::max()whennow + waitis not representable, andnow + wait(unchanged) otherwise. Its readers are a time point comparison andwait_until, which is defined formax()(as inQuerySlot.cpp). I did not use the one-yearsaturatedMillisecondsclamp the issue mentions: it would shorten every configured value between one year and ~292 years, which works today.Validation:
RendezvousHashing.WaitsForOwnerWithHugeWait(the setting's maximum, and the largest value whose conversion fits but whose addition overflows): fails on master (the replica takes the owner's file at once), passes with the fix, 50/50 repeated.05620_cluster_function_wait_for_replica_ms_overflow: aborts a master ASan+UBSan server (signed integer overflow: 9223372036854775 * 1000000atStorageObjectStorageStableTaskDistributor.cpp:218); passes with the fix (10/10 ASan+UBSan, 50/50 debug, randomized). The issue's own query returns3 6with no UBSan report.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130812]
Version info
26.11.1.2020-master(included in26.11and later)