Skip to content

Fix SLRU and SplitFileCachePriority dynamic resize bugs - #102396

Merged
antonio2368 merged 7 commits into
masterfrom
fix-slru-resize-stat
Apr 13, 2026
Merged

antonio2368 merged 7 commits into
masterfrom
fix-slru-resize-stat

Conversation

@antonio2368

@antonio2368 antonio2368 commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

Fix LOGICAL_ERROR abort during SLRU filesystem cache dynamic resize (issue #95983, STID 4012-44fe).

Per-queue stat fix (core bug):
SLRUFileCachePriority::collectCandidatesForEviction shared a single FileCacheReserveStat across both sub-queue passes. The probationary pass accumulated releasable_size, then the protected pass's stopping condition was immediately satisfied by probationary leftovers — so zero protected candidates were collected. modifySizeLimits then threw because the protected queue still exceeded its new limit. Fix: use per-queue local stat objects and merge them afterward.

SLRU recovery path fix:
When eviction fails and entries are restored, they now go back to their original queue (protected or probationary) instead of all defaulting to probationary. EvictionCandidates captures the queue type before invalidation, and a new addForRestore virtual method routes entries back to the correct sub-queue. Recovery uses result_limits = prev_limits since entries existed under those limits.

SplitFileCachePriority::modifySizeLimits no-op guard fix:
The no-op guard compared system_segment_size_ratio (Data/System split) against size_ratio_ (SLRU protected/probationary ratio) — different concepts. This caused real resizes to be silently skipped. Fix: compare only max_size and max_elements.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101427&sha=7b67d034be1a37512c7fbc8c9b428f2eeb0907ba&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29

Closes #95983

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix LOGICAL_ERROR abort during SLRU filesystem cache dynamic resize caused by shared eviction statistics across sub-queues and incorrect recovery path for failed candidates.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.906
  • Backported to: 26.3.14.49

@antonio2368
antonio2368 marked this pull request as draft April 10, 2026 14:33
@antonio2368

Copy link
Copy Markdown
Member Author

Still working on integration tests

@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ebbb5bb]

Summary: ❌

job_name test_name status info comment
Unit tests (tsan) error
Unit tests (msan) error
Unit tests (amd_llvm_coverage) error
Unit tests (asan_ubsan) dropped
LLVM Coverage dropped

AI Review

Summary

This PR fixes two real dynamic-resize correctness issues in filesystem cache: SLRU cross-queue eviction accounting during total cleanup, and failed-eviction restoration routing back to the original SLRU sub-queue. It also fixes a no-op guard bug in SplitFileCachePriority::modifySizeLimits. The fixes are coherent across core code and tests, and I did not find additional high-confidence blockers/majors beyond inline comments already posted by clickhouse-gh[bot].

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 10, 2026
@antonio2368
antonio2368 force-pushed the fix-slru-resize-stat branch from 8064bfc to 77d9742 Compare April 10, 2026 16:08
…ecovery path

