Skip to content

Isolate 00180_no_seek_avoiding_when_reading_from_cache from other cache users - #114245

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:isolate-00180-private-filesystem-cache
Aug 12, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:isolate-00180-private-filesystem-cache

Conversation

@groeneai

@groeneai groeneai commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #114213

Changelog category (leave one):

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

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

...

Description

The test asserts that a query reads entirely from the filesystem cache, but its table inherits
storage_policy = 's3_cache' from test.hits_s3, so it shares one 200 MiB cache with everything
else on the server. Background merges of test.hits_s3 write through that cache and can fill it
with file segments held open by a FileSegmentsHolder. Reservation then finds nothing releasable to
evict, both warm-up queries silently continue without caching, and the measured query reads from S3,
so CachedReadBufferReadFromSourceBytes is non-zero. SYSTEM CLEAR FILESYSTEM CACHE cannot help:
it removes only releasable segments.

Observed on
this run,
where the value was 10667287. Raising
filesystem_cache_reserve_space_wait_lock_timeout_milliseconds and adding no-parallel were both
tried before and neither addresses this: the failure is cannot evict enough space, not lock
contention, and the competing cache user is the server's own background merge rather than another
test.

The fix gives the table a private inline cache disk, keyed on $CLICKHOUSE_DATABASE so it stays
unique per run, and scopes the cache clear to that cache. The assertion, the reference file and the
tags are unchanged. This mirrors 04695_filesystem_cache_wait_for_concurrent_download_timeout.sh,
which was isolated the same way in eca7e2270696c02 for the same mechanism. The explicit
ENGINE = MergeTree is required: without it the inherited storage_policy is merged next to the new
disk setting and the statement fails with storage_policy and disk cannot be specified at the same time. Column and key clauses are still copied from the source table.

Shared-cache eviction behaviour stays covered by the other tests on the s3_cache policy.

Validation: I reproduced the failure mode locally with a concurrent workload that keeps the shared
cache full of held segments, and synthesized test.hits_s3 so the real test could run.

Validation detail

Under the concurrent workload, a global SYSTEM CLEAR FILESYSTEM CACHE left 229.68 MiB across 46
segments resident, and the server log showed the failing job's signature
releasable size: 0, releasable count: 0, non-releasable size: 207535569.

Runs of the real test file via clickhouse-test, same binary and same workload:

Arm Runs Result
Before this change 20 2 pass, 18 fail
After this change 50 50 pass
After this change, no concurrent workload 20 20 pass

All 18 failures are the assertion itself, with values such as 0 12123319, matching the magnitude
seen in CI.

The assertion still catches what it exists for. With the same query and settings against a cold
cache, AsynchronousReaderIgnoredBytes is 4607579 and
CachedReadBufferReadFromSourceBytes is 7944923; against the warm private cache both are 0.

Version info

  • Merged into: 26.8.1.1214 (included in 26.8 and later)

…he users

The test asserts that its measured query reads entirely from the filesystem
cache, but the table is created with `CREATE TABLE hits_s3_sampled AS
test.hits_s3`, so it inherits `storage_policy = 's3_cache'`: the single 200 MiB
cache shared by everything on the server. Background merges of `test.hits_s3`
write through that cache and can fill it with file segments held open by a
`FileSegmentsHolder`, which are not releasable. The warm-up queries' space
reservation then finds nothing to evict, silently continues without caching, and
the measured query reads from S3, so `CachedReadBufferReadFromSourceBytes` is
non-zero. `SYSTEM CLEAR FILESYSTEM CACHE` does not help, since it is
`removeAllReleasable` and skips held segments.

Give the table a private inline cache disk instead, keyed on
`$CLICKHOUSE_DATABASE` so the disk name is unique per run and the test stays
parallel-safe, and scope the cache clear to that cache. The assertion, the
reference file and the tags are unchanged.

`04695_filesystem_cache_wait_for_concurrent_download_timeout.sh` was isolated
the same way in eca7e22 for this same mechanism.

The explicit `ENGINE = MergeTree` is required. Without it, `setEngine` calls
`inheritStorageFromSource`, whose `mergeStorageSettings` appends the source's
`storage_policy` next to the new `disk` setting, and `loadFromQuery` then throws
`storage_policy and disk cannot be specified at the same time`. With the engine
given explicitly that path is skipped, while columns and the PARTITION BY /
ORDER BY / SAMPLE BY clauses are still copied from the source table.

Validated by reproducing the failure mode locally with a concurrent workload
that keeps the shared cache full of held segments, confirmed by a global cache
clear leaving 229.68 MiB across 46 segments resident. Runs of the real test file
under that workload: 2 of 20 passed before this change, 50 of 50 after. With the
same query and settings against a cold cache the asserted counters are 4607579
and 7944923, and against the warm private cache both are 0, so the assertion
still catches the regression it exists for.

Closes: ClickHouse#114213
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: 0 blocking findings

An independent cold re-review of the full change returned 0 findings, covering the test and
reference, the stateful setup, the storage configuration, the cache/create/clear implementations and
the sibling tests.

My own cold review raised five notes, all verified against the source and none blocking:

💡 The explicit ENGINE = MergeTree newly activates the client-side CREATE rewrite for this test
(clickhouse-test injects default_compression_codec = LZ4 for no-random-settings tests, and the
rewrite requires an explicit MergeTree engine). Harmless: it formats with secrets shown, so the
inline disk(...) arguments are not masked, and AS is emitted before the storage clause so the
AS form survives. It ran in all 50 passing runs. 02789_filesystem_cache_alignment.sh is the same
shape.

💡 The private cache runs on default reserve_granularity / cache_policy rather than the shared
cache's tuning. Validation passes, and the install-time randomization of reserve_granularity is
scoped to the <s3_cache> XML block, so it never applied to an inline disk.

