Repository navigation
Fix ReadBuffer-canceled abort in GraceHashJoin spilled-block reader - #111056
alexey-milovidov merged 13 commits into
Conversation
One AccumulatedBlockReader is shared between concurrent
DelayedJoinedBlocksWorkerTransform threads. When reader->read() threw
mid-read (e.g. a MEMORY_LIMIT_EXCEEDED that cancels the underlying
ReadBuffer via ReadBuffer::next()'s catch), read() propagated the
exception without marking the reader finished. A sibling worker then
re-entered read() on the now-canceled buffer and tripped
chassert(!isCanceled()) ("ReadBuffer is canceled. Can't read from it."),
aborting the server in debug/sanitizer builds.
Set eof on any read failure so subsequent reads on the shared reader
return an empty block instead of re-reading the canceled buffer. The
query still fails with the original exception.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings across 1 full pass + 1 delta recheck; bounded).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-3:20260720-094200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-3:20260720-094200 |
|
cc @nickitat @vdimir — could you review this? It fixes the chronic |
|
Workflow [PR], commit [170ad21] Summary: ✅
AI ReviewSummaryThe PR fixes the shared Final Verdict✅ No new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 34/34 (100.00%) · Uncovered code |
count() lets the analyzer prune the wide l.s column (confirmed via EXPLAIN under enable_analyzer=0), so the spilled left payload need not be materialized and the shared delayed-reader path this PR fixes could go uncovered. Selecting l.s post-join makes it a required output column under both analyzers, so the mid-read failure on the shared AccumulatedBlockReader is exercised. Addresses the automated-review finding on the regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — 79a46c7Every failure below has an owner (a fixing PR). Only
Notes: Session id: cron:our-pr-ci-monitor:20260720-210000 |
… reader The existing stateless regression 04545_grace_hash_join_read_after_cancel is probabilistic: it relies on a tight max_memory_usage failing a spilled read at the right moment. Measured on a debug build with the branch instrumented, that query never reaches AccumulatedBlockReader::read at all - the memory limit fires earlier, in MergeTreeSelect while reading the source table (10/10 runs: zero entries into the reader, zero DelayedBlocks constructions). So the branch this PR adds was not covered. Add failpoint grace_hash_join_fail_in_delayed_block_read, armed only for the left (delayed) reader, which cancels the underlying buffer and then throws - the same post state ReadBuffer::next leaves on a real mid-read failure. DelayedJoinedBlocksTransform hands the same delayed stream to every worker port before any worker runs, so the reader is already shared when the failure is injected. With the fix the new test passes (50/50 under randomization); with the eof assignment removed it aborts 5/5 with "ReadBuffer is canceled. Can't read from it.", which is the signature this PR exists to prevent. Co-Authored-By: Claude Fable 5 <[email protected]>
The memory-limit variant added earlier in this PR passes with the fix reverted, so it proves nothing: measured on a debug build, the injected memory limit fires in MergeTreeSelect while reading the source table and the query never enters AccumulatedBlockReader::read at all. Keeping both would leave a test that cannot fail for the reason it names. Co-Authored-By: Claude Fable 5 <[email protected]>
CI finish ledger - b52c6f4Every 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
174 check-runs on this head, all completed: 155 success, 18 skipped, 1 failure, the row above. This is the first ledger for this head; the previous one covered Session id: cron:our-pr-ci-monitor:20260729-193000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 34/34 (100.00%) · Uncovered code |
CI finish ledger - 2f98365Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260801-230000 |
|
Fixing PR for the pre-auth That PR reapplies #110760 (reverted in #112935) together with the fix: |
|
Following up on the ledger above: the fixing PR for the It is not a flaky-wait fix. The root cause is an engine bug, so no timeout would have helped: a |
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 units8 translation units recompiled, 11 s compile time in total, 8 of them have a recent master baseline. |
CI finish ledger - c9b890a49e3b7c1f6cd15b0f4a5ed4d4bdb0f4abCI is fully finished on this head: 177 check runs, 160 success, 17 skipped, 0 failures.
The 17 skipped jobs are the standard non-applicable set for this PR (Performance Comparison Session id: cron:our-pr-ci-monitor:20260816-113000 |
CI finish ledger - fe86a2dEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Not this PR's diff: the failing target is The Session id: cron:our-pr-ci-monitor:20260817-090000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR: ReadBuffer is canceled. Can't read from it.that could occur in agrace_hashjoin when reading spilled blocks failed mid-read while multiple threads shared the reader.Description
GraceHashJoinshares oneAccumulatedBlockReaderbetween concurrentDelayedJoinedBlocksWorkerTransformthreads. Ifreader->readthrows while reading a spilled block,ReadBuffer::nextcancels the underlying buffer and rethrows. Previously the shared reader was not marked finished, so a sibling worker could re-enterreadon the canceled buffer and throwLOGICAL_ERROR: ReadBuffer is canceled. Can't read from it.The query should instead preserve and report the original read exception.The fix marks
AccumulatedBlockReaderfinished on every read exception while holding its existing mutex. Subsequent workers return an empty block and cannot re-read the canceled buffer. This covers both the left delayed reader and the right reader that use the samereadimplementation.The new stateless regression deterministically forces a failure only in the shared left delayed reader: it cancels the underlying buffer, throws
FAULT_INJECTED, verifies the query reports that original exception, and then verifies that the server remains alive. Without theeofassignment, a sibling worker re-enters the canceled buffer and triggers the original logical exception.Workflow [PR]
Sync PR [sync-upstream/pr/111056]
Version info
26.8.1.1598(included in26.8and later)