Repository navigation
Fix Iceberg data file size limit when Parquet encodes in parallel - #127864
seva-potapov wants to merge 3 commits into
Conversation
|
Workflow [PR], commit [5a90477] Summary: ✅
AI ReviewSummaryThe 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
Tests
Missing context / blind spots
Final Verdict |
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
3b456fd to
190a39b
Compare
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 units99 translation units recompiled, 578 s compile time in total, 99 of them have a recent master baseline. |
| } | ||
| } | ||
|
|
||
| void ParquetBlockOutputFormat::writePendingDataImpl() |
There was a problem hiding this comment.
Why don't we write staging_chunks here?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
[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.
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 thaniceberg_insert_max_bytes_in_data_file, differently on every run (repro in the issue).Now
MultipleFileWriterwaits 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 withoutput_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):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/127864]