Repository navigation
Create a new input format for each streamed input unless the format resets all its state - #129209
Conversation
…self StreamingFormatExecutor (async insert flushes, Kafka, Kafka2, NATS, RabbitMQ, FileLog) kept one input format object for many independent inputs and called resetParser() between them, trusting every format to bring itself back to the state of a fresh object. Nothing enforced that: 32 of the 82 input format names kept some per-input field (One `done`, Npy `read_rows`, MySQLDump `table_name` and column mapping, SQLite flags and database, JSON `parse_as_json_each_row`, DWARF section extractors, TSV `first_row`, CustomSeparated `columns` and the detected header, RowBinaryWithNamesAndTypes `read_data_types`, Template `row_num`), so a later input of an async insert batch or a later message lost rows, was rejected, or was parsed with the previous input's state. Per-format resetParser fixes (ClickHouse#128943, ClickHouse#129109, ClickHouse#129140) leave the default unsafe for the next format and the next field. Invert the default: a format is reused only when its name is registered with FormatFactory::markInputFormatSupportsResetParser; any other format is released after each input and created anew for the next one. The executor now takes a format creator and an AddingDefaultsTransform creator (the transform holds a reference to the format). The streaming engines compute their single-threaded parser resources once and share them between created formats. Marked: the 50 names whose reset is complete and 26 hot names completed here with one statement each (TSV first_row, CustomSeparated columns, WithNamesAndTypes is_header_detected, RowBinary read_data_types, Template row_num). Reuse matters for them: a fresh CapnProto, Template, Protobuf, Regexp or AvroConfluent object reads or compiles schemas. Not marked, so re-created with no per-format code: One, Npy, MySQLDump, SQLite, JSON, DWARF. DWARF's incomplete resetParser is deleted. 02187_async_inserts_all_formats now also inserts every format as one batch of two different inputs, plus targeted cases for the leaks that a same-shaped pair does not show, and a FileLog case. Closes ClickHouse#122351 Co-Authored-By: Claude Opus 5.5 <[email protected]>
TemplateRowInputFormat rewrites settings.csv.delimiter and
csv.custom_delimiter before every CSV-escaped column, so an input ends
with the values for the last CSV column of the row format. The format is
marked as resetting all per-input state, but resetParser did not restore
them, and the next input's result-set prefix skipped its ${:CSV} field
with the previous input's delimiter: in one async insert batch the second
input was rejected with "expected ','". Restore both to the values of a
fresh object, and add a Template batch case to
02187_async_inserts_all_formats.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Values` is reused across streamed inputs, but its `resetParser` kept each column's parser mode, templates and template deduction counters unless the previous input threw. Only the streaming mode understands `DEFAULT`, so after an input whose column needed an expression (`(1 + 1)`), a later `(DEFAULT)` in the same async insert batch went through the template/expression path and was rejected with `Unknown expression identifier DEFAULT`, while a fresh format inserts the column default. Reset every per-column field to its constructor value; `templates_cache` is kept, since it is keyed by the expression structure and a fresh object would rebuild the same entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `format_custom_escaping_rule = 'CSV'`, `CustomSeparatedFormatReader::updateFormatSettings` rewrites `csv.delimiter` of the reader's own settings copy before each field, but only when the next delimiter is one character; a multi-character delimiter goes to `csv.custom_delimiter` and leaves `csv.delimiter` as it was. So the last column of one input (row delimiter `'\n'`) left `csv.delimiter = '\n'`, and a reused reader parsed column 0 of the next input with it: a `Bool` followed by the `', '` field delimiter was rejected, while a fresh reader accepts it. The reader now restores the constructor's delimiter and clears the custom one in `setReadBuffer`, which runs for every new input. `02187_async_inserts_all_formats` gains the batch case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop two comments on the StreamingFormatExecutor creator aliases that restate their names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 1-4): 3 fixed, 2 dismissed with evidence
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261104-081600 |
|
Workflow [PR], commit [a820384] Summary: ✅
AI ReviewSummaryReviewed #129209 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings to post. |
|
cc @Avogar @CheSema, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units306 translation units recompiled, 2123 s compile time in total, 306 of them have a recent master baseline. |
Algunenano
left a comment
There was a problem hiding this comment.
@groeneai I like the general direction of this PR, but this should be part of the format registration, not require and extra call via markInputFormatSupportsResetParser. markFormatSupportsSubsetOfColumns is not a good example and we should probably remove it.
Also please update vs master
…only-if-it-resets # Conflicts: # src/Processors/Formats/IInputFormat.h
Replace the separate `FormatFactory::markInputFormatSupportsResetParser` call with a `supports_reset_parser` argument of `registerInputFormat` and `registerRandomAccessInputFormat`, so the property is stated where the format is registered. It defaults to false: a format that does not pass it is created anew for each streamed input. The same 76 names pass true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, both done:
On the new head |
Algunenano
left a comment
There was a problem hiding this comment.
I think this is quite verbose, but it's the right defaults
…allel replicas With parallel replicas, an `INSERT ... SELECT` into a `Join` table runs on every replica, and the inserts share the initial query id. `StorageJoin` takes its write lock by that id, so when two replicas insert at the same time, the second one fails with `DEADLOCK_AVOIDED`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129209&sha=013785db07d54a273f8795ffd2b6a00f4cb1345f&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 Related: ClickHouse#129209 Related: ClickHouse#129328 Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 013785dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Both fixes were merged after this head's CI started. The 5 Session id: cron:our-pr-ci-monitor:20261112-200351 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed lost, rejected or misparsed rows when several
INSERT ... FORMAT SQLite,One,Npy,MySQLDump,JSON,RowBinaryWithNamesAndTypes,CustomSeparated,Template,TSVorValuesqueries are combined into one asynchronous insert batch (asynchronous inserts are enabled by default), and inFileLogtables with these formats: each input is now parsed as if it were the only one.Description
Closes: #122351
Related: #129140 (replaced by this PR)
Related: #129109 (replaced by this PR)
Related: #128943 (the same class in
MsgPack)On 26.10.2.103, one asynchronous insert batch of two
FORMAT SQLiteinputs inserts only the first one's rows and threeFORMAT Oneinputs insert one row. The other formats in the changelog entry fail the same way.StreamingFormatExecutor(async inserts, Kafka, NATS, RabbitMQ, FileLog) reuses one format for all inputs and trustsresetParserto restore a fresh state; 33 of the 82 input format names did not.A format is now reused only if its registration passes
supports_reset_parser = true(FormatFactory::registerInputFormat); any other is created anew per input, so a new format cannot break streamed inputs. 76 names pass it: those whose reset is complete, plus seven reset completions (TSVCRLF check,CustomSeparatedheader width, detected header and CSV delimiter,RowBinaryWithNamesAndTypestypes,TemplateCSV delimiter and row number,Valuesparser mode). Reuse is kept because some formats are costly to build (CapnProtoparses a schema,Regexpcompiles one).One,Npy,MySQLDump,SQLite,JSONandDWARFare re-created, with no per-format code.Validation:
02187_async_inserts_all_formatsnow also inserts each format as a batch of two inputs, plus targeted cases. 13 cases fail on master and 26.10.2.103, 50/50 runs pass with the fix, and undoing a reset completion (except theTemplaterow number, seen only in error text) or passing it forSQLiteorOnereddens exactly its case. Reused formats still rely onresetParser; the batch case checks those it inserts. Price (debug build): FileLog with 200kJSONEachRow/TSVrecords is unchanged; re-creating costs about 3 us per input (one flush of 4500JSONentries: 37-43 ms, now 51-76 ms); theValuesreset about 10 us per input with an expression (4500(1 + 1)entries: 48-49 ms, now 91-97 ms; literals unchanged).Workflow [PR]
Sync PR [sync-upstream/pr/129209]
Version info
26.11.1.2238-master(included in26.11and later)