Skip to content

Implemented SIEVE eviction in cache framework - #62756

Closed
Vectorshine wants to merge 61 commits into
ClickHouse:masterfrom
Vectorshine:master
Closed

Vectorshine wants to merge 61 commits into
ClickHouse:masterfrom
Vectorshine:master

Conversation

@Vectorshine

@Vectorshine Vectorshine commented Apr 18, 2024 •

Copy link
Copy Markdown
Contributor

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.

Closes: #58910

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)

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

@CLAassistant

CLAassistant commented Apr 18, 2024 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-ci

clickhouse-ci Bot commented Apr 18, 2024

Copy link
Copy Markdown

This is an automatic comment. The PR descriptions does not match the template.

Please, edit it accordingly.

The error is: More than one changelog category specified: 'Improvement', 'Performance Improvement'

1 similar comment
@clickhouse-ci

clickhouse-ci Bot commented Apr 18, 2024

Copy link
Copy Markdown

This is an automatic comment. The PR descriptions does not match the template.

Please, edit it accordingly.

The error is: More than one changelog category specified: 'Improvement', 'Performance Improvement'

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 18, 2024
@robot-ch-test-poll robot-ch-test-poll added the pr-improvement Pull request with some product improvements label Apr 18, 2024
@robot-ch-test-poll

robot-ch-test-poll commented Apr 18, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 21fce56 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success

@kssenii kssenii self-assigned this Apr 18, 2024
Comment thread src/Common/SIEVECachePolicy.h Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

Let's add the cache policy to randomization in our functional tests.

@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.

You can add randomization of cache policies in CI similar to

# Randomize cache policies.
cache_policy=""
if [ $((RANDOM % 2)) -eq 1 ]; then
cache_policy="SLRU"
else
cache_policy="LRU"
fi
echo "Using cache policy: $cache_policy"
if [ "$cache_policy" = "SLRU" ]; then
sudo cat /etc/clickhouse-server/config.d/storage_conf.xml \
| sed "s|<cache_policy>LRU</cache_policy>|<cache_policy>SLRU</cache_policy>|" \
> /etc/clickhouse-server/config.d/storage_conf.xml.tmp
mv /etc/clickhouse-server/config.d/storage_conf.xml.tmp /etc/clickhouse-server/config.d/storage_conf.xml
fi
but instead of cache_policy setting in storage_conf.xml you should change the mark_cache_policy in another server config. We do not yet have it explicitly enabled in CI, so you'll also need to add a file with this setting to ClickHouse/tests/configs/config.d/. Also do not forget to add an according file installation into ClickHouse/tests/config/install.sh

Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/tests/gtest_sieve_cache.cpp Resolved
Comment thread src/Common/tests/gtest_sieve_cache.cpp Resolved
Comment thread src/Common/CacheBase.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
Comment thread src/Common/SIEVECachePolicy.h Resolved
@rschu1ze rschu1ze changed the title Implemented SIEVE algorithm in cache framework (Issue #58910) Implemented SIEVE eviction in cache framework Apr 26, 2024
@Vectorshine

Copy link
Copy Markdown
Contributor Author

reopen

@Vectorshine Vectorshine reopened this Jun 18, 2024
@robot-clickhouse robot-clickhouse added the submodule changed At least one submodule changed in this PR. label Jun 18, 2024
@clickhouse-ci clickhouse-ci Bot added the manual approve Manual approve required to run CI label Jun 18, 2024
@Vectorshine Vectorshine reopened this Jun 18, 2024
@Vectorshine Vectorshine reopened this Jun 18, 2024
@alexey-milovidov

Copy link
Copy Markdown
Member

@Vectorshine, what happened?

@Vectorshine Vectorshine reopened this Jun 18, 2024
@rschu1ze

Copy link
Copy Markdown
Member

@Vectorshine Thanks for checking. There is no need to close and re-open this PR over and over 😄 I just started CI to see how the tests respond.

@robot-ch-test-poll3 robot-ch-test-poll3 removed the submodule changed At least one submodule changed in this PR. label Jun 18, 2024
Comment thread src/Common/SIEVECachePolicy.h Resolved
Address review feedback: the correctness fix in `SIEVECachePolicy::remove`
(advancing `hand` when it points at the erased queue node) was not covered by
any test, so it could regress silently.

`SIEVECache.RemoveEntryUnderHand` removes the entry the hand points at and
asserts both the remaining queue order and the hand's new position, checks that
removing an unrelated entry leaves the hand alone, covers the predicate overload
of `remove`, and verifies that eviction still starts from the new hand
position. `SIEVECache.RemoveLastEntryUnderHand` covers the wrap-around case
where the removed entry is the last one in the queue, and that the cache stays
usable after the queue is emptied through `remove`.
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 0.00% 86.40% +86.40%
Functions 0.00% 91.90% +91.90%
Branches 0.00% 78.50% +78.50%

Full report

Comment thread src/Core/ServerSettings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 22367654ab9c47ea4dcfc92ba61d9e4007a92680 with master failed: RuntimeError: CI logs cluster query failed: SELECT file, library, argMax(dur, time) AS ….

See the job log for details.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Regenerated the affected server-settings reference entries from the updated ServerSettings.cpp metadata: all CacheBase-backed cache-policy settings now list SIEVE alongside LRU and SLRU.

@locadex-agent

locadex-agent Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🛑 Locadex Cancelled

New changes were pushed while a Locadex run was in progress, so that run was cancelled. Comment /locadex to re-run on your latest changes.

Reconstructed the merge because the fork branch has two merge bases with
master (criss-cross), which makes a plain `git merge` manufacture spurious
conflicts in unrelated files. The net diff against master is unchanged: the
SIEVE cache policy files, the `*_cache_policy` server-setting descriptions and
their generated docs pages, and the cache-policy randomization in the test
jobs.
The mark and uncompressed cache randomization added by this pull request
replaced the existing `storage_conf` `<cache_policy>` randomization instead of
sitting next to it, so the stress test stopped exercising the `SLRU`
filesystem cache. The filesystem cache is backed by `FileCachePolicy`, which
has no `SIEVE` value, so it gets its own `LRU`/`SLRU` variable, as
`functional_tests.py` already does.
@alexey-milovidov alexey-milovidov added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Aug 28, 2026
Merged with explicit recent merge base 66e8bc0 to avoid spurious
conflicts from the criss-cross merge history (two merge bases).
@abashkeev abashkeev added the comp-memory Memory management infrastructure: allocators (Allocator, Arena, PODArray), memory tracking, memor... label Sep 3, 2026
Comment thread src/Core/ServerSettings.cpp Resolved
alexey-milovidov and others added 2 commits September 16, 2026 09:56
…_policy` settings in Dolor

`tests/casa_del_dolor/properties.py` only chose between `LRU` and `SLRU` for
the 17 `*_cache_policy` server settings, so the random-server-settings run
never exercised `SIEVE` on those entrypoints. All 17 are `CacheBase`-backed,
so `SIEVE` is valid for each of them. The filesystem cache generator is left
alone because it is backed by `FileCachePolicy`, which has no `SIEVE`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Superseded by #123435, which keeps all the original commits and adds a merge of the current master. The merge could not be pushed here: the PR head is the fork's master branch, and the update touches .github/workflows, which GitHub rejects without the workflow token scope. Thank you @Vectorshine for the original implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-memory Memory management infrastructure: allocators (Allocator, Arena, PODArray), memory tracking, memor... manual approve Manual approve required to run CI pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SIEVE algorithm in cache framework