Skip to content

SLRU filesystem cache: promote partially downloaded file segments - #125657

Merged
CheSema merged 9 commits into
masterfrom
slru-promote-partial-segments
Oct 15, 2026
Merged

CheSema merged 9 commits into
masterfrom
slru-promote-partial-segments

Conversation

@CheSema

@CheSema CheSema commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

With the SLRU cache policy, a hit moved a file segment to the protected queue only if it was fully downloaded. A partially downloaded segment stayed in the probationary queue, so a scan could evict the data of narrow reads. With ReaderExecutor, most segments stay partially downloaded.

Now the reader that hits a partially downloaded segment holds its downloader role during the move. Only the downloader reserves space, so no reservation runs during the move. After the move, the segment grows in the protected queue. Adds the FilesystemCachePromotedFileSegments profile event.

Adds FileSegmentWaitWithoutData and FileSegmentWaitWithoutDataMicroseconds: waits for a concurrent downloader that ended because the downloader released the file segment before it downloaded the awaited offset.

Related: #123607

Changelog category (leave one):

  • Performance Improvement

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

The SLRU filesystem cache policy now moves a partially downloaded file segment to the protected queue on a cache hit, as it does for a fully downloaded one. Before, a scan could evict the data of narrow reads from the probationary queue.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125657]

Version info

  • Merged into: 26.10.1.2499-master (included in 26.10 and later)

A hit moves a partially downloaded file segment to the protected queue.
The reader holds the downloader role during the move, so no space
reservation runs concurrently. Add `FilesystemCachePromotedFileSegments`.

Related: #123607
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [34f4c5c]

Summary: ✅


AI Review

Summary

This PR promotes partially downloaded filesystem cache segments into the SLRU protected queue while temporarily holding the downloader role, and adds metrics for promotions and waits ending without the requested data. Reviewed head 34f4c5c02eba7c2af8335342e28975fb29a99a46. Two previously reported cache growth regressions remain in the current code: their safeguards were moved to #125817, which is still unmerged as of 2026-10-15. Request changes pending those safeguards. No new independent inline findings; threads resolved by the author remain resolved.

Findings

