Repository navigation
Do not re-read a partially cached segment's committed prefix from the source (in experimental reader executor) - #115664
Conversation
… source ICacheProvider's Lead contract puts the derivation of a tier's uncommitted tail on the caller: given `available`, fetch [available.end(), range.end()). ReaderExecutor::readThroughCaches bound `lead.available` to a local, used it only for the covers-the-head early return, and then discarded it, because MissTier had no field for it. fetch_lo was therefore computed from the miss range, and on the populating path a partially downloaded segment's miss spans its whole extent starting at seg_left, because that range doubles as the fill geometry handed to DiskCacheWriter. So every partially cached read through the executor re-read the already-cached prefix from the source. DiskCacheWriter::write's append-only offset check then discarded those bytes, which is why the defect produced wasted source I/O rather than incorrect data. The read-only sibling path is unaffected: it emits the miss from the committed frontier. Carry `available` into MissTier and derive each tier's tail once, using it for fetch_lo/fetch_hi and for the write loop. A tier whose committed prefix already spans its range yields an empty tail and is skipped, so it cannot pull fetch_lo back to the segment start. The existing totalSize() and next_resident caps are unchanged, as is the claim/release lifecycle. Measured over an s3_cache_04511 table read with 4 streams (which leaves the segment partially populated), ReaderExecutorBytesFromSource on the warm reread of the same data drops from 1325913 to 276057 bytes; the cold read is unchanged at 1588547. 04511_reader_executor_disk_cache and its reference file are untouched and serve as the SQL-level regression test. Its `warm < cold` assertion was correct and was reporting this defect; the test had been adjusted for flakiness four times. Its worst-case margin across a threads-by-window sweep improves from 16.5% to 49.6%. The new gtest coverage is a unit test rather than SQL because a segment committed to an arbitrary mid-point is not deterministically reachable from SQL, which is precisely why the SQL test was flaky instead of failing. It needs a cache mock shaped like the filesystem cache (append-only segments, a partial segment resolving as a prefix hit plus a whole-extent miss with an open writer); the existing mock is page-cache shaped and cannot express that state. Three cases cover the partial prefix, a read starting inside the tail, and a fully committed neighbouring segment.
…or cache tests The partial-segment cases could not reach the empty-tail branch of the miss loop: MockSegmentCacheProvider emits a Miss only while a segment is incompletely committed, so a fully committed one never becomes a MissTier and the guard that keeps it from pulling the fetch back to the segment start went unexercised. Give MockSegmentState a late-commit frontier that resolve ignores and the writer reports, following MockCacheState::late_committed, and add a case where a segment misses at resolve but is fully available at claim time. Deleting the guard fails that case and nothing else. The case that claimed to cover this is renamed after what it does assert, a resolve-time hit served from cache across segments. Also record what a held source connection does here. It reaches an offset ahead of its parked position by reading the gap through a scratch block, so with the fetch anchored at a committed frontier those bytes cross the wire and land in ReaderExecutorBytesFromSource: 8092 against a 7580 byte tail, versus exactly the tail once no gap is bridgeable and again with connection reuse off. That is a property of connection reuse rather than of the fetch range, and it is unchanged here, but no test combined connection reuse with a cache chain before. No change to src/IO/ReaderExecutor.cpp.
Internal second-model review (2 rounds, 2 findings, both fixed)Before opening this I reviewed the change against an independent model and adjudicated every finding.
Also checked and found sound, so recorded rather than actioned: no underflow in the narrowed source Five suite failures reproduce identically on the base binary, including one that is the subject of a
|
|
Workflow [PR], commit [58e8009] Summary: ❌
AI ReviewSummaryThis PR narrows Final Verdict✅ No new blockers or majors found. |
Pre-PR validation gate (click to expand)
|
|
cc @CheSema @kssenii, could you review this? |
The Config Workflow hook parsed a prose line in the description that began "Changelog category:" as a second template field and exited 1, which dropped all 169 downstream jobs. The line is reworded; the workflow does not re-run on a body edit alone, so this empty commit restarts it. No change to the tree.
clang-tidy runs with -Werror and readability-isolate-declaration, so the four counters declared in one statement failed Build (arm_tidy). Reproduced with clang-tidy-22 -p build: the one-line form reports the violation at gtest_reader_executor.cpp:991 and exits 1, the split form reports none and exits 0. unit_tests_dbms is 44/44.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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. Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 1322705CI fully finished and 0 checks failed, so no failure needed an owner. Measured on the deduped check set (newest attempt per name): 172 unique names, 0 incomplete, Not a void run: Independent CIDB confirmation at this commit: 299,428 ingested rows, 0 This also clears the Config + Finish Workflow blocker that was caused by the PR body itself: a Session id: cron:our-pr-ci-monitor:20260821-023000 |
|
The code in readThroughCaches is not production ready code. I will rewrite it completly soon. So stay tuned and do not fuzz until RE would be in b-test stage. |
|
Understood, standing down. I will not push anything further here, and I will leave Do you want this PR left open as a record of the prefix re-fetch, or closed in favour of your rewrite? |
Master compacted `MissTier` onto one line and renamed the "bypass tier" wording to "writer-less miss" in the comment right where this pull request adds the `available` field. Kept master's wording and the field this fix needs; the translation unit was syntax-checked after the resolution. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The test asserted that the warm reread of a cold-populated table touches the source not at all, and started failing on master right after ClickHouse#118483: -warm_served_from_cache 1 +warm_served_from_cache 0 `min_bytes_for_full_part_storage` is randomized by the test harness, so about two thirds of the runs store the part with the Packed storage: every file of the part lives in ONE object, hence ONE filesystem-cache segment. Inside a single query the marks streams and the data stream each build their own `ReaderExecutor` over that object (`max_threads = 1` does not serialize them - the marks load on their own pool threads) and race for the segment's single downloader role. Only the role winner writes; the losers read through from source and discard. Before ClickHouse#118483 this was invisible: a whole-file read inside `data.packed` was an open-ended range request, so the role winner's fetch ran to the end of the archive and populated the whole segment. ClickHouse#118483 bounds each read to the file's slice, so the winner now fills only that slice and the cold read leaves the segment with holes. 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 `warm` is the whole extent rather than 0. Pin `min_bytes_for_full_part_storage = 0`: with the Full storage every stream is its own object and therefore its own cache key, so each segment has exactly one writer and the cold read populates all of them. That is also what the test means to cover - the executor's read-through contract - rather than whether concurrent streams over one shared segment converge. Verified against a local minio with the failing run's randomized settings, on 26.9.1.1234 (the SHA below): the test as it stands fails 97/200, the patched test passes 350/350. Cross-checked on 26.9.1.1193 (just before ClickHouse#118483), where the unpatched test passes 100/100 and the cold read pulls 4064344 bytes from source for a 1630734-byte archive - the over-read that ClickHouse#118483 removed is what used to fill the segment. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=1d0999bf07898241e1229af5b6c1717aec5d275c&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20sequential%2C%202%2F2%29 Caused by: ClickHouse#118483 Related: ClickHouse#115664 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Dear @CheSema, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
ICacheProvider.h:107-109puts the derivation of a tier's uncommitted tail on the caller: givenLead::available, fetch[available.end(), range.end()).readThroughCachesboundlead.availableto alocal, used it only for the covers-the-head early return, then dropped it -
MissTierhad no field forit.
fetch_locame from the miss range instead, and on the populating path a partial segment's missspans its whole extent from
seg_left(DiskCacheProvider.cpp:651), that range being the writer's fillgeometry. So a partially cached read re-read that prefix;
write's append-only check discarded thosebytes, making it wasted I/O, not wrong data. The read-only sibling emits the miss from
committed_end(
:600-601).This carries
availableintoMissTierand derives the tail once, forfetch_lo/fetch_hiand the writeloop. A tier whose prefix spans its range yields an empty tail and is skipped, so it cannot pull
fetch_loback to the segment start.
The new coverage is a unit test because a segment committed to an arbitrary mid-point is not
deterministically reachable from SQL - which is why 04511 was flaky rather than failing. Its five cases
each fail on master; the suite is 44/44 here.
Measured on
s3_cache_04511,ReaderExecutorBytesFromSourceon the warm reread:1,325,913 -> 276,057 bytes, cold unchanged at 1,588,547. With
reader_executor_use_long_connectionsa held connection can still bridge over the prefix; untouched here.Surfaced by two
04511_reader_executor_disk_cachefailures on 2026-08-20, one on master, both diffing only
warm_served_from_cache 1 -> 0. That test andits
.referenceare unchanged: itswarm < coldassertion was correct and was reporting this bug,having been adjusted for flakiness four times. It passes 50/50 under randomized settings and under those
runs' settings. #115643 pins it to one thread so its oracle can be strict; measured here, the two
compose -
warm = 0needs the pin, and this cuts the multi-thread warm read it leaves.Validation detail: warm-read source bytes per configuration, and the release-branch check
Same fixture and probe each time;
warm/coldratio ofReaderExecutorBytesFromSource. The test'sassertion is
warm < cold, so a ratio near 1.0 is a near-failure.Build IDs: master
c877fb06499b8acdfd053c38051b7fd4c7e79737, this PR2ffe0b96223a5b47c2099d92b26cbbb4768786fd; server identity asserted withSELECT lower(buildId())before each arm.
readThroughCaches,DiskCacheProvider.cppandICacheProvider.hare absent fromevery active release branch (26.7 / 26.6 / 26.5 / 26.3 / 25.8), so the read-through cache path has never
shipped.
use_reader_executorwas added in996c1850(2026-06-09), defaults tofalse, tierEXPERIMENTAL. No backport.Workflow [PR]
Sync PR [sync-upstream/pr/115664]