Skip to content

Fix SLRU file cache exception during dynamic resize - #96142

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-slru-dynamic-resize-exception
Feb 7, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-slru-dynamic-resize-exception

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 6, 2026 •

Copy link
Copy Markdown
Member

The stress test (amd_debug) was failing with:

Logical error: 'Cannot modify size limits to 62914560 in size and
3000000 in elements: not enough space freed. Current size:
64273255/188743680, elements: 87/3000000 (s3_cache, protected)'.

Here: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3561bc3928658933a66f6f1c6f28fa517f4eb841&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29&name_1=Stress%20test%20%28amd_debug%29

The exception was thrown from LRUFileCachePriority::modifySizeLimits when it found the protected sub-queue's current size (64.3 MB) exceeded its new limit (62.9 MB).

Root cause: FileCache::doDynamicResizeImpl computed eviction needs based on total cache size vs. desired total limit. When the total cache size was under the new total limit, it concluded no eviction was needed and directly called modifySizeLimits. However, for SLRU the total limit is split between the protected and probationary sub-queues using a ratio. Even when the total fits, the protected sub-queue can exceed its new sub-limit if the data distribution is skewed. The same issue could also affect SplitFileCachePriority which distributes limits between Data and System segments.

Fix: add a virtual method collectEvictionInfoForResize to IFileCachePriority that takes the desired limits (rather than total eviction amounts) and computes per-sub-queue eviction correctly:

  • The default implementation (used by LRU) computes total eviction from total size vs. desired limit, same as before.
  • SLRUFileCachePriority overrides it to compare each sub-queue's current size against its new sub-limit derived from the desired total and the SLRU ratio, ensuring eviction from the protected queue even when the total fits.
  • SplitFileCachePriority overrides it to distribute desired limits between its Data and System segments and delegates to each inner priority's collectEvictionInfoForResize.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Version info

  • Merged into: 26.2.1.368

The stress test (amd_debug) was failing with:

  Logical error: 'Cannot modify size limits to 62914560 in size and
  3000000 in elements: not enough space freed. Current size:
  64273255/188743680, elements: 87/3000000 (s3_cache, protected)'.

The exception was thrown from `LRUFileCachePriority::modifySizeLimits`
when it found the protected sub-queue's current size (64.3 MB) exceeded
its new limit (62.9 MB).

Root cause: `FileCache::doDynamicResizeImpl` computed eviction needs
based on total cache size vs. desired total limit. When the total cache
size was under the new total limit, it concluded no eviction was needed
and directly called `modifySizeLimits`. However, for SLRU the total
limit is split between the protected and probationary sub-queues using
a ratio. Even when the total fits, the protected sub-queue can exceed
its new sub-limit if the data distribution is skewed. The same issue
could also affect `SplitFileCachePriority` which distributes limits
between Data and System segments.

Fix: add a virtual method `collectEvictionInfoForResize` to
`IFileCachePriority` that takes the desired limits (rather than total
eviction amounts) and computes per-sub-queue eviction correctly:

- The default implementation (used by LRU) computes total eviction from
  total size vs. desired limit, same as before.
- `SLRUFileCachePriority` overrides it to compare each sub-queue's
  current size against its new sub-limit derived from the desired total
  and the SLRU ratio, ensuring eviction from the protected queue even
  when the total fits.
- `SplitFileCachePriority` overrides it to distribute desired limits
  between its Data and System segments and delegates to each inner
  priority's `collectEvictionInfoForResize`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e5d9bbe]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan, targeted) failure
03634_autopr_output_bytes_estimation FAIL cidb
Stress test (arm_asan, s3) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue
Stress test (amd_ubsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue
Stress test (amd_msan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue

@kssenii kssenii left a comment •

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.

This bug was introduced in #82764, which was merged in 26.1, which is also visible by CI db. So let's backport this fix to 26.1, because our chineese friends are using this feature.

Please also be aware that Sync PR will also need modifications as there is one more derived class of IFileCachePriority there.

elements_to_evict,
/* reservee */nullptr,
/* is_total_space_cleanup */false,
/* is_dynamic_resize */true,

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.

Please remove is_dynamic_resize flag from collectEvictionInfo and the code which was under this flag to avoid ambiguity because now there is collectEvictionInfo(..., is_dynamic_resize) and collectEvictionInfoForResize, so let's have only one way to do the resize... This should also simplify SLRUFileCachePriority::collectEvictionInfoForResize a little bit as it uses the first one instead of a second.

magic_enum::enum_name(getType()));
}

EvictionInfoPtr IFileCachePriority::collectEvictionInfoForResize(

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.

Let's make derived classes always define the implementation instead of having a default implementation in the base class

alexey-milovidov and others added 2 commits February 7, 2026 00:20
…nInfoForResize` pure virtual

Remove the `is_dynamic_resize` parameter from `collectEvictionInfo` and all
code that was gated behind it. Now resize eviction is handled exclusively
by `collectEvictionInfoForResize`, removing the ambiguity of having two
code paths for the same operation.

Make `collectEvictionInfoForResize` pure virtual in `IFileCachePriority`
instead of providing a default implementation in the base class. Move the
default implementation into `LRUFileCachePriority`. Simplify
`SLRUFileCachePriority::collectEvictionInfoForResize` to delegate to each
sub-queue's `collectEvictionInfoForResize` directly.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov
alexey-milovidov merged commit 59a60cc into master Feb 7, 2026
125 of 129 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-slru-dynamic-resize-exception branch February 7, 2026 04:59
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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