Skip to content

Fix data race in Iceberg insert with a text data file format - #131515

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-iceberg-writer-parallel-formatting-race
Nov 14, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-iceberg-writer-parallel-formatting-race

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

MultipleFileWriter created the output format of an Iceberg data file with getOutputFormatParallelIfPossible. For a text format such as JSON or CSV, that is ParallelFormattingOutputFormat, whose collector thread writes to the data file buffer while consume reads buffer->count() to decide where to cut the file, a check added in #127670. TSan reports it as a data race (BufferBase::count in MultipleFileWriter::consume vs WriteBuffer::next in ParallelFormattingOutputFormat::collectorThreadFunction). The non-parallel output format is used now; the Iceberg data file formats are not formatted in parallel anyway (the Parquet writer encodes row groups in parallel itself and writes them on the calling thread).

The new test inserts into a JSONEachRow Iceberg table with parallel formatting and a small file size limit, so that the files are cut while formatting.

Found by La Casa Del Dolor (amd_tsan), STID 1003-46d8, master, 2026-11-13: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=c1e69ea54ad361a685f9791174c1f7d22409ad2b&name_0=MasterCI&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29

Related: #127670
Related: #127864

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a data race when inserting into an Iceberg table whose data files have a text format, such as JSON.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131515]

Version info

  • Merged into: 26.11.1.2300-master (included in 26.11 and later)

alexey-milovidov and others added 2 commits November 13, 2026 23:17
`MultipleFileWriter` created the output format with
`getOutputFormatParallelIfPossible`. For a text format such as `JSON`,
that is `ParallelFormattingOutputFormat`, whose collector thread writes
to the data file buffer while `consume` reads `buffer->count()` to cut
the file (since #127670):
a data race reported by TSan. Use the non-parallel output format; the
Iceberg data file formats are not formatted in parallel anyway.

La Casa Del Dolor (amd_tsan), STID 1003-46d8, master, 2026-11-13:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=c1e69ea54ad361a685f9791174c1f7d22409ad2b&name_0=MasterCI&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d9ee3fd]

Summary: ✅


AI Review

Summary

Reviewed #131515 at d9ee3fd7d93f2eae282c94794fcf0c4c584ebbcc, including the diff, current code, prior discussion, and original TSan report. The change makes text-format writes synchronous in MultipleFileWriter, removing concurrent access to its output buffer during file-size checks. The regression test checks data integrity and file rollover with parallel formatting enabled. No actionable findings.

Missing context / blind spots
  • ⚠️ Runtime validation was unavailable: this checkout has no ClickHouse binary/build, and the fetched PR reports contain no completed targeted stateless/TSan results for the new test. Running 05632_iceberg_insert_text_format_file_cut under TSan would confirm the regression coverage.
Final Verdict

Status: ✅ Approve. No code changes requested; normal CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d9ee3fd7d with master cb1a0d516 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.61, programs/clickhouse-keeper ×0.64 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 12.6 s +9.1 s (+258%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.2 s +5.2 s (+253%)
Compile time of recompiled translation units

7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 14, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Nov 14, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 14, 2026
Merged via the queue into master with commit 60f1aaa Nov 14, 2026
208 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-iceberg-writer-parallel-formatting-race branch November 14, 2026 12:27
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 14, 2026
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants