Repository navigation
Make the filesystem cache download wait honor query cancellation - #109116
Merged
murphy-4o merged 2 commits intoJul 2, 2026
Merged
Conversation
A reader that finds a file segment DOWNLOADING waits on it in FileSegment::wait(), which only woke on download completion (60s timeout, then the caller re-loops). So a stalled or dead downloader could block the reader for a long time even after its query was cancelled (KILL QUERY) — pipeline cancellation never reaches a thread parked in this wait. Check CurrentThread::get().isQueryCanceled() before entering the wait and throw QUERY_WAS_CANCELLED; the caller re-enters wait() each loop, so a cancel that lands mid-wait is caught next round. This mirrors how StorageSharedMergeTree guards its own blocking waits. Also cancel the running refresh query in RefreshTask::interruptExecution (not just the pipeline executor), so dropping/stopping a refreshable materialized view whose refresh is blocked in such a wait returns promptly instead of blocking shutdown() -> deactivate() on the whole in-flight refresh. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [f60e231] Summary: ❌
AI ReviewSummaryThis PR makes Missing context / blind spots
Tests
Final VerdictNeeds focused regression coverage before merge. |
FileSegment::wait() parked in a single cv.wait_for(..., 60s) that is only woken on download progress, so a thread already asleep there did not observe query cancellation until the timeout expired. DROP / SYSTEM STOP VIEW of a refreshable materialized view whose refresh was stuck in this wait could sit in deactivate() for up to a minute. Wait in 1s slices and re-check the query's QueryStatus each slice via throwIfKilled(), which also re-raises the original cancellation reason (KILL QUERY / max_execution_time / ...) instead of a generic QUERY_WAS_CANCELLED. The overall 60s budget and the cache-hit fast path are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
murphy-4o
marked this pull request as ready for review
July 2, 2026 08:24
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 36/37 (97.30%) · Uncovered code |
kssenii
approved these changes
Jul 2, 2026
murphy-4o
enabled auto-merge
July 2, 2026 13:08
Merged
via the queue into
ClickHouse:master
with commit Jul 2, 2026
c305cbe
344 of 348 checks passed
evillique
added a commit
that referenced
this pull request
Aug 17, 2026
Resolve conflicts and carry the `RefreshTask` part of #109116, which introduced `ExecutionState::executing_query_status` and is absent from 25.8.
evillique
added a commit
that referenced
this pull request
Aug 17, 2026
Resolve conflicts and carry the `RefreshTask` part of #109116, which introduced `ExecutionState::executing_query_status` and is absent from 26.6.
evillique
added a commit
that referenced
this pull request
Aug 17, 2026
Resolve conflicts and carry the `RefreshTask` part of #109116, which introduced `ExecutionState::executing_query_status` and is absent from 26.5.
evillique
added a commit
that referenced
this pull request
Aug 17, 2026
Resolve conflicts and carry the `RefreshTask` part of #109116, which introduced `ExecutionState::executing_query_status` and is absent from 26.3.
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…ble-download-wait Make the filesystem cache download wait honor query cancellation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a hang where a query reading through the filesystem cache could keep waiting on an in-progress download after being cancelled with
KILL QUERY, and where dropping orSYSTEM STOP VIEW-ing a refreshable materialized view whose refresh was stuck in such a wait would block.Description
When a query needs a range of a file segment that another thread is downloading, it waits in
FileSegment::wait(). That wait is only woken on download completion (with a 60s timeout, after which the caller re-loops), and it never checks whether the waiting query has been cancelled. So a stalled or dead downloader can keep a reader waiting for a long time, andKILL QUERY(or pipeline cancellation) has no effect on a thread parked in this wait — cancellation is cooperative and never reaches it.For a refreshable materialized view this is worse:
DROP/SYSTEM STOP VIEWgoes throughRefreshTask::shutdown()→deactivate(), which waits for the whole in-flight refresh to stop. If that refresh is blocked in the cache wait above, the drop/stop hangs, andRefreshTask::interruptExecution()— which only cancels the pipeline executor — doesn't reach it.Fix:
FileSegment::wait()checksCurrentThread::get().isQueryCanceled()before entering the wait and throwsQUERY_WAS_CANCELLED. The caller (CachedOnDiskReadBufferFromFile::prepareReadFromFileSegmentState) re-enterswait()on each loop, so a cancellation that lands mid-wait is observed on the next round. The 60s timeout and the fast path (cache hit / completed download) are unchanged. This mirrors howStorageSharedMergeTreealready guards its own blocking waits.RefreshTask::interruptExecution()additionally cancels the running refresh query through its process-list entry (not just the pipeline executor), so a refresh blocked in I/O actually stops andshutdown()→deactivate()returns promptly.Version info
26.7.1.435(included in26.7and later)