Repository navigation
Conversation
Data compaction used to rebuild the whole table: it rewrote every snapshot of the history from an empty metadata file and then deleted a raw listing of the table's files. That lost the table uuid, partition specs and properties, changed the content of committed snapshots, could not be committed through a catalog, and a second OPTIMIZE deleted the only metadata file. Now OPTIMIZE plans over the current snapshot only: every live data file with an applicable position delete (the rule SELECT uses) is rewritten without the deleted rows into the current schema, its untouched siblings in the same manifest are kept as EXISTING entries, unaffected manifests are carried forward, and the delete manifests are dropped. The result is committed as one replace snapshot through the catalog or as the next metadata file plus the version hint. Nothing is deleted at commit; expire_snapshots and remove_orphan_files reclaim the replaced files. The commit helper of manifest compaction is shared and now distinguishes a lost race (retry) from an unknown outcome (keep the files, throw UNKNOWN_STATUS_OF_TRANSACTION). Closes ClickHouse#123982 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The REST catalog test now expects OPTIMIZE to commit a replace snapshot through the catalog. New arms: a commit race retried on top of the winning INSERT (failpoint), an identity-partition column materialized into the rewritten file, and rewritten files written to write.data.path. test_optimize's time travel now expects the rows the earlier snapshot committed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…outcome Two writers racing for the same `vN.metadata.json` usually both pass the existence check, so the loser's create-only write is rejected (S3/MinIO `PreconditionFailed`, local `FILE_ALREADY_EXISTS` from `link`, the Azure condition error) and the primitive reported `WriteFailed`. Compaction maps `WriteFailed` to an unknown outcome and throws `UNKNOWN_STATUS_OF_TRANSACTION`, so concurrent `OPTIMIZE ... MANIFEST` on S3 failed instead of retrying (`test_optimize_manifest_files_partitioned_concurrent[s3]`: 5 of 8 runs). `writeMetadataFileAndVersionHintWithOutcome` now reads the target back once, bypassing caches, after a failed write. Bytes other than ours prove a lost race (`TargetExisted`): the write is create-only, so no request of ours can land on that name any more, and another writer's bytes never equal ours because they carry a different snapshot id. An absent or unreadable target, or our own bytes (an unproven replay of a write that landed), stay `WriteFailed`, so the files of a commit that may be published are never removed. The `bool` wrapper used by INSERT, mutations, DROP PARTITION and `expire_snapshots` does not read back, so their results and I/O are unchanged. Both compactions now initialize their commit outcome to `Unknown`, the value that keeps the files (clang-tidy `cppcoreguidelines-init-variables`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…keep row order A REST catalog's 409 does not prove that none of our requests applied: `ReadWriteBufferFromHTTP` re-sends the commit POST after a network error and after any 5xx, and when the first POST landed and its answer was lost, the re-sent one fails `assert-ref-snapshot-id`. Both compactions treated the 409 as a conflict and removed the files of the snapshot that had just been committed. A rejection is now checked against the catalog's current metadata: our snapshot present -> committed; main moved past our parent -> conflict (every request of ours asserts `main == parent`, so none can apply any more); anything else, or a failure of the check itself -> unknown, files kept. Glue's `UpdateTable` is unconditional and the file CAS only guards our own `vN+1` name, so a writer that names metadata differently could commit during the rewrite and be overwritten. The catalog pointer is now compared with the one the attempt was planned on right before anything is written. The source of a rewrite is read with `parquet.preserve_order`, since the new data file keeps the source's `sort_order_id` and read-in-order trusts it. Smaller: `UNSUPPORTED_METHOD` from the metadata write (raised before anything is written) is rethrown with this OPTIMIZE's files removed instead of being reported as an unknown outcome; the rewrite reuse key is a tuple instead of a joined string that two delete sets could collide in; the rewritten file's size lookup runs inside the scope that removes the file on failure. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…roof After a REST 409 the catalog's current metadata was read as "not applied" whenever our snapshot was absent and main had moved. An applied snapshot can already be expired by then while a descendant built on it is retained, and the cleanup that follows a conflict then deletes files that descendant reads. Now the rejection is resolved against the retained snapshots: ours, or a snapshot whose parent is ours, means some attempt was applied (Committed); a conflict is reported only when main's retained lineage reaches our parent through another snapshot; anything else (an expired link in the chain, no current snapshot) stays Unknown and keeps every file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… numbers
After a REST 409, a rejection whose snapshot is absent was still read as a
conflict when main's retained lineage reached our parent through another
snapshot. That is not proof: if the first POST was applied, another writer
can build a child and a grandchild on ours, keep the grandchild on a branch
or tag, reset main through a foreign child of our parent and expire ours and
the child. The verifier then saw a conflict and the cleanup deleted files the
retained grandchild still reads.
Iceberg snapshot sequence numbers increase monotonically ("a monotonically
increasing long that tracks the order of changes to a table"), so every
descendant of ours has a sequence number greater than ours, and a snapshot
with a sequence number at or below ours is not one. The verifier now walks
each retained snapshot towards its root while its sequence number is above
ours; if the walk meets a parent that is not retained, that snapshot may
descend from ours and the outcome is Unknown, every file kept. Lineages that
lose a link at or below our sequence number do not block the conflict check,
which is otherwise unchanged. This holds for any interleaving of ref resets,
branches and expiries.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…snapshot sequence number as 0 Data compaction drops the delete manifests of the current snapshot, so the equality-delete refusal is the only thing that keeps equality-deleted rows from coming back. 05325 now runs OPTIMIZE on the shared `deletes_db/eq_deletes_table` fixture and checks NOT_IMPLEMENTED, an unchanged history and the 881 live rows. After a rejected REST commit the verifier read every retained snapshot's `sequence-number` with `getValue`. A table upgraded from v1 keeps snapshots without it, so the read threw and every rejection became UNKNOWN_STATUS. Such snapshots now read as 0, the value Iceberg readers default to: they are older than ours, and a descendant of ours is a v2 snapshot that carries the field. Comments in 04815 and the history-summary integration test no longer describe the removed history replay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The history-summary integration test explained its fixture with checkIfIcebergHistorySupported, which this branch removes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Compaction.cpp: drop the narration of the manifest regrouping loop and shorten the totals comment to its invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model plus my own review (engine: codex; 5 rounds, 21 findings).
Severity: ❌ blocker / Bounce cap reached, published as-is: the last fix round (936b487, one test comment) was checked by my own review only, without another independent-model run. Rows 9, 10, 12 and 13 are noted, not blocking. Session id: cron:clickhouse-review-slot-11:20261006-001900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261005-215800 |
|
Workflow [PR], commit [cf80b1d] Summary: ✅
AI ReviewSummaryPR #124114, reviewed at Consumers of the new Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum action: make Glue publication conditional on the planned catalog version, or keep Glue compaction unsupported. The existing discussion was not reopened. |
The compaction section claimed support for Iceberg tables without naming the refusals in the data-compaction path: any format-version other than 2 (BAD_ARGUMENTS; this also covers deletion vectors, a v3 feature), equality delete files in the current snapshot, and per-file key_metadata in a data manifest that has to be rewritten (both NOT_IMPLEMENTED). "Catalog-backed" is narrowed to catalogs ClickHouse can INSERT into: the commit goes through ICatalog::updateMetadata like INSERT, and only the REST-derived, Glue and Unity v2 catalogs implement it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes27 object files changed (+33.87 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units122 translation units recompiled, 1202 s compile time in total, 122 of them have a recent master baseline. Symbol sizes
|
CI finish ledger - cd2a1b1Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no Session id: cron:our-pr-ci-monitor:20261006-073316 |
…publish-repair Conflicts resolved: - Compaction.cpp: this branch's version. Master's changes there (the next-version commit, the version-hint retention and the field-id read mapper of data compaction) sit in code this branch replaces; the rewrite already reads through `getColumnMapperById`, which carries the time field ids and the last assigned field id. - MetadataGenerator: `generateNextMetadata` takes master's `removals`, then `precomputed_summary`; compaction passes no removals. - Utils: `writeMetadataFileAndVersionHintWithOutcome` is built on master's `writeMetadataFile` / `tryWriteVersionHintFile` split and keeps the refused-write rule. - gtest_iceberg_commit_propagation.cpp: master's stub, extended so a failed write can leave content that `readObject` serves. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion test `OPTIMIZE TABLE` now rewrites only the data files that position deletes apply to and keeps the others. With one deleted row, two of the three pyiceberg files were kept, so the check that every row is read from a file written by `OPTIMIZE` failed. Deleting one row from each file keeps that check. With the compaction read stripped of its field-id mapper the test fails on every row (seconds instead of microseconds). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ummary The `replace` snapshot of data compaction copied every extra field of the parent's summary, so compacting a snapshot written by Spark kept Spark's `engine-name`, `engine-version`, `app-id` and `spark.app.id`. Those fields describe the write that produced the parent. The refresh cursor is the only extra field every snapshot must carry forward (the rule `generateNextMetadata` applies), so only it is kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An incremental refreshable materialized view resumes from the cursor in the latest snapshot's summary. Compact the target after the first refresh and check that the `replace` snapshot carries the cursor and that the refresh after a restart appends only the new rows. With the cursor dropped by compaction the new arm fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…snapshot The Iceberg spec allows JSON null for a table without a current snapshot, and SELECT, INSERT and mutations already read it that way. The compaction planner called `getValue<Int64>` on the null and failed with `Invalid access: Can not convert empty value`; it now takes the no-snapshot path and commits nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The replace snapshot listed only the rewritten files, so the data files it replaced and the position delete files it applied vanished from the manifests. Iceberg's Java writer validates a concurrent commit against the DELETED entries of the snapshots committed since it planned (MergingSnapshotProducer.validateDataFilesExist), so a position delete planned against a file that OPTIMIZE then replaced still committed, and was lost: its rows live on in the rewritten file. Incremental snapshot expiration relies on the same entries to reclaim the replaced files. Every replaced source, including one with no surviving rows, and every removed position delete file is now a DELETED entry of the new snapshot that keeps its data and file sequence numbers, and the manifest list carries the matching deleted_files_count and deleted_rows_count. ClickHouse readers skip DELETED entries, so SELECT, expire_snapshots and remove_orphan_files see the same files as before. Measured with Spark 4.0 and Iceberg 1.11: a RowDelta staged against a replaced file before OPTIMIZE committed on the previous head, and is now rejected with "Cannot commit, missing data files". Co-Authored-By: Claude Opus 5.5 <[email protected]>
…publish-repair
Conflicts:
- Compaction.cpp: the PR's version, with master's changes to the code it keeps:
the rewrite read asks the format for row numbers (the position delete transform
needs them, formats attach them only on request now); the metadata object is
deep-copied before MetadataGenerator mutates it (metadata.json is cached and
shared now); a group keeps one partition tuple per file and the manifest list
gets a ManifestPartitionSummary, and OPTIMIZE ... MANIFEST groups by partition
value only without iceberg_insert_single_manifest_for_all_partitions; the
existing-entry statistics carry NaN counts (master's getColumnStatisticsForRewrite
and getEntryLineageForRewrite are reused). Master's changes to the code this PR
replaces (getPlan, writeDataFiles, writeMetadataFiles, getOldFiles) are dropped.
- IcebergIterator.{h,cpp}: DataFileEntriesStream is gone on master and
defineDeletesSpan moved to ManifestFile.h; only positionDeleteMayReferenceDataFile
stays here.
- IcebergMetadata.cpp: updateLastColumnId is gone on master.
- Utils.cpp: master's concurrent-write debug log in writeMetadataFileWithOutcome.
- StorageObjectStorageSource.h, test_optimize.py: both sides kept.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
05325 gets the reproducers of ClickHouse#123282 (an earlier schema must not become the schema of the rewritten files) and ClickHouse#123909 (rows of a dropped partition must not come back). Both fail on master: `-1294967296 Int32`, and `[2,3]` with the dropped row back. 05483 (from master) expected master's OPTIMIZE, which rewrites every snapshot. Here the earlier snapshots keep their totals and the one `replace` snapshot has the totals of its live files, so the expected arrays list them all; the trivial count, the size check and the reads per delete file are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A manifest group checked for a duplicate path with a linear scan of the paths already in the group, which makes collecting n files O(n^2). Master's OPTIMIZE ... MANIFEST used a per-group unordered_set before the groups were shared with data compaction; restore it for both the existing-entry and the rewritten-file insertions. Same equality as before: IcebergPathFromMetadata compares and hashes its raw path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
05401 (from master) asserted master's OPTIMIZE, which deletes a listing of data/ after rewriting the table. Here OPTIMIZE commits a replace snapshot and deletes nothing: the earlier snapshots still reference the replaced files and expire_snapshots reclaims them. The OPTIMIZE section now checks that every data file listed before OPTIMIZE is still there; it prints 0 on master (the files are deleted) and 1 here. The strays outside the table directories are still checked to survive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#128600 a metadata file of a catalog-backed table is named `<N>-<uuid>.metadata.json` with the UUID derived from the base metadata file, and `FileNamesGenerator` throws LOGICAL_ERROR when that base is not set. The data compaction commit still called `setVersion`, so OPTIMIZE on a table in a REST catalog aborted the server (test_database_iceberg in Integration tests (amd_asan_ubsan, flaky)). Use the same generator setup as the other writers after ClickHouse#128600: UUID names for every catalog-backed table and `setBaseMetadataFile` with the metadata file the plan was read from. A non-transactional catalog (Glue) now also gets the deterministic name, so two writers committing on the same base collide on it and the loser retries, as for INSERT. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Data compaction already reads `"current-snapshot-id": null` as "no current snapshot", but the manifest compaction pre-check and `writeConsolidatedManifestFile` still called `getValue<Int64>` on it, so `OPTIMIZE TABLE t MANIFEST` on such a table failed with POCO_EXCEPTION `Invalid access: Can not convert empty value` (also on master, where data compaction fails the same way). All three sites now share one null-aware lookup, and the 05325 null case also runs the MANIFEST mode and checks that no metadata is published. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
OPTIMIZE TABLEon an Iceberg table (allow_experimental_iceberg_compaction) now commits onereplacesnapshot on top of the current one, merging position deletes into the data files they apply to. Earlier snapshots, the table UUID, partition specs and properties stay as they were, nothing is deleted at commit time (expire_snapshotsreclaims the replaced files), and tables in catalogs that ClickHouse canINSERTinto and tables read throughiceberg_use_version_hintcan now be compacted.Description
Closes #123982. Data compaction rebuilt the table: it replayed every retained snapshot into a new metadata file, always named
v0.metadata.json, and then deleted a listing ofmetadata/anddata/taken before the write. So a secondOPTIMIZEleft no metadata file, time travel to a committed snapshot returned other rows, and a catalog could not express the commit.Now compaction plans over the current snapshot only. Each data file with applicable position deletes is rewritten into the current schema with SELECT's read chain; the replaced files stay as
DELETEDentries for writers that validate concurrent commits. Other manifests are carried forward, and the snapshot is committed likeOPTIMIZE ... MANIFEST: metadata-file CAS plus version hint, or the catalog. Glue cannot reject a concurrent commit, so its pointer is re-read just before the swap; if it moved, compaction retries. A lost race is retried on top of the winner; after a failed metadata write the file is read back, and another writer's bytes mean a lost race. Any other failure keeps every file and throwsUNKNOWN_STATUS_OF_TRANSACTION, forOPTIMIZE ... MANIFESTtoo (it used to delete the manifests of a commit that may have landed). A nullcurrent-snapshot-idnow means no current snapshot, as for SELECT.The diff is big because a catalog can only add a snapshot on top of the current one, so no patch of the rewrite could reach catalogs.
Overlaps: merged #122833, #116941 and #128759 patched the removed rewrite, and their cases hold here; #110069 and #121500 patch it too. #115390 reconciles failed writes for every writer; this PR adds only the lost-race case.
Tests: new
05325_iceberg_optimize_replace_snapshot(every arm fails on master, including the reproducers of #123282 and #123909);05483and05401now expect the earlier snapshots to keep their totals and files; integration and unit tests.Workflow [PR]
Sync PR [sync-upstream/pr/124114]