Fix `LOGICAL_ERROR` abort during SLRU filesystem cache dynamic resize
(issue #95983, STID `4012-44fe`).

**Per-queue stat fix (core bug):**
`SLRUFileCachePriority::collectCandidatesForEviction` shared a single
`FileCacheReserveStat` across both sub-queue passes. The probationary
pass accumulated `releasable_size`, then the protected pass's stopping
condition was immediately satisfied by probationary leftovers — so zero
protected candidates were collected. `modifySizeLimits` then threw
because the protected queue still exceeded its new limit. Fix: use
per-queue local stat objects and merge them afterward.

**SLRU recovery path fix:**
When eviction fails and entries are restored, they now go back to their
original queue (protected or probationary) instead of all defaulting to
probationary. `EvictionCandidates` captures the queue type before
invalidation, and a new `addForRestore` virtual method routes entries
back to the correct sub-queue. Recovery uses `result_limits = prev_limits`
since entries existed under those limits.

**`SplitFileCachePriority::modifySizeLimits` no-op guard fix:**
The no-op guard compared `system_segment_size_ratio` (Data/System split)
against `size_ratio_` (SLRU protected/probationary ratio) — different
concepts. This caused real resizes to be silently skipped. Fix: compare
only `max_size` and `max_elements`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101427&sha=7b67d034be1a37512c7fbc8c9b428f2eeb0907ba&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29
Related PR: #101427

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@antonio2368
antonio2368 force-pushed the fix-slru-resize-stat branch from 77d9742 to 992169f Compare April 10, 2026 16:12
# Since 100 is also the starting value, we double-check after a delay
# to confirm the thread actually ran.
for _ in range(30):
if get_max_size() == 100:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The loop can exit without proving the failpoint path was exercised.

max_size is already 100 before SYSTEM RELOAD CONFIG, so if get_max_size() == 100 is true immediately, and after the extra sleep(1) the second check can still be 100 even when resize never attempted. In that case this test may pass while not validating the failed-eviction recovery path.

Please gate loop exit on evidence that resize was attempted (for example, a log/metric signal from failed dynamic resize), rather than on max_size == 100 alone.

@antonio2368
antonio2368 marked this pull request as ready for review April 10, 2026 16:18

# Poll for the real resize to complete
for _ in range(30):
if get_max_size() == 10:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ This loop can also pass without proving the resize-to-10 path completed. If get_max_size() never reaches 10 within 30 seconds, the test still continues to assert get_downloaded_size() <= 10, which may already be true from the pre-resize state (e.g., when cached data is small).

Please assert the target is reached after the polling loop, e.g. assert get_max_size() == 10, so the test fails when dynamic resize does not happen.

Replace fragile timing-based polling with log-message-based detection
for the resize failure path, and add explicit `max_size` assertion after
successful resize.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
antonio2368 and others added 2 commits April 13, 2026 08:07
When `use_split_cache` + SLRU are composed, `SplitIterator::getType`
returns `SplitCache_Data`/`SplitCache_System` instead of the inner
`SLRU_Protected`/`SLRU_Probationary` type. This caused `addForRestore`
to route all restored entries to probationary after failed eviction,
reintroducing the queue-corruption bug.

Override `getNestedOrThis` in `SplitIterator` to delegate to the inner
iterator, and use `getNestedOrThis()->getType()` when saving the
original queue type in `EvictionCandidates::removeQueueEntries`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
… test

Replace the hand-rolled sleep+`contains_in_log` loop with the
`count_log_lines`/`wait_for_log_line` pattern, which correctly scopes
the log search to lines written after the test action and avoids
matching stale log entries from earlier test cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.60% +0.10%

Changed lines: 85.83% (103/120) · Uncovered code

Full report · Diff report

antonio2368 and others added 2 commits April 13, 2026 14:42
Add a third cache base path to the test fixture setup/teardown
for testing SLRU resize statistics.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@antonio2368
antonio2368 added this pull request to the merge queue Apr 13, 2026
Merged via the queue into master with commit db951f3 Apr 13, 2026
156 of 161 checks passed
@antonio2368
antonio2368 deleted the fix-slru-resize-stat branch April 13, 2026 20:58
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 13, 2026
@antonio2368 antonio2368 added v26.2-must-backport pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Jun 22, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 22, 2026
robot-ch-test-poll added a commit that referenced this pull request Jun 22, 2026
Cherry pick #102396 to 26.3: Fix SLRU and SplitFileCachePriority dynamic resize bugs
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
kssenii added a commit that referenced this pull request Jun 22, 2026
Backport #102396 to 26.3: Fix SLRU and SplitFileCachePriority dynamic resize bugs
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 23, 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-bugfix Pull request with bugfix, not backported by default 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 v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: Cannot modify size limits to A in size and B in elements: not enough space freed. Current size: C/D, elements: E/F (G) (STID: 4012-44fe)

6 participants