Skip to content

Cherry pick #113322 to 26.5: fs cache download wait timeout - #113819

Merged
robot-ch-test-poll3 merged 10 commits into
backport/26.5/113322from
cherrypick/26.5/113322
Aug 7, 2026
Merged

robot-ch-test-poll3 merged 10 commits into
backport/26.5/113322from
cherrypick/26.5/113322

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #113322

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

kssenii and others added 9 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]>
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]>
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]>
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Aug 7, 2026
@kssenii

kssenii commented Aug 7, 2026

Copy link
Copy Markdown
Member

Resolved the conflicts (merged the base backport/26.5/113322 into this branch).

Common to all cherry-picks of #113322

  • src/Common/FailPoint.cpp / FileSegment.cpp — the master hunks pulled in neighbouring failpoints that do not exist on this branch (file_cache_pause_before_do_eviction, file_cache_simulate_evicting_segment, cache_filesystem_failure_non_errno, ...). Only file_segment_pause_before_write was kept.
  • FileSegment::wait — the branch still has the old single cv.wait_for(lk, 60s, ...) form, while master has the 1-second-slice loop with query_status->throwIfKilled(). The loop was reintroduced with the timeout_ms deadline, but without query_status, which does not exist in FileSegment on this branch. Behaviour of the backported change is unaffected: the kill check is an unrelated master-only feature.
  • src/Core/SettingsChangesHistory.cpp — this is the important one. The three-way merge silently re-added whole newer version sections from master into this branch's history file. Those entries reference settings that do not exist here, and SettingsImpl::applyCompatibilitySetting calls getTier(name), which throws UNKNOWN_SETTING for an unknown name — so any SET compatibility = '<older version>' would start failing. The file was reset to the branch version and only the single entry for filesystem_cache_wait_for_concurrent_download_timeout_milliseconds was added, to this branch's own top section (same convention as the earlier backports on this branch).

Specific to 26.5

ReadSettings on this branch is still flat — the HTTPReadSettings / PageCacheSettings / FilesystemCacheSettings split is master-only. So instead of filesystem_cache_settings.wait_for_concurrent_download_timeout_milliseconds the field is ReadSettings::filesystem_cache_wait_for_concurrent_download_timeout_milliseconds, set accordingly in Context::getReadSettings and read as info_.settings.filesystem_cache_wait_for_concurrent_download_timeout_milliseconds in CachedOnDiskReadBufferFromFile.

Not built locally; relying on CI for the backport PR.

@robot-ch-test-poll3
robot-ch-test-poll3 merged commit ebc4581 into backport/26.5/113322 Aug 7, 2026
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.5/113322 branch August 7, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants