Repository navigation
Cut Iceberg data files by their compressed size - #127670
Conversation
`MultipleFileWriter` compared `iceberg_insert_max_bytes_in_data_file` and `iceberg_compaction_max_bytes_in_data_file` against the uncompressed size of the chunks written to the current file, while the compaction selects its input files by their compressed size (`file_size_in_bytes`). When the compression ratio of the data is above `max_bytes / lower_threshold` (1.33 with the defaults), every output file of the compaction stays below `iceberg_data_file_size_lower_threshold_compaction`, so the compaction selects it again and rewrites the same data forever. Now the limit is compared against the bytes written to the current file so far, the same measure as `file_size_in_bytes`, and the meaning of the Iceberg property `write.target-file-size-bytes`. A file can exceed the limit by what the output format still buffers (incomplete Parquet row groups and the ones being encoded), which keeps it above the lower threshold. ClickHouse/clickhouse-private#83527 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [7c9c375] Summary: ✅
AI ReviewSummaryThe PR changes Iceberg data-file rollover to count compressed bytes and adds an insert regression test. The change addresses undersized output, but buffered Parquet row groups can instead produce oversized files that remain eligible for compaction. Request changes to establish convergence across both size thresholds. Missing context / blind spots
Findings
Tests
Final Verdict |
| /// Comparing it against the uncompressed size makes the files smaller than the target by the compression ratio, | ||
| /// and the output of the compaction is selected by the compaction again. The file can exceed the limit | ||
| /// by what the output format has not written yet: an incomplete Parquet row group and the row groups being encoded. | ||
| if (!current_file_num_rows || *current_file_num_rows >= max_data_file_num_rows || buffer->count() >= max_data_file_num_bytes) |
There was a problem hiding this comment.
This can replace the small-file rewrite loop with an oversized-file rewrite loop. With the defaults, output_format_parquet_row_group_size_bytes is 512 MiB, the target is 512 MiB, and iceberg_data_file_size_upper_threshold_compaction is about 921.6 MiB. If each row group encodes to 480 MiB, the first group leaves buffer->count() below the target, so the second is accepted and the result is at least 960 MiB: eligible for compaction again. Rewriting it with the same row-group boundaries need not reduce its size. This is possible even with synchronous encoding; with parallel encoding, completed groups are only reaped inside ParquetBlockOutputFormat::consume, after this check, and additional groups can already be queued. IOutputFormat::flush does not drain them.
Please bound row-group/in-flight output relative to the target and upper threshold, or ensure the planner does not repeatedly select these unavoidable oversized outputs. Add a focused compaction regression with lightly compressible data and normal row-group/parallel settings that verifies the resulting files are not immediately selected again. The added test forces 100-row groups and disables parallel encoding, so it does not establish convergence under the default settings.
There was a problem hiding this comment.
It's a different matter.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units18 translation units recompiled, 156 s compile time in total, 18 of them have a recent master baseline. |
|
@alexey-milovidov a measurement on this change: with default Parquet settings the size limit barely applies, because SET allow_experimental_insert_into_iceberg = 1, max_insert_threads = 1,
iceberg_insert_max_rows_in_data_file = 1000000000, iceberg_insert_max_bytes_in_data_file = 2816000;
CREATE TABLE t (id Int64, s String) ENGINE = IcebergLocal('/tmp/lake/t', 'Parquet');
INSERT INTO t SELECT number, toString(number) FROM numbers(32000000);
SELECT count(), max(file_size_in_bytes) FROM system.iceberg_files WHERE table = 't' AND content = 0;
Two things are not in
Which one do you prefer?
I can make the PR for A or B. |
Since `MultipleFileWriter` compares `iceberg_insert_max_bytes_in_data_file` and `iceberg_compaction_max_bytes_in_data_file` with the bytes written to the file, the limit was ignored for files smaller than a Parquet row group: the writer writes a row group only when it is complete, and the default `output_format_parquet_row_group_size_bytes` is 512 MiB before compression, so the size of such a file stayed near zero until it was finished. An insert of 16 MiB with a limit of 1 MiB wrote a single file of 14 MB, and the Iceberg compaction no longer split a file above the upper threshold. The row groups are now not bigger than the limit. Caused by: ClickHouse#127670 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`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 ClickHouse#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]>
MultipleFileWritercomparediceberg_insert_max_bytes_in_data_fileandiceberg_compaction_max_bytes_in_data_fileagainst the uncompressed size of the chunks written to the current file, while the compaction selects its input files by their compressed size (file_size_in_bytes) belowiceberg_data_file_size_lower_threshold_compaction. When the compression ratio of the data is abovemax_bytes / lower_threshold(1.33 with the defaults, so almost any real data), every output file of the compaction stays below the lower threshold, is selected again, and the compaction rewrites the same data forever without making the files larger.Now the limit is compared against the bytes written to the current file so far (
buffer->count()), the same measure asfile_size_in_bytesand the meaning of the Iceberg propertywrite.target-file-size-bytes. A file can exceed the limit by what the output format still buffers (incomplete Parquet row groups and the ones being encoded), which keeps it above the lower threshold, so it is not selected again. The same writer is used byINSERT, so inserted and compacted files are measured the same way.Closes: https://github.com/ClickHouse/clickhouse-private/issues/83527
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The settings
iceberg_insert_max_bytes_in_data_fileandiceberg_compaction_max_bytes_in_data_filenow limit the compressed size of a data file, as written to the storage, instead of the uncompressed size of the data. This is consistent with the Iceberg propertywrite.target-file-size-bytesand withiceberg_data_file_size_lower_threshold_compaction, and fixes the Iceberg compaction endlessly rewriting files that compress well.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127670]
Version info
26.11.1.724-master(included in26.11and later)