Repository navigation
Conversation
`MultipleFileWriter::consume` compares `buffer->count()` with `iceberg_insert_max_bytes_in_data_file` between the blocks. The data file format was created with `getOutputFormatParallelIfPossible`, so for a row format with parallel formatting the `ParallelFormattingOutputFormat` collector thread wrote the same buffer concurrently: a data race reported by TSan (La Casa Del Dolor, amd_tsan), and a size check that sees a count lagging by an unknown number of blocks. Create the format with `getOutputFormat` (the other Iceberg writers, compaction and mutations, already do), and disable the squashing thread of the Pretty formats, which also writes the buffer from its own thread and defers the writes so that the size limit is not applied. Parquet, ORC and Avro take the same path as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`iceberg_insert_max_bytes_in_data_file` is checked between the blocks against the size of the data file written so far. Two formats wrote the file from threads of their own: a row format with parallel formatting (`RowBinary`; on the unfixed tree TSan reports the race and the files run past the limit by up to two times), and a Pretty format with squashing (`PrettyCompact`; on the unfixed tree the whole INSERT lands in one file). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the comment on the in-thread output format of Iceberg data files to one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings; 1 full pass).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261104-033400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261104-024000 |
|
cc @PedroTadim @hanfei1991, could you review this and add the |
|
Workflow [PR], commit [bf7e375] AI ReviewSummaryReviewed PR #129168 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings; normal CI validation remains pending. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
|
@groeneai why the changelog category is not for changelog? |
|
Because neither problem is in a release. Both come from #127670, which made |
| /// the column mapper, so it covers the compaction/mutation rewrite paths too. | ||
| FormatFilterInfoPtr format_filter_info = std::make_shared<FormatFilterInfo>(nullptr, context, column_mapper, nullptr, nullptr); | ||
| output_format = FormatFactory::instance().getOutputFormatParallelIfPossible( | ||
| output_format = FormatFactory::instance().getOutputFormat( |
There was a problem hiding this comment.
@groeneai are you sure this wont create a performance regression elsewhere?
There was a problem hiding this comment.
Not for every format, so I measured it.
Scope: only MultipleFileWriter, i.e. Iceberg INSERT on any object storage. Iceberg compaction and mutations already use getOutputFormat. Parquet, ORC and Avro (the Iceberg data file formats) do not support parallel formatting, so getOutputFormatParallelIfPossible already returned getOutputFormat for them (FormatFactory.cpp:856, :874): no change there. squash_consecutive_ms only affects Pretty*.
Row formats (CSV, TSV, JSONEachRow, RowBinary, ...) lose the formatting threads. Release builds, INSERT INTO <IcebergLocal table> SELECT number, toString(number * 7919), number / 3, toDateTime(number) FROM numbers_mt(N), seconds, master / this PR, median of 3:
| Shape | Parquet | CSV | JSONEachRow | RowBinary |
|---|---|---|---|---|
max_insert_threads = 1, 20M rows |
2.54 / 2.58 | 0.99 / 2.33 | 1.16 / 3.41 | 0.90 / 1.34 |
| defaults, 384 cores, 100M rows | 2.15 / 2.13 | 1.09 / 2.02 | 1.38 / 2.45 | 0.83 / 1.23 |
16 cores (taskset), max_threads = max_insert_threads = 16, 50M rows |
1.55 / 1.49 | 1.15 / 0.93 | 1.46 / 1.42 | 0.67 / 0.64 |
So row formats get up to 2.9x slower when there are fewer insert threads than cores, and are not slower when the insert threads already use the cores. Master with output_format_parallel_formatting = 0 gives the same numbers as this PR, so the difference is only the formatting threads.
I'd keep it as is: the parallel path is the TSan race and data files over iceberg_insert_max_bytes_in_data_file (up to 2x in the test), and these formats are not data file formats in the Iceberg spec. Keeping the threads would need a thread-safe byte counter in ParallelFormattingOutputFormat, and the size check would still lag by the blocks being formatted. Tell me if you prefer that.
There was a problem hiding this comment.
@groeneai I just realized, the row formats (CSV, TSV, JSONEachRow, RowBinary, ...) should be disallowed as Iceberg formats?
There was a problem hiding this comment.
Yes, I think so, for writes. Measured on master (26.11.1.1316):
- The Iceberg spec allows only
avro,orcandparquetas thefile_formatof a data file, and ClickHouse writes the format name into the manifest as is (IcebergWrites.cpp:617). PyIceberg 0.11.1 reads theParquettable and fails on the others:ValueError: 'CSV' is not a valid FileFormat(same forRowBinary,JSONEachRow,Native). - ClickHouse reads
CSV,TSVandRowBinarytables back only if the reader passes the same format; with the default format it fails (INCORRECT_DATA,CANNOT_PARSE_INPUT_ASSERTION_FAILED,CANNOT_READ_ALL_DATA).PrettyCompactandMarkdowntables cannot be read back at all (FORMAT_IS_NOT_SUITABLE_FOR_INPUT). - The docs say writes support the formats of the Iceberg spec, and Support other formats (ORC, ...) in iceberg writes #87277 opened writes for ORC and Avro, not for row formats.
The check would allow Parquet, ORC, Avro and Vortex (written into Iceberg on purpose, e.g. 05339_vortex_iceberg_mixed_write_format). All four write the data file on the inserting thread, so with the check the race and the row-format size limit overshoot fixed here are no longer reachable. The only other test that writes a row format is test_writes_create_table_bugs (CSV, 0 rows).
So either:
- I replace this PR with the check (a behaviour change for the Beta
allow_insert_into_iceberg), or - this PR stays as is and I send the check as a separate PR.
Which do you prefer?
There was a problem hiding this comment.
I prefer to go with 1. Also look for the other data lake formats: delta lake, paimon and hudi
There was a problem hiding this comment.
OK, I'll replace the change in this PR with the format check. I measured the other lakes on master (26.11.1.1316):
- Hudi and Paimon have no write path in ClickHouse (
INSERTfails withWrites are not supported for engine. (NOT_IMPLEMENTED)). Nothing to check there. - Delta Lake has the same gap as Iceberg. The Delta protocol allows only Parquet data files, but a
DeltaLakeLocal(path, CSV)table (same forRowBinary,JSONEachRow,PrettyCompact,ORC,Avro) accepts theINSERT, commits a.csvdata file to_delta_log, and reading the table back then fails withNot a Parquet file (wrong magic bytes at the end of file).
So the check will allow Parquet, ORC, Avro and Vortex for Iceberg writes and only Parquet for Delta Lake writes, and reject the rest on write. Reading and DESCRIBE of tables declared with another format stay as they are. I'll post here when the PR is updated.
There was a problem hiding this comment.
@PedroTadim correction to my plan above: the check you asked for already exists in my #105667, added there after your report (#105667 (comment)). At its head 2a7fd2e8 it rejects any other format with BAD_ARGUMENTS for a new table or a table function, per engine: Iceberg Parquet, ORC, Avro, Vortex; DeltaLake Parquet; Paimon Parquet, ORC, Avro; Hudi Parquet, ORC (test 05037_datalake_unsupported_format_rejected). That rejects the fuzzer's INSERT INTO TABLE FUNCTION icebergLocal(..., format = 'RowBinaryWithNamesAndTypes'). A write-time check here would be a second copy of that list, so I have not written it.
The only path #105667 leaves open is a table attached from a definition stored before the upgrade (ATTACH is exempt there): it can still INSERT in a row format and hit this race.
Which do you prefer?
- I close this PR and rely on Reject compression_method argument for data lake engines #105667.
- I keep this PR as it is (the version you approved), which also covers those attached tables.
Related: #127670
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
TSan reported a data race in
La Casa Del Dolor (amd_tsan)(report):MultipleFileWriter::consumereadsbuffer->count()between the blocks to compare it withiceberg_insert_max_bytes_in_data_file, while theParallelFormattingOutputFormatcollector thread writes the same data file buffer. The format was created withgetOutputFormatParallelIfPossible, so an IcebergINSERTin any row format with parallel formatting (RowBinary,CSV,TSV,JSONEachRow, ...) hit it. The count also lags by an unknown number of blocks, so the files ran past the limit. The Pretty formats render the blocks in a thread of their own after the input pauses (output_format_pretty_squash_consecutive_ms), so the limit did not cut their files. Both exist since #127670, which compares the limit withbuffer->count(), and are not in a release.The data file format is now created with
getOutputFormat, as the Iceberg compaction and mutation writers already do, withpretty.squash_consecutive_ms = 0, so every write into the buffer happens in the inserting thread before the next size check. Parquet, ORC and Avro do not support parallel formatting and take the same path as before. #127864 (Parquet parallel encoding) is independent; ORC and Vortex buffer inside the format, which is #128558.Validation: new test
05444_iceberg_insert_file_size_format_threads(RowBinaryandPrettyCompactarms). Without the fix, the TSan server aborts with the CI stack, and a debug build writes files of up to twice the limit and a singlePrettyCompactfile (10/10). With the fix: 50/50 randomized runs on debug, 20/20 on TSan with no report; each of the two lines is needed by its own arm.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129168]