Skip to content

fs cache download wait timeout - #113322

Merged
kssenii merged 8 commits into
masterfrom
fs-cache-download-wait-timeout
Aug 7, 2026
Merged

kssenii merged 8 commits into
masterfrom
fs-cache-download-wait-timeout

Conversation

@kssenii

@kssenii kssenii commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added fs cache download wait timeout configured by filesystem_cache_wait_for_concurrent_download_timeout_milliseconds. This timeout defined only the wait for a single chunk (buffer bytes of ~1mb) of data, not the whole file segment.

Version info

  • Backported to: 26.7.6.47, 26.6.4.30, 26.3.28.4

kssenii and others added 2 commits August 3, 2026 20:56
…timeout

A read which needs a file segment in `DOWNLOADING` state waited for the
downloader indefinitely: `FileSegment::wait` has a 60 s deadline, but the
caller looped and waited again. The downloader role is held by another query
for as long as it is reading the segment, so a fast point read could stall
behind an arbitrarily slow foreign query downloading the same segment.

Add the setting `filesystem_cache_wait_for_concurrent_download_timeout_milliseconds`
(default 1 second). When the timeout is reached, the read bypasses the cache
for that range and reads directly from remote storage, while the concurrent
download continues to fill the cache. Value `0` means bypass immediately.
The new profile event `CachedReadBufferDownloadWaitTimeouts` counts such
bypasses, and the new pauseable failpoint `file_segment_pause_before_write`
allows reproducing the stall in tests.

Co-Authored-By: Claude Fable 5 <[email protected]>
…aller

Rename the profile event `CachedReadBufferDownloadWaitTimeouts` to
`FileSegmentWaitTimeouts` and increment it inside `FileSegment::wait` when
the wait deadline expires. The cached read buffer no longer tracks a
deadline of its own: `wait` returning a state which is still `DOWNLOADING`
without usable progress is the timeout signal, so the `DOWNLOADING` branch
just bypasses the cache in that case and continues otherwise.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4c41771]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) FAIL
Logical error: 'database_name != "_temporary_and_external_tables"' (STID: 2508-48e6) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR adds filesystem_cache_wait_for_concurrent_download_timeout_milliseconds, makes waiters bypass the filesystem cache after that timeout, and adds a stateless failpoint test for the new path. The timeout logic itself is coherent, but the compatibility mapping still does not restore the pre-26.8 behavior, so I would not merge it as-is.

Findings