⚠️ Majors

  • src/Interpreters/FileCache/FileSegment.cpp:1530: Promotion must preserve a partial segment's ability to finish downloading. With max_size = '4Mi', slru_size_ratio = 0.25, 2 MiB segments and alignment, and background download disabled, a 128 KiB prefix can move into the 1 MiB protected queue. Further reservations use that queue exclusively, and the held segment cannot be downgraded. Growth stops at 1 MiB with PARTIALLY_DOWNLOADED_NO_CONTINUATION, despite 3 MiB of probationary capacity where it could previously finish. Retain oversized segments in probationary, support safe demotion before growth, or land the configuration safeguard before this change.
    [dismissed by author -- https://github.com/SLRU filesystem cache: promote partially downloaded file segments #125657#discussion_r4263224424]
    Still real because the final-size admission check was reverted and the replacement validation is absent from this head.

  • src/Interpreters/FileCache/SLRUFileCachePriority.cpp:627, src/Interpreters/FileCache/FileCache.cpp:3151: Resizing must preserve continuation for already-promoted partial segments. With dynamic resizing enabled, a 2 MiB segment's 128 KiB prefix fits the protected queue of a 16 MiB cache at ratio 0.25. Shrinking the cache to 4 MiB retains the prefix because resize accounts for reserved bytes, leaving its full range larger than the new 1 MiB protected limit. The already-protected access path performs no range-size check; continuation encounters the same permanent cache-write cutoff. Reject the unsafe shrink or demote/evict affected partial segments before applying it.
    [dismissed by author -- https://github.com/SLRU filesystem cache: promote partially downloaded file segments #125657#discussion_r4271231297]
    Still real because the claimed reload safeguard exists only in the separate, unmerged PR Reject an SLRU filesystem cache whose file segment does not fit each queue #125817.

Tests
  • ⚠️ The added stateless test and concurrency test use equal queue sizes and segments smaller than both queues. Add focused evidence for a segment that fits probationary but exceeds protected capacity, and for promotion → shrink → continuation. If configuration rejection is the chosen solution, prove rejection before the cache is created or resized.
Missing context / blind spots
  • ⚠️ Individual test execution could not be confirmed: the Praktika report reports green workflow statuses, but .claude/tools/fetch_ci_report.js returned no individual test results; targeted job artifact requests returned HTTP 403. Local tests were not run. Accessible results for 05394_filesystem_cache_slru_promote_partial_segment and FileCacheTest.SLRUPromotePartiallyDownloadedConcurrent, including TSan coverage, would close this gap.
Final Verdict

⚠️ Request changes. Land or integrate the admission and resize safeguards, with focused regression evidence, before merging this promotion change. Recheck both invariants against the resulting code; a link to an unmerged follow-up does not protect this PR's current behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 13, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. label Oct 13, 2026
@kssenii kssenii self-assigned this Oct 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 1 query(s) improved out of 31 analysed

This PR lets the SLRU filesystem cache move partially downloaded file segments into the protected queue, and adds a profile event that counts promotions. It does not touch query execution or aggregation code. The large Q20 improvement (-43.2%, with CPU time roughly halved) passes the hard trust override and stands, but the diff only explains it if the benchmark cache runs SLRU and was re-fetching URL column segments before; it is worth checking that against base-commit drift. I downgraded the Q33 and Q34 improvements (-6.5% and -6.4%) to not sure: their PR medians are inside master's current range, and both queries have a noisy history. The Q32 suppression (+10.3%, inside master's range) and the borderline Q28 result (+6.9%) both match a PR with no plausible effect on those queries.

clickbench

🟢 1 improved · ⚠️ 4 inconclusive

Flagged queries (5 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🟢 20 improvement 222 126 -43.2% <0.0001 cache: This -43.2% change passes the hard trust override, so the verdict stands, but the cause is unclear. The only link to this PR is that SLRU now keeps partially downloaded segments of the large URL column, which helps only if the benchmark cache uses SLRU.
⚠️ 28 not_sure 1001 1070 +6.9% <0.0001 Borderline +6.9% with mixed signals and noisy measurements on both sides. The cache-priority change does not explain a slowdown on this regex-heavy GROUP BY.
⚠️ 32 not_sure 702 775 +10.3% <0.0001 The +10.3% delta sits inside master's current variance band, and the PR-side measurements were very noisy. No changed code path explains a slowdown here, so the suppression stands.
⚠️ 33 not_sure 1127 1054 -6.5% <0.0001 aggregation: The -6.5% median of 1054 ms is inside master's current band of 962-1202 ms, and this query has a noisy history. A change to cache queue promotion cannot cut GROUP BY URL CPU by about 10%.
⚠️ 34 not_sure 1123 1051 -6.4% <0.0001 aggregation: The -6.4% median of 1051 ms is inside master's current band of 964-1175 ms, and this query has a noisy history. It is the same pattern as Q33 and is not plausibly caused by the cache promotion change.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 60ededab-4276-433e-8ec9-d2c664fc364c
  • MIRAI run: fbf29e22-a901-4d7e-ac9a-a404076126fb
  • PR check IDs:
    • clickbench_45066_1791928055
    • clickbench_45134_1791928058
    • clickbench_45346_1791928111
    • tpch_adapted_1_official_45607_1791928241
    • tpch_adapted_1_official_45637_1791928242
    • tpch_adapted_1_official_45854_1791928352

…queue whole"

A file segment larger than an SLRU queue becomes an invalid cache configuration instead.

This reverts commit ff840e6.
@CheSema
CheSema added this pull request to the merge queue Oct 15, 2026
Merged via the queue into master with commit 7055af3 Oct 15, 2026
178 checks passed
@CheSema
CheSema deleted the slru-promote-partial-segments branch October 15, 2026 16:38
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
JTCunning pushed a commit to JTCunning/ClickHouse that referenced this pull request Oct 17, 2026
PedroTadim pushed a commit that referenced this pull request Oct 20, 2026
…ents"

Reverts #125657 and its test fix #126174: suspected of breaking CI.
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. pr-performance Pull request with some performance improvements 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.

3 participants