Repository navigation
Conversation
…ata rebuild When Iceberg metadata is recreated from scratch (no base metadata file: first snapshot after enabling the compatibility, metadata directory deleted or expired, or an Iceberg format-version change), createMetadataWithoutBase hardcoded the snapshot summary operation to "append" even when the triggering Paimon snapshot was a COMPACT or OVERWRITE commit. The with-base path already derives REPLACE/OVERWRITE from the commit kind, so the two paths disagreed: incremental Iceberg readers that key off the operation replay a full rebuilt snapshot as newly appended data and see duplicated rows. Derive the operation from paimonSnapshot.commitKind() in the rebuild path as well, mirroring createWithDeleteManifestFileMetas.
The rebuild test only pinned COMPACT -> "replace". Add an overwrite case asserting that an overwrite commit rebuilds the metadata with the "overwrite" operation, an append case pinning the "append" default of the first without-base export, and an existence check that the metadata wipe really removed the directory so the with-base path cannot silently cover the rebuild.
JingsongLi
left a comment
There was a problem hiding this comment.
I verified both cases against the merge base using Iceberg's incremental append scan.
| // the full table must do the same, or incremental consumers replay it as new data | ||
| String operation = IcebergSnapshotSummary.APPEND.operation(); | ||
| if (paimonSnapshot.commitKind() == Snapshot.CommitKind.COMPACT) { | ||
| operation = IcebergSnapshotSummary.REPLACE.operation(); |
There was a problem hiding this comment.
On a primary-key table with deletion vectors disabled, publish an empty Iceberg snapshot, append rows that stay in L0, delete the Iceberg metadata directory, and run a full compaction. The rebuilt snapshot exposes the new rows in a full scan. An incremental append scan using fromSnapshotExclusive(previousSnapshotId) skips them because the snapshot is marked replace. Reserve replace for compactions that preserve the Iceberg-visible row set. If the prior Iceberg state is unavailable, make the rebuild require a full resync.
There was a problem hiding this comment.
Addressed in 863101c. The rebuild no longer describes itself as an incremental delta at all: createMetadataWithoutBase now publishes the full export as an append snapshot with no parent, so a metadata rebuild starts a new Iceberg snapshot history. A reader holding a pre-rebuild checkpoint gets Iceberg's own ancestor validation instead of silently skipped rows — newIncrementalAppendScan().fromSnapshotExclusive(oldCheckpoint) throws IllegalArgumentException ("... not a parent ancestor ...") and the reader must resync from a full scan. This also retires the commit-kind-derived replace/overwrite marking from the previous revision, which as you demonstrated would have hidden the L0 rows from the incremental scan.
testWithoutBaseRebuildRequiresIncrementalResync reproduces your exact sequence with the Iceberg client (primary-key table, deletion vectors disabled, empty Iceberg snapshot, L0 appends, metadata wipe asserted, full compaction): the full scan still returns all rows, the rebuilt snapshot has a null parent, and both pre-rebuild checkpoints are rejected. Red on the previous head: the same test did not raise on fromSnapshotExclusive(previousHead). Green: IcebergCompatibilityTest 65/65.
| if (paimonSnapshot.commitKind() == Snapshot.CommitKind.COMPACT) { | ||
| operation = IcebergSnapshotSummary.REPLACE.operation(); | ||
| } else if (paimonSnapshot.commitKind() == Snapshot.CommitKind.OVERWRITE) { | ||
| operation = IcebergSnapshotSummary.OVERWRITE.operation(); |
There was a problem hiding this comment.
On a new append table with Iceberg publishing enabled, use INSERT OVERWRITE for the first write. The Iceberg snapshot has no parent and only adds data files. Marking it overwrite makes newIncrementalAppendScan() skip the inserted rows. Keep append for the initial snapshot when it only adds data files.
There was a problem hiding this comment.
Addressed in the same commit: a full export always publishes as append, including when the first Paimon write is an INSERT OVERWRITE, so an initial snapshot that only adds data files stays readable by newIncrementalAppendScan. testInitialIcebergSnapshotCanBeReadAsAppend covers both a plain first insert and a first overwrite and verifies with the Iceberg client that the incremental append scan plans the inserted files (record count asserted). Red on the previous head (overwrite operation): the overwrite variant found no files in the incremental scan. The resync requirement is documented in docs/docs/iceberg/index.md.
A full export cannot serve as an incremental delta from a missing parent. Publish it without a parent so a reader with an old checkpoint must resync. Preserve append semantics for an initial export, including a first overwrite, and verify both behaviors with the Iceberg client.
Purpose
An Iceberg metadata rebuild exports the complete current file set. The rebuilt snapshot used to claim the preceding Paimon snapshot ID as its Iceberg parent even though the rebuilt metadata contains no prior Iceberg snapshot. An append scan can accept a checkpoint at that missing parent and replay the full export as a delta.
Publish a full export as the root of a new Iceberg snapshot history. A reader with a checkpoint from before the rebuild must read a full snapshot and resume on the new history. Keep the initial export readable as an append, including when the first Paimon write is an overwrite. The normal publication path with a usable Iceberg base keeps its existing behavior.
Tests
IcebergCompatibilityTestandspotless:checkforpaimon-core.API and Format
Existing Iceberg metadata fields encode the new snapshot history boundary.
Documentation
Documented how an incremental reader resumes after an Iceberg metadata rebuild.