❌ Blockers

  • [src/Core/SettingsChangesHistory.cpp:73] [dismissed by author -- https://github.com/fs cache download wait timeout #113322#discussion_r3712677819] compatibility = '26.7' still changes read behavior. Before this PR, a waiter that met a DOWNLOADING segment kept re-entering FileSegment::wait and could wait indefinitely while the downloader stayed alive. In the current code, compatibility only sets filesystem_cache_wait_for_concurrent_download_timeout_milliseconds = 60000, and src/Disks/IO/CachedOnDiskReadBufferFromFile.cpp:670 now turns the first timed-out wait into REMOTE_FS_READ_BYPASS_CACHE instead of looping again. That means older compatibility modes still start issuing duplicate remote reads after one minute on slow downloads, which violates the compatibility contract.
    Suggested fix: represent the old mode as an explicit unbounded-wait behavior instead of approximating it with 60000, and map compatibility to that behavior.
Tests

⚠️ Add a focused regression for SET compatibility = '26.7' that keeps the downloader alive past 60 seconds and proves the waiter still blocks instead of bypassing the cache. The new stateless test covers only the new timeout path.

Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 67/67 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 4, 2026
@kssenii
kssenii requested a review from nickitat August 4, 2026 12:32
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@nickitat nickitat self-assigned this Aug 4, 2026
The one-time pause failpoint must be consumed by the downloader query, but
two other writers could take it first and let the downloader run unimpeded,
leaving the waiter with nothing to wait on (the flaky check failed with `0`
instead of `1` in the profile event check):

- the mark-cache warmup query ran with default prefetch settings, and its
  abandoned prefetch tasks could still write to the cache from reader-pool
  threads after the client had already returned;
- background download of partially downloaded segments could leak cache
  writes into the next iteration of the flaky check.

Make the warmup query strictly synchronous, disable background download in
all three queries, and assert that exactly one file segment is DOWNLOADING
after the failpoint pause, so a stray consumer fails the test explicitly
instead of making it vacuous.

Failed CI: https://github.com/ClickHouse/ClickHouse/actions/runs/30908188704/job/92013126246
Related PR: #113322

Co-Authored-By: Claude Fable 5 <[email protected]>

if (download_state == FileSegment::State::DOWNLOADING && !canStartFromCache(offset, file_segment))
{
LOG_TRACE(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe LOG_TEST?

kssenii and others added 3 commits August 4, 2026 22:07
The flaky check showed the test is not isolated from server background
activity: a background merge of `test.hits_s3` writes through the shared
`s3_cache` and can fill it with non-releasable segments. The downloader's
space reservation then fails, so it silently continues without caching and
never reaches the failpoint, while the merge consumes the one-time pause
instead (`FileSegmentWaitTimeouts` stayed `0` and the `DOWNLOADING` count
saw the merge's segment).

Rework the test to not depend on the shared cache at all:
- the table uses a private inline cache disk over `local_disk`, so no other
  cache user can fail its reservations, and `max_file_segment_size` covers
  the whole data file so the waiter never becomes a downloader itself;
- the failpoint is `PAUSEABLE` instead of `PAUSEABLE_ONCE`: every cache
  write pauses while it is enabled, so an unrelated writer cannot steal it
  (it just pauses too and resumes on disable);
- after `SYSTEM WAIT FAILPOINT` the test additionally polls until the
  private cache holds exactly one `DOWNLOADING` segment, since the first
  pause on the server is not necessarily the downloader's.

Verified locally: 25 consecutive runs pass with a concurrent workload
inserting into and merging a cache-on-write table on the shared `s3_cache`.

Failed CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113322&sha=c5f7fd81a5824409956120442597006de4a5935a&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
Related PR: #113322

Co-Authored-By: Claude Fable 5 <[email protected]>
`file_segment_pause_before_write` is a server-global `PAUSEABLE`
failpoint, so a script that aborts between `SYSTEM ENABLE FAILPOINT` and
the explicit disable at the end left every filesystem cache write on the
server paused: the following tests would hang behind it and mask the
original failure. Add a `trap` right after enabling the failpoint that
always disables it, ignoring cleanup errors.

Addresses #113322 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
@kssenii
kssenii enabled auto-merge August 5, 2026 19:46
@kssenii kssenii added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 5, 2026
@kssenii
kssenii added this pull request to the merge queue Aug 7, 2026
Merged via the queue into master with commit f5e7b58 Aug 7, 2026
178 of 180 checks passed
@kssenii
kssenii deleted the fs-cache-download-wait-timeout branch August 7, 2026 12:56
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 7, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 7, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Aug 7, 2026
Cherry pick #113322 to 25.8: fs cache download wait timeout
robot-ch-test-poll3 added a commit that referenced this pull request Aug 7, 2026
Cherry pick #113322 to 26.3: fs cache download wait timeout
robot-ch-test-poll3 added a commit that referenced this pull request Aug 7, 2026
Cherry pick #113322 to 26.5: fs cache download wait timeout
robot-ch-test-poll3 added a commit that referenced this pull request Aug 7, 2026
Cherry pick #113322 to 26.6: fs cache download wait timeout
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 7, 2026
kssenii added a commit that referenced this pull request Aug 9, 2026
Backport #113322 to 26.5: fs cache download wait timeout
nickitat added a commit that referenced this pull request Aug 27, 2026
Backport #113322 to 26.6: fs cache download wait timeout
kssenii added a commit that referenced this pull request Aug 28, 2026
The conflict resolution commit copied several master-only hunks that are
not part of #113322: the `AsyncLoaderSpawnFailures` and
`SelectivityEstimatorInSet*` profile events, memory-order changes in
`ProfileEvents::Counters`, the `file_size_mutex` locking in
`CachedOnDiskReadBufferFromFile` (the mutex does not even exist on this
branch), the `statistics_max_set_size_for_exact_selectivity_estimation`,
`analyzer_compatibility_multiple_joins_qualify_column_names` and
`throw_on_hive_partitioning_resolution_failure` settings with their
changes-history entries, and assorted setting description rewordings.

Restore every file to the branch state plus exactly the hunks of the
original pull request, and record the new setting in the existing 26.8
section of `SettingsChangesHistory.cpp`, where master records it.

Co-Authored-By: Claude Fable 5 <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #113322 to 26.7: fs cache download wait timeout
kssenii added a commit that referenced this pull request Aug 31, 2026
Backport #113322 to 26.3: fs cache download wait timeout
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants