Repository navigation
Merge Iceberg manifests on append - #128472
alexey-milovidov wants to merge 24 commits into
Conversation
Every `INSERT` into an Iceberg table adds new manifests and carries all the manifests of the parent snapshot forward, so their number grows with the number of inserts, and so does the startup cost of every query, which has to read all of them. Like the reference implementation's `MergeAppend`, an append now merges the small data manifests of the parent snapshot into fewer ones as part of the same commit. The data files are listed as EXISTING entries keeping their lineage, statistics and partition tuples, so no separate snapshot is created and no data is read. - The merge happens when the new snapshot would have more small data manifests than the table property `commit.manifest.min-count-to-merge`, or the `iceberg_manifest_min_count_to_compact` setting (default 100). - Merged manifests span partitions, ordered by partition so the manifest-list bounds stay narrow, and hold up to the entries that fit in `commit.manifest.target-size-bytes` (default 8 MiB). Manifests holding at least half of that are carried forward as they are, so a merge never rewrites large parts of the metadata again. - `commit.manifest-merge.enabled` = `false` disables it. It is done only for format version 2, and skipped for encrypted data files and partition values that cannot be written, so an `INSERT` never fails because of it. The collection and rewriting of data manifests is moved from `OPTIMIZE TABLE ... MANIFEST` into `DataManifestsRewriter`, shared by both. `OPTIMIZE` keeps writing one manifest per partition. The manifest-list partition summary is now a range, and `generateManifestFile` accepts per-file partition tuples. Related: #98178 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
…er manifests are merged - `ALTER TABLE ... DROP PARTITION` now rewrites a data manifest that also lists files of other partitions (e.g. one merged by an `INSERT`) without the dropped files, using `DataManifestsRewriter`, instead of throwing `NOT_IMPLEMENTED`. Partially matched delete manifests are still rejected. - Full `OPTIMIZE TABLE` rejects, before anything is written, a history where a data file is listed in several manifests (a merged one and the originals kept by older snapshots). It assigns each data file to its first manifest only, so it would drop the files from the other manifests and then delete the originals. - The merge on append also checks the resolved partition types with `canGetAvroType`, not only the `Field` carriers, so e.g. an old `fixed` identity partition skips the merge instead of failing the `INSERT` in `getAvroType`. The test covers `DROP PARTITION` and full `OPTIMIZE` after a merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/DataManifestsRewriter.cpp.o |
new | 667.67 KiB | +667.67 KiB |
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp.o |
1.34 MiB | 1.44 MiB | +105.10 KiB (+7.67%) |
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp.o |
1.14 MiB | 1.05 MiB | -84.77 KiB (-7.29%) |
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/AlterDropPartitionExecutor.cpp.o |
715.38 KiB | 739.45 KiB | +24.07 KiB (+3.36%) |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
60 translation units recompiled, 489 s compile time in total, 59 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Storages/ObjectStorage/DataLakes/Iceberg/DataManifestsRewriter.cpp: 8.2 s
…ite `Float32` partition values as Avro `float` - Full `OPTIMIZE TABLE` wrote one partition tuple per rewritten manifest, so a manifest listing data files of several partitions (a single Spark append, or manifests merged by an `INSERT` whose original snapshots have expired) got a wrong partition value for some files, breaking partition pruning and identity-column projection. It now passes the partition tuple of each data file to `generateManifestFile`. - `generateManifestFile` built a `double` datum for `Float32` partition values, which the Avro writer encodes as eight bytes where readers expect a four-byte `float`, corrupting the manifest written by a merge of manifests with a `float` identity partition. It now builds a `float` datum when the manifest schema field is `float`. - `test_drop_partition_shared_spark_manifest_is_rejected` pinned the old `NOT_IMPLEMENTED` rejection of `DROP PARTITION` on a manifest spanning partitions; this PR rewrites such manifests instead, so the test now checks the result and that Spark reads it. - New tests: merge, expire the original snapshots, position delete, full `OPTIMIZE`; and Spark `float`-partitioned manifests merged by a ClickHouse `INSERT` after the spec became unpartitioned. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=f657285adeae8109e0279123c0dbf6b29c37c2c5&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20targeted%29 PR: #128472 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reconcile with #128880 (single manifest per `INSERT`), which also introduced per-file partition tuples in `generateManifestFile` and a range partition summary: - Use master's `ManifestPartitionSummary` class and the required `per_file_partition_values` argument of `generateManifestFile`; drop this branch's duplicates of them. - Keep master's full-compaction handling of manifests spanning several partitions. - `OPTIMIZE TABLE ... MANIFEST` keeps using `DataManifestsRewriter`, with `Grouping::SpanPartitions` when `iceberg_insert_single_manifest_for_all_partitions` is set, as on master. - `ALTER TABLE ... DROP PARTITION` rewrites a manifest shared with other partitions (this branch), so the tests and the setting description that expected `NOT_IMPLEMENTED` for it are updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion sources `DataManifestsRewriter` derives the partition types from the ClickHouse types, which do not tell an Iceberg `binary` from a `string`, so a merged manifest would declare a `binary` partition value as Avro `string`. It also resolved the partition sources through `ChunkPartitioner`, which knows only the top-level columns, so an old spec partitioned by a nested column made the append-time merge throw `NOT_FOUND_COLUMN_IN_BLOCK` and fail the `INSERT`. Such specs are now reported by `hasUnsupportedPartitionValues`: the `INSERT` skips the merge, `DROP PARTITION` and `OPTIMIZE TABLE ... MANIFEST` throw `NOT_IMPLEMENTED` before writing anything. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=c989bf47d68d7a9cbfcbdb3d6ff5a51a1561ccd0&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 ( |
|
Acknowledged. No fix for this is in progress yet (no open PR touches |
|
The fix is in #129574. The failure is not about the test: under |
…anifest rewrites The shared `DataManifestsRewriter` (used by the merge of manifests on `INSERT`, `OPTIMIZE TABLE ... MANIFEST` and `ALTER TABLE ... DROP PARTITION`) declared the manifest partition fields and encoded the manifest-list partition bounds from the return types of the transform functions, which are not the Iceberg partition types: `icebergBucket` returns `UInt32`, which was written as Avro `long` with 8-byte bounds, while a bucket partition is an Iceberg `int`; a `uuid` identity partition was declared as `string` instead of `fixed[16]`. The partition types are now derived from the Iceberg types of the transform results: integer types are narrowed or widened to the Iceberg `int`/`long`, and a spec whose partition values cannot be written with the physical type the spec requires (e.g. `uuid`, `binary`, `fixed`) is not rewritten. Rewritten entries also lost their `split_offsets`; they are now carried over. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…flight partition transforms before reading manifests - Expiring snapshots with metadata cleanup can remove a schema from the metadata while live manifests are still written under it. `getSchemaObjectById` now takes such a schema from `IcebergSchemaProcessor`, where the manifest header registered it, and keeps preferring the authoritative copy in the metadata. - Reading a manifest instantiates the transform functions of its partition spec, and `ChunkPartitioner` does too. `icebergTruncate` rejects e.g. `truncate[10]` of a `decimal(20, 2)`, so an append failed with `ILLEGAL_TYPE_OF_ARGUMENT` when an old spec like that crossed the merge threshold. `collect` now checks the spec of each manifest first, and the manifests of an unsupported spec are kept as they are. `OPTIMIZE TABLE ... MANIFEST` reports such a table as unsupported rather than as having nothing to do. Both cases are covered by a Spark integration test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=7d3c4efb51731de1f1f13b27344be6f8e4645e81&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%206%2F6%29 ( |
|
Acknowledged. The flagged query is |
|
The #130581 makes |
…blished The check of the partition transforms before reading a manifest searched only top-level fields of the schemas of the metadata and accepted a spec when it did not find the source column. A source nested in a struct, or a dropped column whose schemas were expired, then reached `buildPartitionKeyFromSpec`, which instantiated `icebergTruncate` and threw. A spec whose source type cannot be established is now treated as unsupported (except for `void`). The manifests of an unsupported spec were also treated as empty when the manifest list reported zero live files, but the counts are optional in v1 manifest lists and a missing or null count is read as zero. The rewrite would then drop the data of such manifests from the snapshot. Now an unsupported manifest is only skipped when the statuses of its entries, which are read without the spec, show that it has no live entries. The integration test of the historical `truncate` of `decimal(20, 2)` is extended to a source nested in a struct. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/128472/66b011f8b82b06df7e21b1a0a441709b167bfcea/pr/ast_fuzzer_amd_release_oracle/job.log ( |
|
@groeneai, there was an outage, so this request may have been missed. Please take a look at #128472 (comment) |
|
@groeneai, a reminder about this request after the outage: #128472 (comment) |
|
The fix is #122966 (mine, open). This is the same query condition cache key collision: a lambda that captures a column is keyed by its signature, In this run's The same pair on a server (
#122966 got a master merge today to resolve a conflict in |
# Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
…ce column is gone The Iceberg spec allows a `void` partition field to reference a source column that was dropped later, and the schemas that defined it may be expired from the metadata. Such manifests are readable, but `DataManifestsRewriter::resolvePartitionSpec` threw `ICEBERG_SPECIFICATION_VIOLATION` because no schema defines the source, so an otherwise writable `INSERT` failed once it crossed the manifest merge threshold. Mark the spec as not rewritable instead, so the manifests are carried forward unchanged (and `OPTIMIZE ... MANIFEST` / `DROP PARTITION` report it as unsupported). Other missing source columns are still reported as an error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks, @groeneai. I agree the AST fuzzer oracle mismatch (query condition cache key collision for lambdas) is unrelated to this PR and is covered by #122966. The other red result, the |
…schema defines all its sources A historical spec such as `void(a), identity(b)` can reference sources that never coexisted in one schema (`a` dropped before `b` was added). The previous check only looked whether each `void` source exists in some schema, so it fell through to the `ICEBERG_SPECIFICATION_VIOLATION` exception. Now, if no schema defines all source columns of a spec that has a `void` field, the spec is marked as not rewritable and its manifests are kept unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ynchronous insert AsyncInsertQueueTransform held a materialized copy of the first block of an INSERT ... SELECT under async_insert (const, sparse and replicated columns converted to full). When a second block arrived, that copy was replayed into the synchronous fallback pipeline, so CountingTransform counted the first block at full size and Squashing, seeing chunks of different structures, materialized every chunk of the squashed block. For a wide table with sparse columns this wrote a full part and used about 6 times more memory. This is what fails 03237_insert_sparse_columns_mem in the AsyncInsert job with min_chunk_bytes_for_parallel_parsing = 171302: the first parsed segment is 4953 rows, small enough to be held, and the second insert reports 10165446 written bytes instead of about 340000. Hold the original chunk and materialize a copy only when the block is diverted to the queue. A block whose materialized size exceeds async_insert_max_data_size now falls back with the original chunks at the end of input, after the existing kill / timeout / cancel guard, which therefore covers both exits of a held block. The replay part of disqualify() is split out as fallBack(). The new test compares the bytes written by the async fallback with a plain synchronous INSERT ... SELECT of the same blocks. Its source table pins index_granularity: a granule of 20000 rows or more is read as one block, which the queue route diverts instead of falling back. Related: ClickHouse#128472 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t assert its route The previous commit moved materializeBlockInplace in getRemaining below the kill / timeout / cancel guard, so an O(block) expansion ran between the last check and the write. Materialize first and keep the guard right before both writes (the divert to the queue and the fallback of a block that is too large after materialization), as it was before. The rejected materialized copy is now released before the fallback runs. The test now also fails when its evidence is missing: it requires both query_log rows and the text_log line showing that the async query took the queue route and fell back there (async_insert_select_as_async_insert = 0 gives 0 for that line). Related: ClickHouse#128472 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
…under another partition spec Full compaction rewrites every data file under the default partition spec and reuses its partition tuple as is. The arity check let a file of another spec with the same number of fields through, e.g. `identity(a)` after the default spec changed to `identity(b)`, and the rewritten file then declared values of `a` as values of `b`, so partition pruning and identity-column projection could return wrong results. Now each data file must have the same source columns and transforms as the default spec, otherwise `OPTIMIZE` fails with `NOT_IMPLEMENTED` before anything is written. `test_optimize_position_delete_other_partition_spec` compacted an `identity(region)` file under `truncate(1, region)`, which only kept the right partition value by coincidence; it now expects the refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n_spec_of_another_source` Spark merged the manifests of the table, so a data file was listed in two manifests and `OPTIMIZE` was refused by the duplicate-manifest check before it reached the partition spec check the test is about. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes `clang-tidy` `modernize-use-nodiscard` in the `arm_tidy` build: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=latest&name_0=PR&name_1=Build%20%28arm_tidy%2C%202%2F4%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
…ests-on-append Conflicts in `Compaction.cpp` and `IcebergWrites.cpp` are unions of both sides: the manifest merge on `INSERT` and the partition-spec check of the compaction from this branch, the NDV table statistics and the new insert settings from master. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…anifest rewrite `icebergTruncate` of a `decimal(5, 2)` returns `Decimal(9, 2)`, the widest precision of the same carrier, and both are an Avro `fixed`, so `getManifestPartitionType` accepted the widened type and the merged manifest declared `decimal(9, 2)` in four bytes instead of the `decimal(5, 2)` in three bytes of the partition spec. The partition type of `identity` and `truncate` of a decimal is now built from the precision and scale of the Iceberg source type, and the spec is not rewritten if the transform returns another scale or carrier. Co-Authored-By: Claude Fable 5.2 <[email protected]>
# Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
…nifest rewrite `getManifestPartitionType` applied the decimal precision handling whenever the source column was a decimal, so for `bucket[N]` of a `decimal(P, S)`, whose result is an Iceberg `int`, it returned no type: the transform returns `UInt32`, which is not a decimal. Such manifests were never merged on `INSERT`, and they disabled the merge of the other candidates as well. Apply the precision handling only when the partition type is the decimal itself (the required Avro type is `fixed`), and let the `bucket` take the integer path. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged |
Related: #98178
Every
INSERTinto an Iceberg table adds new manifests and carries all the manifests of the parent snapshot forward, so the number of manifests grows with the number of inserts. Reading manifests is a large part of the work of every query, and for many small manifests it is pure startup delay and cost, while it is easy to avoid: manifests are small, so merging them is cheap.OPTIMIZE TABLE ... MANIFEST(#98178) does this only on request and as a separate snapshot.Like other Iceberg writers (
MergeAppendin the reference implementation),INSERTnow merges the small data manifests of the parent snapshot into fewer ones as part of the same commit, without any experimental setting. The newappendsnapshot lists the same data files as EXISTING entries keeping their snapshot ids, sequence numbers, statistics and partition tuples, so no data is read and no separate snapshot is created; older snapshots keep their own manifests.commit.manifest.min-count-to-merge, or, when it is not set, theiceberg_manifest_min_count_to_compactsetting (default100).commit.manifest.target-size-bytes(default 8 MiB). Manifests that already hold at least half of that are carried forward as they are, so the cost of a merge stays bounded.commit.manifest-merge.enabled=falsedisables it. It is done only for format version 2, and skipped (not failed) for encrypted data files and for partition values that cannot be written (includingbinaryand nested partition source columns); delete manifests are always carried forward unchanged.ALTER TABLE ... DROP PARTITIONrewrites a data manifest that also lists files of other partitions (such as a merged one) without the dropped files, instead of failing. The fullOPTIMIZE TABLEcompaction rejects, before writing anything, a history where a data file is listed in several manifests (a merged one and the originals kept by older snapshots).The collection and rewriting of data manifests moves from
OPTIMIZE TABLE ... MANIFESTinto a sharedDataManifestsRewriter;OPTIMIZEkeeps writing one manifest per partition, or one per partition spec and schema withiceberg_insert_single_manifest_for_all_partitions(#128880). The manifest-list partition summary as a range and per-file partition tuples ingenerateManifestFilecome from that PR. A manifest written with that setting can now also be handled byALTER TABLE ... DROP PARTITION.Related: #128880
Measurements {#measurements}
Workload:
CREATE TABLE t (k Int64, p Int64, s String) ENGINE = IcebergS3(<local MinIO>, 'Parquet') PARTITION BY p, then 300 separateINSERT INTO t SELECT number + i * 1000, i % 10, 'x' FROM numbers(100)from oneclickhouse localsession, then 11 runs ofSELECT count(), sum(k) FROM t WHERE p = 3withuse_iceberg_metadata_files_cache = 0(first run discarded). Merge enabled:iceberg_manifest_min_count_to_compact = 100(the default); merge disabled:iceberg_manifest_min_count_to_compact = 1000000. The same with 500 inserts on a local disk (IcebergLocal). The machine was shared (load average 40–90), so wall-clock times are noisy; request and byte counts are exact.SELECT: S3GetObjectper querySELECT: bytes read from S3 per querySELECT: median time, S3 (noisy)SELECT: median time, local diskGetObjectin totalPutObjectin totalWith merging, a query reads about half as many objects here (the manifest-list partition bounds already prune most manifests of other partitions; without them the difference grows linearly with the number of inserts), and the manifest lists written by every insert stay small. The cost on the insert side is about one extra
GetObjectper insert (the parent manifest list read to decide whether to merge) plus, once per ~100 inserts, reading and rewriting the small manifests; the total bytes moved per insert are slightly lower. The insert-latency difference on S3 is within the noise of the shared machine (the two enabled runs differ by 25%).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
INSERTinto an Iceberg table merges the small manifest files of the current snapshot within the same commit when there are more thancommit.manifest.min-count-to-merge(or theiceberg_manifest_min_count_to_compactsetting, 100 by default) of them, so the number of manifests a query has to read no longer grows with the number of inserts. The merge can be disabled with the table propertycommit.manifest-merge.enabled=false.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128472]