Skip to content

ReaderExecutor: coordinate cleanup, run-anchored reach, serve-to-bound long connections - #111088

Merged
CheSema merged 7 commits into
masterfrom
reader-executor-coord-longconn
Jul 21, 2026
Merged

CheSema merged 7 commits into
masterfrom
reader-executor-coord-longconn

Conversation

@CheSema

@CheSema CheSema commented Jul 20, 2026

Copy link
Copy Markdown
Member

Cache-independent refactors split out of the ReaderExecutor cache-chain PR (#110029) so they can
be reviewed and merged on their own. All are behind the experimental use_reader_executor path
(off by default); no user-facing behavior change.

  • OffsetMap: findObjectAt returns a Segment (object + file offset) instead of a StoredObject*
    plus a size_t* out-param; Segment::logical_offset renamed to file_offset (it was always a
    physical file offset).
  • Centralize the executor's physical<->logical coordinate conversions behind toPhys/toLogical
    instead of scattered inline +/- data_start_offset.
  • Track a run-anchored reach prediction (predictedEnd) for the held source connection.
  • Serve a window that crosses the connection's bound as a short window (canServeAt) instead of
    dropping the connection and draining+re-reading the residual, which over-read on a cold scan.

Verified: the ReaderExecutor / OffsetMap / ReadContinuityTracker / PipelineReadBuffer gtests
and the 0431x/0434x/0450x executor functional tests.

Related: #110029

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

CheSema added 3 commits July 20, 2026 14:26
…ersion

Return a `Segment` (object plus its file offset) from `OffsetMap::findObjectAt`
instead of a `StoredObject*` plus a `size_t*` out-param, and rename
`Segment::logical_offset` to `file_offset` -- it was always a physical file offset,
so the old name collided with the executor's "logical" (payload) vocabulary.

Route the executor's physical<->logical conversions through two helpers, `toPhys`
and `toLogical`, instead of scattered inline `+/- data_start_offset`. No behavior
change.
…prediction

Re-port ReadContinuityTracker: the reach estimator now predicts an ABSOLUTE
run-anchored end (predictedEnd) instead of a forward length from the caller's
offset (predictedForwardLength). Anchoring at the run rather than the cursor
avoids re-anchoring the prediction forward as the cursor advances -- which
inflated it at ~twice the consumption rate; the predicted end is now identical
wherever a caller asks from. Includes the continuation-checkpoint fold and the
live-run blend fix.

Adapt the executor: clampReach bounds the absolute predicted end to
[position, file end]; shouldOpenLongConnection and the held-GET bound use
predictedEnd. Re-port the tracker gtest for the new API.
…t windows)

Replace the all-or-nothing `canContinue` with `canServeAt`: a window that crosses the
held connection's bound is served short (up to `read_until`) instead of being rejected --
rejecting previously dropped the connection, drained the residual, and re-read it, so a
cold sequential scan over-read at every bound. `readNextWindow` now treats a short window
(`got < want`) as normal (advance by `got`, re-call; EOF only at `got == 0`, where a
known-size source ending early is truncation). Pairs with the run-anchored reach.
@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [498a995]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) FAIL
Server died FAIL cidb
04066_pr_view_non_simple_views UNKNOWN cidb
03601_temporary_views UNKNOWN cidb
00918_json_functions UNKNOWN cidb
02004_max_hyperscan_regex_length UNKNOWN cidb
00700_to_decimal_or_something UNKNOWN cidb
03915_exchange_tables_race UNKNOWN cidb, issue
03229_query_condition_cache_folded_constants UNKNOWN cidb
03751_fixed_string_escape_quote_with_quote UNKNOWN cidb
02890_named_tuple_functions UNKNOWN cidb
3 more test cases not shown

AI Review

Summary

This PR refactors ReaderExecutor/ReadContinuityTracker, moves the continuity estimate to a run-anchored absolute end, and changes long-connection reuse to serve windows up to the held bound instead of dropping and refetching the residual. The predictor math looks coherent, but the new "short window is normal" rule weakens known-size truncation detection: a truncated object can now be accepted on prefix reads if the caller stops after the first short window, so I do not think this is ready to merge as-is.

Findings

❌ Blockers

  • [src/IO/ReaderExecutor.cpp:508-517] Known-size objects no longer fail as soon as the executor has already observed an impossible short read. After this change, any positive short read is treated as normal and the exception only appears on a later got == 0, which means prefix-read workloads can miss the corruption entirely. A concrete trace is bytes_size = 1000, actual length 100, block_size = 256, and a caller that only consumes a prefix through PipelineReadBuffer: the first window asks for 256, gets 100, and can be returned successfully with no later read to surface the truncation.
    Suggested fix: keep short-window handling only for the long-connection-bound case (serve < want). If a known-size source returns got < requested_from_source, throw immediately as before, and add a focused regression that stops after consuming only a prefix of that first short window.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: restore immediate truncation detection for known-size short reads that are not explained by the held connection bound, and cover that prefix-read case with a focused regression.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 20, 2026
CheSema added 2 commits July 20, 2026 17:13
The member tracks the ranges we fetch to predict the held connection's reach; `fetch_tracker`
names that intent. Pure rename, no behavior change.
Cut the doc-comments on the coordinate/OffsetMap/long-connection changes down to terse
non-obvious notes. No code change.
@CheSema
CheSema marked this pull request as ready for review July 20, 2026 15:14
Cut the verbose narration on `predictedEnd`, `checkpointRun`, the exact-continuation
checkpoint, and the class doc down to terse non-obvious notes. No code change.
Comment thread src/IO/ReaderExecutor.h Resolved
Spell it out so it reads symmetrically with `toLogical` (review suggestion).
@CheSema
CheSema enabled auto-merge July 21, 2026 10:50
Comment thread src/IO/ReaderExecutor.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 48.20% 86.20% +38.00%
Functions 56.90% 92.00% +35.10%
Branches 36.60% 78.20% +41.60%

Changed lines: Changed C/C++ lines covered: 223/228 (97.81%) · Uncovered code

Full report · Diff report

@CheSema
CheSema added this pull request to the merge queue Jul 21, 2026
Merged via the queue into master with commit 296c1ae Jul 21, 2026
178 of 180 checks passed
@CheSema
CheSema deleted the reader-executor-coord-longconn branch July 21, 2026 16:37
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 21, 2026
CheSema added a commit that referenced this pull request Jul 23, 2026
The #111088 extract added an `UnknownSize` test against its
`findObjectAt` API; the merge kept this branch's `map` API, so the
coverage is re-expressed against it.

Related: #111088

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…coord-longconn

ReaderExecutor: coordinate cleanup, run-anchored reach, serve-to-bound long connections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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.

3 participants