Skip to content

Fix flaky 04511_reader_executor_disk_cache - #115643

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-04511-reader-executor-disk-cache-flaky
Aug 21, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-04511-reader-executor-disk-cache-flaky

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

04511_reader_executor_disk_cache fails on master with

 cold_read_from_source	1
 executor_populated_cache	1
-warm_served_from_cache	1
+warm_served_from_cache	0

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2101f9b0850389d7fddfefd04d2577162c8958c3&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%202%2F2%29

It also fails on unrelated pull requests in Stateless tests (amd_msan, WasmEdge, sequential, 2/2) (4 of 14 reruns there). No tracking issue exists.

What goes wrong

The third check asserted warm < cold, comparing the ReaderExecutorBytesFromSource totals of a cold and a warm SELECT. That is a proxy, and a partially populated cache inverts it.

With more than one reading thread each stream builds its own ReaderExecutor over the same file. DiskCacheWriter appends only at the segment's live write offset, so whichever stream loses the downloader race contributes nothing, and the cold read leaves the segment partially populated. The warm read then re-fetches such a segment from its start — claimLeadRole's available prefix is deliberately unused, see the "Coarse by design" note in ReaderExecutor::readThroughCaches — so it can move more source bytes than the cold read did.

The failing job's server log and query_log show exactly that: the cold read populated 285856 of the 801126-byte segment and read 1658884 bytes from source; the warm read then read 2480460. Across the 28 runs of that job the cold total was a constant 1658884 while the warm total was 0, 801126, 1372817, 1479995 or 2480460, purely as a function of how the streams interleaved.

The fix

Pin the reads to a single thread, so the cold read populates the segment completely, and assert the strong property instead of the proxy: the warm read must touch the source not at all (warm = 0).

Verified over 54 runs of the test with randomized settings against a local minio: cold is now a stable 800461 (one clean pass over the file instead of two or three overlapping ones) and warm is 0 in every run.

The re-fetch-from-segment-start behaviour itself is left alone — it is a documented limitation of the experimental ReaderExecutor with a follow-up already noted in the code, not something to change in a CI fix.

Changelog category (leave one):

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

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

The test asserted that the warm reread pulls strictly fewer source bytes
than the cold read. That is a proxy, and a partially populated cache
inverts it, so the test failed on master:

    -warm_served_from_cache	1
    +warm_served_from_cache	0

With more than one reading thread, every stream builds its own
`ReaderExecutor` over the same file. `DiskCacheWriter` appends only at
the segment's live write offset, so whichever stream loses the
downloader race contributes nothing and the cold read leaves the segment
partially populated. The warm read then re-fetches such a segment from
its start - `claimLeadRole`'s `available` prefix is deliberately unused,
see the "Coarse by design" note in `ReaderExecutor::readThroughCaches` -
and can move MORE source bytes than the cold read did.

The failing run shows exactly this: the cold read populated 285856 of
the 801126-byte segment and read 1658884 bytes from source, and the warm
read then read 2480460. Across the 28 runs of that job the warm total
was 0, 801126, 1372817, 1479995 or 2480460 depending only on how the
streams interleaved.

Pin the reads to one thread, so the cold read populates the whole
segment, and assert the strong property instead of the proxy: the warm
read must touch the source not at all. Verified with 54 runs of the
test under randomized settings against a local minio; `cold` is now a
stable 800461 (one clean pass over the file rather than two or three
overlapping ones) and `warm` is 0 in every run.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2101f9b0850389d7fddfefd04d2577162c8958c3&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%202%2F2%29

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ec1274a]

Summary: ✅


AI Review

Summary

This PR fixes the flakiness in 04511_reader_executor_disk_cache by constraining the probe to a single read stream and by asserting the direct contract that a warm reread should consume zero source bytes once the cold read has fully populated the cache. The change matches the current ReaderExecutor / DiskCacheWriter behavior, does not hide a correctness regression in the touched code path, and I did not find any unresolved review issues.

Final Verdict

Status: ✅ Approve

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

clickhouse-gh Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ec1274afe with master 12e8fa319 (stripped binary size, per-symbol sizes and ThinLTO time; 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 704.42 MiB 701.37 MiB -3.04 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

49 object files changed (+4.20 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/NATS/StorageNATS.cpp.o 568.35 KiB 597.33 KiB +28.98 KiB (+5.10%)

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

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

Job report

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit 18902ca Aug 21, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-04511-reader-executor-disk-cache-flaky branch August 21, 2026 03:10
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 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.

2 participants