💡 The disk and cache are registered server-globally and outlive the table. No in-tree test queries
system.disks or system.filesystem_cache without an exact name predicate, and the name is keyed on
$CLICKHOUSE_DATABASE, so nothing else can observe it.

💡 Test liveness: the reference is byte-identical and both counters stay reachable exactly when the
invariant breaks (AsynchronousReaderIgnoredBytes via the lazy-ignore branch, gated on the read type
not being CACHED). Cold cache 4607579 / 7944923, warm private cache 0 / 0.

💡 The placeholder changelog entry is correct for the CI Fix or Improvement category.

Disclosed and not chased: an inline custom disk outlives its table and leaves a small cache
directory. Pre-existing behaviour of the mechanism, shared by a dozen in-tree tests including the
recently merged 04695; median residue ~0 bytes over 105 local runs.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate
# Check Result
a Deterministic repro Yes. With a concurrent workload keeping the shared s3_cache full of held segments, the unfixed test fails 18 of 20 runs. Without it, it passes, which is why CI sees it as flaky.
b Root cause explained Yes. The table inherits storage_policy='s3_cache', another user holds every segment non-releasable, reservation cannot evict, the warm-ups silently bypass the cache. Reproduced locally: a global cache clear left 229.68 MiB / 46 segments resident and the log showed releasable size: 0, releasable count: 0, non-releasable size: 207535569.
c Fix matches root cause Yes. The cause is a contended shared resource; the change removes the sharing. No widened bound, no skip tag, no reduced dataset, no defensive guard. The assertion is untouched.
d Test intent preserved Yes. Assertion, reference file and tags unchanged. Test-only fix, so no new regression test is owed.
e Both directions demonstrated Yes, on the real test file, same binary, same workload: 18/20 fail before, 50/50 pass after, 20/20 pass after with no workload.
f General across code paths Yes. The change is in the test, not a build-conditional path, so all four affected checks (amd_debug, arm_binary, amd_tsan sequential, amd_tsan parallel) are covered. Other tests on the s3_cache policy stay there deliberately: shared-cache eviction is their subject.
g General across inputs N/A for a test-only change. Exercised: cold vs warm cache, merged vs unmerged mark ranges, scoped clear before and after INSERT, saturated vs unsaturated server.
h Backward compatible Yes. No setting, no default change, no serialization format, no SettingsChangesHistory.cpp entry, no experimental gate.
i Invariants preserved Yes. Invariant: the table read by the measured query is served by a cache no other actor can exhaust. The table is fixed, both warm-ups and the measured query use that same private cache, the clear is scoped to it so it no longer perturbs other cache users, and test.hits_s3 merges are untouched by design.

The assertion is not weakened. Same query and settings against a cold cache give
AsynchronousReaderIgnoredBytes = 4607579 and CachedReadBufferReadFromSourceBytes = 7944923;
against the warm private cache both are 0. Two probes that produced no difference were discarded
rather than counted: enable_filesystem_cache=0 never constructs the cached buffer, and merged mark
ranges leave no forward gap for seek-avoiding.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antonio2368, could you review this? The test's table inherits storage_policy = 's3_cache' from test.hits_s3, so when another user of that shared cache holds every segment non-releasable, the warm-up queries' space reservation finds nothing to evict and silently reads past the cache; this gives the table its own inline cache disk and leaves the assertion untouched.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [20dea4f]

Summary: ❌

job_name test_name status info comment
Stress test (arm_release) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR changes 00180_no_seek_avoiding_when_reading_from_cache.sh to read through a private inline filesystem cache instead of the shared s3_cache, so unrelated cache users no longer invalidate the test's assumption that the sampled table is fully cacheable. I reviewed the current one-file diff, the PR description, the existing PR discussion, and the current all-green CI report, and I did not find a remaining correctness, isolation, or evidence gap that warrants an inline review finding.

Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 20dea4f5e with master ee618c56a (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 3cf74b5e9; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 691.08 MiB 688.09 MiB -2.99 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

6 object files changed (+241.92 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Core/ServerSettings.cpp.o 847.30 KiB 1.04 MiB +217.35 KiB (+25.65%)
programs/server/CMakeFiles/clickhouse-server-lib.dir/Server.cpp.o 1.47 MiB 1.49 MiB +24.55 KiB (+1.63%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

6 translation units recompiled, 5 s compile time in total, 6 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 20dea4f

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_release) / Hung check failed, possible deadlock found one already-cancelled DROP TABLE prometheus (is_cancelled: 1, elapsed 722 s) never returns from DatabaseCatalog::waitTableFinallyDropped; the DROP DATABASE ... SYNC teardown then convoys behind it on the DDL guard #113397 (external, open), issue #113954

Owner resolved from hung_check.log, not by test name: the processlist head carries the
DROP TABLE prometheus + waitTableFinallyDropped + getDDLGuard frames that #113397 addresses.

175 jobs, 0 incomplete, 0 dropped, 39 green, 135 genuinely skipped (each with a config reason -
this PR only touches one stateless test file, so the build-dependent matrix is not required).
Config Workflow and Finish Workflow both succeeded, last completion 2026-08-11T05:40:32Z.

Not caused by this PR: the diff only isolates 00180_no_seek_avoiding_when_reading_from_cache, and
that test appears nowhere in the hung processlist.

Session id: cron:our-pr-ci-monitor:20260811-060000

@PedroTadim PedroTadim self-assigned this Aug 11, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 24a4d5c Aug 12, 2026
179 of 181 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.

Flaky test 00180_no_seek_avoiding_when_reading_from_cache: filesystem cache full of non-releasable segments, warm-up silently bypasses cache

4 participants