Repository navigation
Add a maintained ReadPlan to the experimental ReaderExecutor - #115816
Conversation
Add ReadPlan: resolve the cache residency of a look-ahead span once, hold the pinned hit-readers and miss-writers, and answer per-offset which tier serves an offset - coalescing consecutive misses (across cells and tiers) into one fetch run - via runAt/writersFor, growing the span on the right and retiring the consumed prefix on the left as the cursor advances. Adds IntervalSet::ranges for the committed-range query. Unit-tested in gtest_read_plan; not yet wired into the executor.
Replace the per-window cache resolve in readThroughCaches with the maintained ReadPlan: ensureResolved resolves the look-ahead span once (Options plan_look_ahead, default 16 MiB) into the held plan; readThroughCaches serves one block per window from the tier runAt reports (hit reader, committed writer, or a coalesced miss); fetchAndServe reads a miss run in one capped source request and populates every populating tier. The plan grows right and retires the consumed prefix as the cursor advances. Serve semantics are unchanged - the existing executor tests pass; only the resolve is now held across windows instead of repeated per window.
Expose the ReaderExecutor look-ahead as an experimental setting (default 16 MiB), validated to be at least 4 KiB like the other reader_executor_* sizes, mapped through ReadSettings into the executor Options. Add the settings-history entry.
|
Workflow [PR], commit [629784f] Summary: ❌
AI ReviewSummaryThis PR adds a maintained Findings
Final Verdict❌ Changes requested. LLVM Coverage ReportMeasured on commit 629784f.
Changed lines: Changed C/C++ lines covered: 261/275 (94.91%) · Uncovered code |
Grow the plan only once less than half the look-ahead remains ahead of the cursor, then resolve up to the full length - replacing the per-window top-up with fewer, larger resolves.
When the head block is uncommitted and a concurrent downloader owns it on every populating tier, fetchAndServe now waits for that download (CacheWriter::waitAndRead) and serves the block from cache instead of re-reading the same bytes from source; on a wait timeout it falls back to a source read of just the head block. The decision is head-based, so a role held on a later block of a coalesced miss run does not force a re-read of a concurrently-downloaded head. Adds gtests for both the wait-served and the timeout-fallback paths.
Drop the head_is_ours tracking: with one coordinating cache tier in practice, wait whenever a concurrent downloader leads the head block. Still a single iteration - wait once, then serve from cache or fall back to one source read of the head block; no waiting/reclaiming loop.
When the wait for a concurrent downloader times out, try once to claim the head's role (the downloader may have released it) so the coalesced fetch below populates the cache; if it committed meanwhile, serve that. If it is still led elsewhere, the source read serves the bytes without a write. One attempt, no waiting/reclaim loop.
Handle each tier in one pass over the writers: serve a committed head prefix from cache, wait once on a head segment a concurrent downloader leads and serve it if it lands, otherwise take the download role for the fetch. Fetch from source only after the pass. Replaces the separate post-loop wait/re-claim block.
The tiers() helper took std::vector<PlanTier> and was called with a braced list, copying the move-only PlanTier - a clang-diagnostic-error under the tidy build (RelWithDebInfo tolerated it). Make it variadic/forwarding and drop the braces at the call sites.
How
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes263 object files changed (+58.24 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units4039 translation units recompiled, 18495 s compile time in total, 4037 of them have a recent master baseline. Symbol sizes
|
The experimental `ReaderExecutor`'s plan-driven read filled a cell only over `[pos, window)`, so a whole-segment tier (page cache) got a partial write and stored nothing, and an incremental filesystem-cache segment opened mid-segment was written off its frontier and dropped. Both left the cache unpopulated, so the warm read went back to source - failing `04511_reader_executor_disk_cache` and `test_reader_executor_page_cache`. `ReadPlan::runAt` now returns the full source-read extent of a FETCH run: coalesced right to the nearest resident offset (capped at the window), extended left to each covering segment's committed frontier (below `pos` when a read opens mid-segment), and out to a whole-segment head cell's true end. `fetchFillServe` (renamed from `fetchAndServe`) reads that extent once, fills the tiers it spans, and serves one block. Also simplifies the cache-writer interface: `committed` returns the `size_t` frontier instead of an `IntervalSet`, `claimLeadRole` returns just a `Claim` (availability is read via `committed`), and `CacheWriter::fillsWholeSegment` lets a writer report its own segment discipline. All head resolution (serve-committed, or wait-for-downloader) runs in the single pass over writers.
…ases A coalesced fetch that bridges a segment no tier can cache (a read-only or a detached tier) used to discard those bytes and re-read them when the cursor arrived. Retain the un-served, un-cached part of each fetch in memory and serve it on the next windows; it is freed as the cursor passes, and a cold read (every cell writer-backed) holds nothing. Bounded by the window. Adds `ReaderExecutor` gtests for the writer-less read paths - no cache, a read-only (bypass) tier, and a detached segment - and documents that a writer-less miss keeps its snapshot residency within the held span: it is not re-probed, because such misses are rare (a full or detached cache) and re-probing would add pressure to a cache that already had no room. Also makes the multi-layer (page + filesystem) whole-cell fetch's correctness-over-fewest-bytes trade-off explicit in the comments.
`fetchFillServe` ignored what the cache accepted: it assumed a claimed writer cached its whole range and, worse, built the retained set AFTER resetting the claims (the `if (c.claim)` guard was always false), so it held the entire un-served extent and never accounted for a rejected write. Record what each tier actually committed (`committed()` after the write, which reflects no-disk-space or a reservation failure) and retain only the un-served bytes no tier accepted, via `cached.subtract(unserved)`. Adds a `ReaderExecutor` gtest for a rejected write (mock `reject` state): the block is served from the retained fetch, not re-read from source, and stays uncached.
Bytes a fetch pulled that no tier accepted (a read-only or detached tier, or a rejected write) were kept in a private `held_fetch` buffer, with a manual serve fast-path and trim in `readThroughCaches`/`seek`. Move that hold into `ReadPlan`: `runAt` serves it first as a `from_memory` run, `hold`/`readMemory` store and serve it, and `retireBefore` frees the passed part - one lifecycle with the cache pins. The executor just asks the plan; `fetchFillServe` hands the rejected set to `hold`. This removes the executor-side range math and is the memory support the prefetch slice needs (it will drop its uncacheable remainder into the same hold). Adds a `ReadPlan` gtest for the memory hold; existing gtests and 04511/04930/page-cache stay green.
`readThroughCaches` now retires up to the end of the block it just served, so the block's cache pins and memory hold are freed at the end of its window instead of one window later (at the next `ensureResolved`). The served bytes are independently owned by the returned buffer, so dropping the plan's refs is safe; `ensureResolved` still retires a region a forward jump skipped.
A coalesced FETCH can enter a later whole-segment (page) cell and stop inside it at the window boundary. `runAt` only widened `fetch_end` for the cell covering the head, so that later cell got a partial write, which a whole-segment tier rejects - it never landed in cache and was re-read when the cursor reached it (an extra source request). Widen `fetch_end` to the end of ANY whole-segment miss cell the fetch straddles (fixpoint; converges on cell boundaries, one step for a single page tier). Adds a `ReaderExecutor` gtest (a window stopping mid the second page block now costs one source read with both blocks cached) and gives the mock writer `fillsWholeSegment()` so it faithfully models a whole-block cache.
Condense the doc and inline comments accumulated over the ReadPlan review series into short "why" notes: drop restatement and method docs duplicated between header and definition, keep the non-obvious invariants. No behavior change.
`claimLeadRole` is called per-writer and every caller passed the writer's own segment range; `PageCacheWriter` ignored it and `DiskCacheWriter` used it only to clamp to its own segment (a no-op). Availability is read via `committed()`. Drop the parameter - `claimLeadRole()` acquires the role for the writer's one segment.
Add two ReaderExecutor gtests: - a file-level page block straddling two StoredObjects is fetched whole across the boundary, cached, and the object is read from source once (no re-fetch); - a faster-tier hit over a slower-tier miss reads the whole file from source to fill the slower tier - correct, documenting the stacked-layer C-case is not the fewest source bytes (a gather path would read only the gap).
…populate" `populatesOnMiss()` duplicated the per-cell signal the plan already uses: a bypass (read-only) tier emits writer-less misses, which `writersFor` and `runAt` skip via their `cell.writer` checks - exactly like a detached or rejected cell. Remove the virtual and `PlanTier.populates`; each provider's `resolve` reads its own bypass setting directly to pick `get` vs `getOrSet`. "Do not populate" is now one signal (a writer-less miss), covering bypass, detached, and rejected identically.
…s block The `reader_executor_plan_look_ahead` entry was recorded in the `26.8` block. CI evaluates the pull request merged with master, where the current version is `26.9`, so the style check requires new settings in the current-version block. Move the entry into a `26.9` block. `reader_executor_window_size` and `reader_executor_block_size` stay in `26.8`; they are already recorded there on master.
…cutor Add an incremental mode to the mock cache provider so a tier can model append-only filesystem-cache fills, and add three tests for how the read executor reuses a long connection over the cache path: - page cache (whole-segment) reuses one connection across windows; - filesystem cache (incremental) reuses one connection across windows; - a stacked faster-hit over slower-miss tier stays correct, even though its partial-residency fill collapses into a single source read and opens no long connection.
|
Also question from Kssenii: when the memory cache allocates: at resolve or at insertion? PS: On a read we pin the data in caches for look ahead window and hold it until window passes over the segments. |
The read plan holds every cache cell it resolved until the cursor passes it, so the look-ahead span is also the bound on what a single reader pins: page-cache cells cost memory, and a held filesystem-cache segment is not releasable, so it blocks eviction. `Context::getReadSettings` validated only the lower bounds, so any value was accepted. This answers the review question about limiting the held segments. The bound belongs on the span in bytes, which covers every cache tier at once, rather than on a per-resolve segment count, which reaches only the filesystem cache and never binds at the default geometry. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The plan holds every cache cell it resolved until the cursor passes it,
so the look-ahead span is what one reader pins. The window and the block
already track the memory-pressure level; the look-ahead did not, so the
largest holder was the one that never shed.
`sampleWindowSizes` now derives `plan_bytes` through
`PLAN_LOOK_AHEAD_REDUCTION` ({1, 2, 8, 32} - gentler than the window,
because re-resolving a cell costs a cache probe per tier), floored at the
live block so `plan_look_ahead >= block_size` holds at every level. At the
16 MiB default that is 16 / 8 / 2 / 0.5 MiB.
`ReadPlan::dropAfter` gives back the span the smaller look-ahead no longer
covers. Without it the shrink would only stop growth, and since the window
shrinks too, a span resolved under `Normal` would stay pinned for as long
as the pressure lasted.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ReadPlan::extend` deduped whole cells: any cell starting before the held end was skipped. But `resolve` reports a segment from its own start, so a re-returned cell can reach past that end. Dropping it whole left the bytes past the old `resolvedEnd` with no covering cell while `span_end` advanced over them, so `runAt` fetched from source what the refill had just seen in cache. Two shapes hit this. A writer-less tier (`read_if_exists_otherwise_bypass`) reports a hit as the segment's committed prefix, which grows when a concurrent downloader commits more. And a partial segment resolves as two cells from one start - the prefix hit, then the whole extent carrying the writer - so the hit set the held end and the writer cell behind it was dropped, leaving that segment's tail fetched from source and never written back to the cache. Dedup the bytes instead of the cell: skip one already wholly held, clip one that straddles to its uncovered suffix. Cells stay disjoint and ordered, and a clipped cell's reader or writer keeps its full segment range, which `CacheReader::range` already allows. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review feedback on the plan's public names. - `coversForward` -> `contains`, and it is now actually called. `ensureResolved`'s discontinuity test spelled the same predicate out by hand, so the accessor had no caller at all. - `spanStart` / `resolvedEnd` -> `begin` / `end`. - The covered region is a range, not a span: `span_start` / `span_end` -> `range_start` / `range_end`, with the prose following. - `retireBefore` -> `dropBefore`, so it pairs with `dropAfter`. The call site drops its `empty()` test, which `contains` subsumes: an empty plan has `range_end <= range_start`, so no offset is contained. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…docs
Review feedback.
- `ChainedBuffers::contains(offset)` replaces `covers(ByteRange{offset, 1})`
at the memory-hold check. The `!empty()` guard goes with it: `covers` is
already false on an empty chain.
- `runAt` computes `fetch_end` and `fetch_start` in one pass over the tiers.
The serve walk above them stays separate - it returns on the first tier
that can serve, so folding the geometry in would compute it on every hit
and then discard it.
- `runAt`'s doc drops from six lines to two.
- `max_fetch_ahead` -> `fetch_limit`. It is a byte count bounding one
`Fetch`, unrelated to the plan's look-ahead, and `max_` read like a
tunable constant.
- Its default argument is gone. Only tests relied on it; the one production
caller always passed a value, and the default was
`numeric_limits<size_t>::max()`, whose failure mode - an unbounded fetch
from a caller who forgot the argument - is silent rather than a compile
error. Tests pass `NO_LIMIT`.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`dropBefore` and `dropAfter` each took an offset and used it twice: to move a boundary, and as the cut line for a hand-rolled scan. Each scan had its own shape - one hunted a leading run of consumed cells, the other a trailing run - so the rule "a held cell lies inside the range" was written twice and stated nowhere. Both now move their boundary first and call `dropCellsOutsideRange`, which erases every cell not overlapping `[range_start, range_end)`. That predicate is the union of the two old rules, and a straddling or overhanging cell still overlaps, so it survives as before. The memory hold stays one-sided per method. Held bytes can legitimately sit past `range_end`, because `runAt`'s whole-segment widening pushes the fetch end beyond the cap; `dropAfter` frees them to relieve memory pressure, while `dropBefore` must keep them, since not re-reading already-fetched bytes is the point of the hold. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Master bumped the version to 26.10 in c9ae3d3 and opened a 26.10 block in SettingsChangesHistory.cpp. This branch recorded `reader_executor_plan_look_ahead` under 26.9, which stopped being the current block, so the settings_changes_history style check failed on the merged tree from 2026-09-16 onward. Move the record to 26.10 as part of the merge - master rewrote the same file, so it cannot be split out.
Review feedback, both on text I wrote. `reader_executor_plan_look_ahead` was documented as bounding what a reader holds. It does not: a cache pin covers a whole segment or block - `DiskCacheReader` holds a `FileSegmentPtr`, `PageCacheReader` a `MappedPtr` - so a cell straddling either end of the range stays pinned entire. Clipping `cell.range` narrows what the plan serves, never what it holds, and dropping a straddler would force a source re-read of bytes that are in the cache. The span therefore drives the hold rather than capping it, with up to one overhanging segment or block per tier at each end. `ReaderExecutorConcurrentDownloadWaitTimeouts` claimed every counted wait meant the query advanced at the downloader's pace. It is incremented on any return short of the requested overlap, including the empty one that falls through to `readSource` - the opposite case. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`reader_executor_plan_look_ahead` got a 40 MiB ceiling while `reader_executor_block_size` kept only a floor, and the pre-existing `plan_look_ahead >= block_size` rule then made any `block_size` above 40 MiB unsatisfiable. `getReadSettings` runs for every query, so such a configuration failed everything, including queries that never touch the executor. Put window, block and look-ahead in one `[128 KiB, 40 MiB]` band instead, checked by a single helper. The ceiling can no longer create an unsatisfiable pair, because `block_size` cannot exceed it either. This rejects `reader_executor_window_size` and `reader_executor_block_size` above 40 MiB, which were previously accepted. Deliberate: the settings are EXPERIMENTAL and one coherent band is worth the break. `MAX_READER_EXECUTOR_PLAN_LOOK_AHEAD` becomes `MAX_READER_EXECUTOR_SIZE`, the counterpart of `MIN_READER_EXECUTOR_SIZE`, and the test is renamed `05212_reader_executor_max_size` to mirror `04604_reader_executor_min_size`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
One conflict, in the `26.10` block of SettingsChangesHistory.cpp: master appended `analyzer_compatibility_allow_cte_redefinition` where this branch had appended `reader_executor_plan_look_ahead`. Kept both.
| const size_t hi = lo + piece.size; | ||
|
|
||
| /// The plan resolves every layer itself (all tiers asked, matched by CacheTier). | ||
| stats.add(Stats::CacheGetRequests, cache_chain.size()); |
There was a problem hiding this comment.
ReaderExecutorCacheGetRequests and the modeled-cost KPI are described as counting cache get operations, but this increments once per provider per extend, not once per underlying probe. With the default 1 MiB page-cache blocks and a 16 MiB look-ahead, PageCacheProvider::resolve does 16 cache->get calls here while the counter only grows by 1.
That makes both the new lookup counter and ReaderExecutorModeledCostMicroseconds materially optimistic on page-cache-heavy reads. I think the accounting needs to move into the providers, or resolve needs to report how many cache lookups it actually performed.
One conflict again, same place: master appended `parallel_replicas_for_queries_with_multiple_tables` to the `26.10` block of SettingsChangesHistory.cpp where this branch had appended `reader_executor_plan_look_ahead`. Kept both, and moved our row to the top of the block - the collision only happens because both sides append at the end, and the position within a version block carries no meaning.
|
@CheSema @kssenii — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Introduces a maintained
ReadPlanto the experimentalReaderExecutor(gated byuse_reader_executor, default off). It resolves the residency of a look-ahead span once and holds the pinned hit-readers and miss-writers across serves, instead of re-resolving the cache chain on every read window. The plan grows right (extend) and retires the consumed prefix left (retireBefore) as the cursor advances.extendasks every cache layer itself (fastest-first), matched to held tiers byCacheTier- "all layers asked" is the plan's invariant.runAt(offset)returns astd::variant:ServeFromReader,ServeFromWriter,ServeFromMemory,Fetch, orstd::monostate. AFetchextent is coalesced right to the nearest resident byte (capped at the window), extended left to each covering segment's write frontier, and widened to cover any whole-segment cell it enters (all-or-nothing fill).fetchFillServereads that extent once, fills the tiers, serves one block, and parks the bytes no tier accepted (bypass / detached / rejected write) in the plan's memory hold - served first, freed as the cursor passes, never re-read.Builds on the cache-provider API simplification in #116092 (merge first). Look-ahead is
reader_executor_plan_look_ahead(default 16 MiB, at leastreader_executor_block_size).Schema and walkthrough: #115816 (comment)
Related: #116092
Related: #103706
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The experimental
ReaderExecutorresolves cache residency once into a maintained read plan (configurable viareader_executor_plan_look_ahead) instead of re-resolving on every read window.Workflow [PR]
Sync PR [sync-upstream/pr/115816]
Version info
26.10.1.605-master(included in26.10and later)