Skip to content

Implemented SIEVE eviction in cache framework - #123435

Merged
alexey-milovidov merged 70 commits into
masterfrom
continue-pr-62756-sieve-cache-policy
Oct 12, 2026
Merged

alexey-milovidov merged 70 commits into
masterfrom
continue-pr-62756-sieve-cache-policy

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Implements the SIEVE cache eviction policy in the cache framework (CacheBase), available alongside the existing LRU and SLRU policies.

SIEVE is a simple, scan-resistant eviction algorithm: a single "hand" walks a FIFO queue of entries and evicts the first entry whose visited flag is clear, clearing the flag as it passes set entries. See the paper for details: https://junchengyang.com/publication/nsdi24-SIEVE.pdf

This continues the original work by @Vectorshine, brought up to date with master:

  • Reworked SIEVECachePolicy to match the current ICachePolicy interface (CurrentMetrics tracking, maxCount, contains, per-entry OnRemoveEntryFunction), mirroring LRUCachePolicy.
  • Fixed a bug in remove where the stored queue iterator was advanced in place and the wrong node was erased.
  • Added unit tests in gtest_sieve_cache.cpp, including a step-by-step test of the eviction logic.
  • Randomized the mark and uncompressed cache policy across LRU, SLRU and SIEVE in stateless functional tests (ci/jobs/functional_tests.py) and the stress test (tests/docker_scripts/stress_runner.sh). SIEVE is only implemented for the CacheBase-backed caches, so the filesystem cache (backed by FileCachePolicy) is not randomized to it, and it is excluded during bugfix validation, which runs downloaded master-side binaries.

This supersedes #62756 (original work by @Vectorshine, whose commits are preserved here): that PR's head is the fork's master branch, and merging the current master into it cannot be pushed there because the merge touches .github/workflows and the available token lacks the workflow scope.

Closes: #58910
Related: #62756

Changelog category (leave one):

  • New Feature

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

Added a new cache eviction policy SIEVE. It can be selected for the in-memory caches backed by CacheBase, such as the mark cache and the uncompressed cache, via the corresponding *_cache_policy server settings (for example, mark_cache_policy and uncompressed_cache_policy). It is not available for the filesystem cache.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code


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

Version info

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

Vectorshine and others added 30 commits June 18, 2024 22:12
# Conflicts:
#	src/Common/CacheBase.h
#	tests/config/install.sh
#	tests/docker_scripts/stateless_runner.sh
#	tests/docker_scripts/stress_runner.sh
Mark the `assertQueue` test helper as `static` so it does not trigger
`-Werror,-Wmissing-prototypes`, and take `expected_keys` by const reference.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
List the supported cache eviction policies (`LRU`, `SLRU`, `SIEVE`) in the
descriptions of the `uncompressed_cache_policy`, `mark_cache_policy`,
`index_uncompressed_cache_policy` and `index_mark_cache_policy` server
settings, and in the documentation of the filesystem cache `cache_policy`
setting.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-memory Memory management infrastructure: allocators (Allocator, Arena, PODArray), memory tracking, memor... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Oct 5, 2026
alexey-milovidov and others added 2 commits October 6, 2026 10:47
The columns cache is `CacheBase`-backed and is live by default (it is sized by
`columns_cache_size_to_ram_ratio`), so randomizing its policy, including `SIEVE`,
and its `columns_cache_size_ratio` gives it the same coverage as the other caches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123435&sha=30bded508da21d41e57e933e3f8f3d81338e9b51&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 (05210_lightweight_update_materialized_cte_in_ignore fails with UNKNOWN_TABLE under parallel replicas, also on master and many other PRs since 2026-10-08) and provide a fix in a separate PR. If the fix is already in progress, link it here.

Other failures: 05316_secret_arguments_declared_by_engines is fixed on master by 351f549fe5b (merged into this branch now); 03657_gby_overflow_any_sparse is fixed in #125060.

@groeneai

Copy link
Copy Markdown
Collaborator

Not caused by this PR. The fix is #123121 (mine, open).

This run fails query 26 of the test with UNKNOWN_TABLE on _materialized_cte_c_*, the parallel replicas race from #112642: the initiator's local plan waits for the materialized CTE only in its own branch, so the query sent to the other replicas can start before the CTE table exists. With a slow CTE body that query fails 10 of 10 runs on master and passes 10 of 10 with #123121. Since 2026-10-08 the test failed on 60 PRs and twice on master. #123121 is mergeable and has been waiting for review since 2026-09-30 (requested from @ novikd and @ devcrafter).

huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 10, 2026
With parallel replicas the order in which rows reach `GROUP BY` depends on
the coordinator's assignment of ranges, so `group_by_overflow_mode = 'any'`
with `max_rows_to_group_by = 100` keeps a different set of keys (e.g. 32560..32569
instead of 0..9). The test was blacklisted for parallel replicas before
(ClickHouse#90858) and re-enabled in `ab50bbc1a4d`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/123435/30bded508da21d41e57e933e3f8f3d81338e9b51/pr/result_stateless_tests_arm_binary_parallelreplicas_s3_storage_parallel.json
PR: ClickHouse#123435

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai. 05210_lightweight_update_materialized_cte_in_ignore is tracked by #123121.

The other red job, Stateless tests (arm_asan_ubsan, azure, sequential), hit the 9000 s job timeout at test 1156 of 1180 with no test failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123435&sha=b5e8dde4a8af1cd24ef4ee2966f2f9ea30e6ed9f&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29. Master times out the same way, for example at test 1164 of 1180 on 5be322a6b28, so this is not caused by the PR. The fix in progress is #123849, which splits that job into 2 batches.

I merged the latest master into the branch (clean merge, and the PR's translation units still compile).

@clickhouse-gh

clickhouse-gh Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 555d19d2-0530-4f2e-bbd6-a4bc66fea3d4
  • MIRAI run: 6453e27f-8a56-420c-b3d1-058f4c4e0665
  • PR check IDs:
    • clickbench_942807_1791759200
    • clickbench_942820_1791759200
    • clickbench_942826_1791759200
    • tpch_adapted_1_official_942832_1791759200
    • tpch_adapted_1_official_942843_1791759200
    • tpch_adapted_1_official_942878_1791759200

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The literature suggests that SIEVE is unlikely to be better than SLRU.

However, the implementation is compact and clean, and it will improve our capabilities for further generalization and experimentation.

Good to merge.

@alexey-milovidov alexey-milovidov self-assigned this Oct 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 12, 2026
Merged via the queue into master with commit d47196f Oct 12, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the continue-pr-62756-sieve-cache-policy branch October 12, 2026 21:34
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
alexey-milovidov added a commit that referenced this pull request Oct 13, 2026
…r-part

Conflicts:
- `src/Storages/MergeTree/MergeTreeData.cpp`, `MergeTreeData.h`: master changed the old statistics
  refresh task (`startStatisticsCache` / `stopStatisticsCache` / `refreshStatistics`, #125165) so that
  shutdown does not wait for a running refresh. This PR removes that task entirely in favor of the
  per-part cache, so the removal is kept. Its test `05361_statistics_refresh_does_not_block_drop`
  exercises only the removed task and `refresh_statistics_interval` (now obsolete), so it is deleted.
- `src/Core/ServerSettings.cpp`: kept the `statistics_cache_*` settings and took master's new
  description of `iceberg_metadata_files_cache_policy`; the description of `statistics_cache_policy`
  now lists the possible values like the other cache policies after #123435.
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Oct 13, 2026
…ache policy

Since ClickHouse#123435 the functional test jobs pick the mark/uncompressed cache
policy at random from LRU, SLRU and SIEVE. The test reads 13 blocks once
with use_uncompressed_cache = 1 and expects the second read to hit all 13.

The CI uncompressed cache (128 MiB) is shared by all tests of the job.
When earlier tests leave it full of entries that were already hit, the
first insert that overflows makes the SIEVE hand clear all of those
entries and evict the test's own first block. After that every insert
evicts the oldest new block, so the second read misses blocks before it
reaches them (0 400518 0 in CI). LRU and SLRU keep the most recent
blocks, which the test relied on. This is how SIEVE is defined, not a
bug in it.

The test is no-parallel, so clear the uncompressed cache right before
the first cached read: the 13 blocks then fit with no eviction under
every policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-memory Memory management infrastructure: allocators (Allocator, Arena, PODArray), memory tracking, memor... pr-feature Pull request with new product feature 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.

Implement SIEVE algorithm in cache framework

5 participants