Repository navigation
Don't retry a failed read while recovering from a parse error in the Values format - #121916
Conversation
…Values format `ValuesBlockInputFormat::tryReadValue` classifies a failed value read with `isParseError` and, on a match, rolls back to the value's checkpoint and re-walks the row through the expression parser. `CANNOT_READ_ALL_DATA` is on that allowlist, so a read that failed inside the stream is swallowed exactly like a failure to parse a value. That swallow is the defect. A read that throws cancels its buffer for good (`ReadBuffer::next` catches, cancels and rethrows, and the assertion at ReadBuffer.cpp:107 makes the state terminal), while `PeekableReadBuffer::rollbackToCheckpoint` clears only the wrapper's own flag and never the sub-buffer's. After the rollback the wrapper therefore reads as clean while the object it delegates to is canceled, and the re-walk's first refill trips the assertion. The wrapper's own `isCanceled()` is the right predicate at that point, rather than the sub-buffer's: the sub-buffer can only be canceled inside `sub_buf->next()`, reachable only from `PeekableReadBuffer::nextImpl`, reachable only from the wrapper's own `ReadBuffer::next`, whose catch cancels the wrapper on the same unwind. The two flags diverge only after a rollback, and this gate runs before it. Completing the existing gate is what @ Avogar asked for when the same assertion was fixed for `IRowInputFormat` in ClickHouse#109708: reach the skip-bad-lines logic only for a parse error that was not thrown in the buffer itself. It also continues the narrowing f188894 applied to this same allowlist, where only a genuine parse error should be reported as an unparsed value. One site is enough. `readUntilTheEndOfRowAndReTokenize` runs `skipToNextRow` and then `makeContinuousMemoryFromCheckpointToPos`, so every template and retry path afterwards reads the row out of the buffer's own memory and cannot refill, hence cannot cancel. `ValuesSchemaReader` sets no checkpoint at all, and `TemplateRowInputFormat` is already covered by ClickHouse#109708, whose read buffer is the peekable one. Reachable from an HTTP `INSERT ... VALUES` whose body is shorter than its declared `Content-Length` and is streamed to the input format rather than drained for query-text extraction, which `executeQuery.cpp:4180` decides; a truncated body alone is inert. Measured on a debug build: the abort reproduces 3/3 through the `X-ClickHouse-100-Continue: defer` form and 3/3 through a bulk body over `max_query_size`, and the new test aborts the server on the unpatched build while passing with this change.
The test's assertions so far were that the read failure is reported, that the request does not hang, that the server is still alive and that no row landed. Every one of those also holds on the path where the body never reaches a data format at all: without the `X-ClickHouse-100-Continue: defer` header the request is drained for query-text extraction instead, the decision `executeQuery.cpp:4180` makes, and the short read is then reported from `copyData` with the server alive. So the test distinguished the two builds only because the header happens to be there, not because it checked that it mattered, and a later change to that decision would leave the test green while covering nothing. Assert the precondition instead of assuming it. A parse-classified error picks up the row context in `ValuesBlockInputFormat::read`'s own catch, so its presence in the response says the row really was handed to the Values format. Removing the header now flips that one assertion and nothing else, which is the measurement the test was missing. Also give the table the cleanup shape of the test this one is modelled on, `04826_handler_lengthless_body_keep_alive`, so a local re-run starts from a known state instead of relying on each invocation getting a fresh database. Test only, no change to the fix.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex). Two passes: a full review of the
I also re-derived the two claims the original report got wrong, and both corrections hold: What keeps the fix from being over-broad: the third arm ( Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260924-075100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260924-073300 |
|
Workflow [PR], commit [7c7d144] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict
LLVM Coverage ReportMeasured on commit 7c7d144.
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes one branch in the Values input format: it now rethrows a parse exception when the read buffer was canceled, plus a new stateless test. Only INSERT ... VALUES error recovery runs that code. One ClickBench query was flagged: Q16 is +10.4% (585 ms vs 530 ms). It is a read-only SELECT that never runs the changed code, and its time falls inside the range master itself currently varies over, so the suppression holds and nothing in this PR explains it. No performance impact from this PR is expected or shown on clickbench or tpch_adapted_1_official. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
INSERT ... VALUESover a stream that fails mid-row now reports that read failure directly, instead of retrying the failed read while recovering from a parse error. This affects an HTTP request body that is shorter than its declaredContent-Lengthand is streamed to the input format.Description
Related: #109708
ValuesBlockInputFormat::tryReadValueclassifies a failed value read withisParseErrorand, on a match, rolls back to the checkpoint and re-walks the row through the expression parser.CANNOT_READ_ALL_DATAis on that allowlist, so a read that failed inside the stream is swallowed like a failure to parse a value. A throwing read cancels its buffer for good, andPeekableReadBuffer::rollbackToCheckpointclears only the wrapper's flag, never the sub-buffer's, so the re-walk refills a canceled buffer and trips the assertion inReadBuffer::next().I complete the existing gate with the buffer's own cancellation state, so recovery runs only for a parse error not raised inside the stream. This is the shape @ Avogar prescribed for the same assertion in
IRowInputFormat(#109708).Not a
Bug Fix: the assertion is active only in debug and sanitizer builds. In a stable build it is compiled out and the failed read is reported either way, so no released version misbehaves.Reachability: an HTTP
INSERT ... VALUESwhose body is shorter than its declaredContent-Lengthand is streamed to the format rather than read as query text. Two default-settings forms qualify: a bulk body overmax_query_size(256 KiB), or a client sendingX-ClickHouse-100-Continue: defer. A truncated body alone is inert.One site, not several:
readUntilTheEndOfRowAndReTokenizeputs the whole row into the buffer's own memory before any template or retry path reads it, so those cannot refill or cancel; the schema reader sets no checkpoint;TemplateRowInputFormatis covered by #109708.CIDB shows no occurrence of this frame chain in 120 days, so I have no failing job to link. The substitute is the new test, which aborts the server on the unpatched build and passes with the fix.
Alternatives not taken: propagating cancellation through
PeekableReadBuffer, which reverses schema-detection behaviour added in5c6c629bfc4e8, and weakening the assertion, which #109785 owns.Workflow [PR]
Sync PR [sync-upstream/pr/121916]
Version info
26.10.1.1686-master(included in26.10and later)