Repository navigation
Check the schema of every block a client sends for an external table - #119849
Conversation
The schema of a query-local external table is bound once, by the first Native block the client sends for it. `TCPHandler::processData` did not compare the blocks that follow against that schema, and nothing else does either: the columns of such a block are written to the table as a `Chunk`, which carries no types at all, and `MemorySink::consume` labels them with the table header again. A client that declared one type in the first block and another in the second therefore got its data read back as the type named by the header - a type confusion on data the client controls, which for `AggregateFunction` columns means the state of one function being interpreted as the state of another. Every block after the one that bound the schema is now validated against it and rejected with `INCORRECT_DATA`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [3fcf2e0] Summary: ✅
AI ReviewSummaryThis PR fixes the missing schema validation for repeated external-table uploads on the native TCP and HTTP multipart paths, adds focused regressions for both, and updates the Native protocol spec to document the per-table schema invariant. The two earlier inline concerns on this PR are addressed in the current head, and I did not find a remaining blocker or major issue in the patched code. Final Verdict✅ No blocking or major findings on the current PR head. LLVM Coverage ReportMeasured on commit 3fcf2e0.
Changed lines: Changed C/C++ lines covered: 22/22 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 26 s compile time in total, 8 of them have a recent master baseline. |
…block-schema # Conflicts: # src/Server/TCPHandler.cpp
…xternal table `ExternalTablesHandler::handlePart` looks up the `_structure` / `_types` fields by the part name each time, and `HTMLForm::readMultipart` adds plain form fields to the parameter set as it reads them, so a later part with the same name could declare a different schema than the one the first part bound. The data of such a part reached the already-bound `StorageMemory` table, where the mismatch surfaced only as a `LOGICAL_ERROR` from the pipeline connect (`Block structure mismatch in function connect between ParallelParsingBlockInputFormat and MemorySink stream`), i.e. a client-triggerable logical error instead of a data error. Compare the declared schema of every part after the first with the bound one and reject a mismatch with `INCORRECT_DATA`, as the Native protocol path now does. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ets in the Native protocol spec Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
🕵 @groeneai, investigate the failure: https://github.com/ClickHouse/clickhouse-private/actions/runs/34819722237/job/103902645387 ( |
|
Acknowledged. I am investigating the foreground I will follow up in this thread with a separate fix PR, or with a link to the existing PR if one turns out to cover this signature. |
|
Three measurements, and the first one changes the framing. The pool name is a formatting artifact, not a mechanism. The public carrier of this signature is gone. Over 120 days, 20 CIDB rows carry that addendum. 19 are The read side cannot be the defect in this tree. A live That leaves the deletion side, which is where your configuration leaves the tree. I cannot read the run. The private repo, that run, that job and PR 74720 all return 404 for my token, and the public On whether a fix is already in progress, nothing open covers this signature. #119154 covers the One offer rather than an unsolicited PR: the harness records the matched line in |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
🕵 @groeneai, thanks for the analysis. What I can add from the private side: Same head, different result. The private sync PR head is unchanged ( What the harness recorded for the key. The only line the job kept is the I cannot give you the Harness improvement: yes, please. Emitting the #114046: agreed that it cannot be this signature ( No action on this PR: the public CI is 159 green / 0 red, and the private reds are flakes on an unchanged commit. I will re-run the failed private jobs once that workflow finishes. |
|
Acknowledged. I am opening a separate PR that emits, next to each |
|
🕵 Status of the
@groeneai, thanks for taking the harness improvement, nothing else is needed from you for this PR. I will re-run the failed private jobs once the workflow completes. |
|
🕵 The separate fix for |
…terialized_warning` by time The test checked for the stale `MATERIALIZED` warning with a `SELECT` over `system.text_log` filtered only by `logger_name`. In a long parallel run the table grows past the 20M-row `max_rows_to_read` limit of the test profile, and the query fails with `TOO_MANY_ROWS` (seen in the `CH Inc sync` run of ClickHouse#119849: `Stateless tests (amd_release, distributed cache, meta in keeper, s3 storage, parallel)`). Add the `event_date` / `event_time` bound that the other `text_log` tests use, so the scan goes through the primary key. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Integrate upstream through 360a086 while preserving the existing profiler changes. Resolve the protocol documentation overlap by retaining the external-table schema validation guarantee and the rule that `ProfileTraces` delivery waits for the upload terminator. The five overlapping C++ files preserve the previous profiler diff. The external-table schema guard remains before storage writes, and early upload exceptions still discard queued traces before the terminal response. Related: ClickHouse#118415 Related: ClickHouse#119849 Co-Authored-By: Codex CLI <[email protected]>
Cherry pick #119849 to 26.6: Check the schema of every block a client sends for an external table
…nds for an external table
Cherry pick #119849 to 26.3: Check the schema of every block a client sends for an external table
…nds for an external table
Cherry pick #119849 to 26.8: Check the schema of every block a client sends for an external table
…nds for an external table
Cherry pick #119849 to 26.7: Check the schema of every block a client sends for an external table
…nds for an external table
|
Both sites covered. Each matched key now gets its One thing found on the way: the |
Backport #119849 to 26.8: Check the schema of every block a client sends for an external table
Backport #119849 to 26.7: Check the schema of every block a client sends for an external table
Backport #119849 to 26.6: Check the schema of every block a client sends for an external table
Backport #119849 to 26.3: Check the schema of every block a client sends for an external table
A `Code: 499 ... The specified key does not exist` red records only the failing read: `no_such_key_errors.txt` holds the matched error line and nothing else, so the artifact names the victim and never the culprit. It does not say when the object was written, whether it was deleted, by which thread, or whether the delete was a batch removal. By the time the question is asked the server logs are usually gone, and the investigation dead-ends on lines that were in the log at the time. Those lines are in the same logs, keyed by the same string. `ReadBufferFromS3::key` is `splitBucketAndKey(remote_path).second`, which for a non-qualified path returns `remote_path` verbatim, and that is also the key that `Writing blob for path` and `deleteFileFromS3` print. They were simply never selected. `ci/jobs/scripts/s3_key_lifecycle.py` extracts each matched key with `while reading key: (...)`, makes one `grep -F` pass over the enumerated logs for all keys at once, and prints each key's lines under its own header in timestamp order (grep reports one file at a time, so file order is not time order and an upload would otherwise print after the delete that followed it). Lines are kept by logger name rather than by message wording, so rewording a log message cannot silently empty the report. A key with nothing to show says so: an empty report and "no lifecycle exists" must not look alike. Every distinct key always gets a header and only the per-key line expansion is capped, so no key can vanish from the largest incident, which is the one worth attributing. Both harness sites that run the grep call it. Note that `no_such_key_command` in `clickhouse_proc.py` is fed to TWO `Result` rows, `Lost s3 keys` and `S3_ERROR No such key thrown (in clickhouse-server.log or clickhouse-server.err.log)`, so the single edit moves both. The verdicts are unchanged. The appender's status is discarded and the group's status comes from the trailing `echo`, so a failed collection cannot turn a real failure into `No lost s3 keys`; it leaves a marker in the artifact instead. Both row texts are left alone deliberately, because those strings are the CIDB `test_name`s and renaming them would break every query keyed on the signature. Replacing `tee /dev/stderr | grep -q .` with `cat >&2` plus an explicit emptiness test also repairs a pre-existing truncation of those two rows' `info`: `grep -q` exits on its first line, so `tee` takes SIGPIPE and the copy to stderr is cut off once the content grows. Measured on a 133,848-byte report, the old shape delivered 28,200 bytes and the new one delivers all of it. The appended section sits at the end, which is exactly the part that was being lost. Commissioned in ClickHouse#119849 (comment)
The schema of a query-local external table is bound once, by the first Native block the client sends for it.
TCPHandler::processDatadid not compare the blocks that follow against that schema, and nothing else does either: the columns of such a block are written to the table as aChunk, which carries no types at all, andMemorySink::consumelabels them with the table header again. A client that declared one type in the first block and another in the second therefore got its data read back as the type named by the header - forAggregateFunctioncolumns, the state of one function read as the state of another.Every block after the one that bound the schema is now validated against it and rejected with
INCORRECT_DATA.The HTTP multipart path had the same gap in a milder form:
ExternalTablesHandler::handlePartlooks up_structure/_typesby the part name each time andHTMLForm::readMultipartadds plain form fields as it reads them, so a later part with the same name could declare another schema. There the mismatch surfaced as a client-triggerableLOGICAL_ERRORat pipeline connect. Every such part is now checked against the bound schema too and rejected withINCORRECT_DATA. The Native protocol specification documents the invariant.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the server not validating the schema of the second and subsequent data blocks that a client sends for an external table over the native protocol. Such a block could make the data be interpreted as a type other than the one it was sent as.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119849]
Version info
26.9.1.1488(included in26.9and later)26.8.5.11,26.7.9.11,26.6.7.17,26.3.33.81