Skip to content

Fix Iceberg data file size limit when Parquet encodes in parallel - #127864

Open
seva-potapov wants to merge 3 commits into
ClickHouse:masterfrom
seva-potapov:fix/127862-iceberg-file-size-parallel-encoding
Open

seva-potapov wants to merge 3 commits into
ClickHouse:masterfrom
seva-potapov:fix/127862-iceberg-file-size-parallel-encoding

Conversation

@seva-potapov

@seva-potapov seva-potapov commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #127862
Related: #127670

Since #127670, the size of an Iceberg data file is compared against the bytes already written to it. With output_format_parquet_parallel_encoding (the default), a row group reaches the file only once its background encoding finishes. So the check lagged behind, and files came out several times larger than iceberg_insert_max_bytes_in_data_file, differently on every run (repro in the issue).

Now MultipleFileWriter waits for the pending row groups when they could make the file reach the limit, so for most data the file is cut at the same row group as with output_format_parquet_parallel_encoding = 0, and nothing waits while the file is far from the limit. The pending size is estimated by memory, which is not an upper bound: a column that encodes bigger, e.g. many distinct values in a dictionary, can still push a file past the limit, by at most the row groups in flight. Exact cuts would mean always waiting, which leaves one row group in flight, encoded in parallel only across its columns.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...


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

@clickhouse-gh

clickhouse-gh Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5a90477]

Summary: ✅


AI Review

Summary

The change drains pending parallel Parquet encoding before an Iceberg file-size check when its memory estimate could reach the target. The documented estimate-based overshoot is an accepted tradeoff from the prior discussion. Request changes for a separate performance concern: byte-sized row groups can force a full drain while the compressed file remains far below its target.

Findings

⚠️ Majors

  • MultipleFileWriter.cpp:106–107: startNewFile caps the row group's input byte target at the file-size target. An unfinished group that fills this cap can therefore trigger writePendingData before any rows of the next group are accepted, even when compression makes its output much smaller. For an encoder-bound insert, this removes concurrency across row groups and restricts encoding to one group's columns. This also occurs with default byte targets for sufficiently wide rows. Preserve bounded overlap for compressible groups, or demonstrate an acceptable throughput cost with before/after measurements. The pipeline stall follows from the code; its throughput impact is not measured.
Tests
  • ⚠️ Measure a two-column, compressible Iceberg insert with max_threads = 8, max_insert_threads = 1, a raised iceberg_insert_max_rows_in_data_file, and row groups that reach the file's byte target. Compare throughput and file sizes before/after. The added regression case uses 100-row groups of incompressible data and does not exercise this performance risk.
Missing context / blind spots
  • ⚠️ No local ClickHouse binary/build is available. The current-head targeted CI report returned no test results, so execution of 05444_iceberg_insert_file_size_compressed could not be confirmed. A completed targeted report would close the regression-test execution gap.
Final Verdict

⚠️ Request changes. Preserve overlap for byte-sized compressible row groups, or supply focused before/after evidence that the throughput cost is acceptable, and confirm the regression test passes.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 26, 2026
@seva-potapov seva-potapov added the can be tested Allows running workflows for external contributors label Oct 26, 2026
With `output_format_parquet_parallel_encoding`, the Parquet writer writes a row group
to the file only after it has been encoded in a background thread, so the size that
`MultipleFileWriter` compared against `iceberg_insert_max_bytes_in_data_file` lagged
behind and the files came out several times larger than the limit, differently on
every run. Wait for the pending row groups when they can make the file reach the limit.

Fixes ClickHouse#127862
@seva-potapov
seva-potapov force-pushed the fix/127862-iceberg-file-size-parallel-encoding branch from 3b456fd to 190a39b Compare October 26, 2026 17:23
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5a904775a with master cb2cbd899 (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.66 (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 13.0 s +9.5 s (+269%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.3 s +5.3 s (+263%)
Compile time of recompiled translation units

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

Job report

}
}

void ParquetBlockOutputFormat::writePendingDataImpl()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't we write staging_chunks here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

staging_chunks is the next row group, still being collected. Writing it here would cut that row group short, which output_format_parquet_parallel_encoding = 0 never does for the size limit either. It wouldn't make the cut more exact: if the file is cut, finalizeImpl writes staging_chunks as its last row group anyway, and if it isn't (common for compressible data, because the bytes in flight are estimated by memory), it would only leave a small row group in the middle of the file. Also, it is normally empty here: the bytes in flight grow only when consume submits a row group, which empties the staging, and MultipleFileWriter checks before it writes the next chunk.

/// exceed the limit, by at most the row groups in flight. Always waiting would be exact, but would leave one row
/// group in flight, encoded in parallel only across its columns.
if (output_format && buffer->count() + output_format->getPendingDataBytes() >= max_data_file_num_bytes)
output_format->writePendingData();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve overlap when a row group's input reaches the file target

startNewFile caps parquet.row_group_bytes at max_data_file_num_bytes. Consequently, when a row group fills that byte cap, its unfinished input alone can make this condition true, even if compression will shrink it far below the file target. The next consume then waits for the entire group before accepting any of the next group's rows. For example, with a two-column table, an 8 MiB file target, the default row-group settings, and compressible strings, a still-encoding 8 MiB input group forces a drain while the file can contain much less than 8 MiB. The same situation occurs at the default 512 MiB target with sufficiently wide rows.

For an encoder-bound insert this removes overlap across row groups and limits encoding to the columns in one group, precisely the parallelism loss the description intends to avoid. The new 100-row, incompressible case does not exercise this path. Please preserve bounded overlap for compressible groups, or provide before/after throughput measurements for this case to establish that the cost is acceptable; the size of the regression has not been measured here.

@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 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg INSERT doesn't cut data files at iceberg_insert_max_bytes_in_data_file when Parquet encodes in parallel (regression from #127670)

2 participants