Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/docs/iceberg/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Initial publication and metadata rebuilds use snapshot splits that can be read d
Paimon's merge logic. The table above describes subsequent incremental publication. Use compaction
to establish a predictable visibility boundary for primary key tables.

An Iceberg metadata rebuild starts a new snapshot history. An incremental reader with a checkpoint
from before the rebuild must read a full snapshot and resume from a checkpoint in the new history.

The [primary key guide](./primary-key-table.mdx) explains both modes and their configuration.
Disabling an Iceberg catalog's cache can help with interactive verification, but cannot make
uncompacted or unpublished changes visible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ private void createMetadataWithoutBase(
new IcebergSnapshot(
snapshotId,
snapshotId,
snapshotId == Snapshot.FIRST_SNAPSHOT_ID ? null : (Long) (snapshotId - 1),
// A full export starts a new lineage. Readers with old checkpoints must
// resync.
null,
// the Paimon snapshot's own commit time, the as-of time readers see
paimonSnapshot.timeMillis(),
snapshotSummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.FileScanTask;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.data.IcebergGenerics;
import org.apache.iceberg.data.Record;
Expand Down Expand Up @@ -179,6 +180,96 @@ public void testFileLevelChange() throws Exception {
commit.close();
}

@Test
public void testWithoutBaseRebuildRequiresIncrementalResync() throws Exception {
RowType rowType =
RowType.of(
new DataType[] {DataTypes.INT(), DataTypes.INT()}, new String[] {"k", "v"});
FileStoreTable table =
createPaimonTable(
rowType,
Collections.emptyList(),
Collections.singletonList("k"),
1,
Collections.singletonMap(
CoreOptions.DELETION_VECTORS_ENABLED.key(), "false"));

String commitUser = UUID.randomUUID().toString();
try (TableWriteImpl<?> write = table.newWrite(commitUser);
TableCommitImpl commit = table.newCommit(commitUser)) {
commit.ignoreEmptyCommit(false).commit(1, Collections.emptyList());
commit.ignoreEmptyCommit(true);
long checkpoint = getIcebergTable().currentSnapshot().snapshotId();
assertThat(getIcebergResult()).isEmpty();

write.write(GenericRow.of(1, 10));
commit.commit(2, write.prepareCommit(false, 2));
write.write(GenericRow.of(1, 11));
write.write(GenericRow.of(2, 20));
commit.commit(3, write.prepareCommit(false, 3));
assertThat(getIcebergResult()).isEmpty();
long previousHead = getIcebergTable().currentSnapshot().snapshotId();

Path metadataPath = IcebergCommitCallback.catalogTableMetadataPath(table);
table.fileIO().deleteDirectoryQuietly(metadataPath);
assertThat(table.fileIO().exists(metadataPath)).isFalse();

write.compact(BinaryRow.EMPTY_ROW, 0, true);
commit.commit(4, write.prepareCommit(true, 4));

assertThat(table.snapshotManager().latestSnapshot().commitKind())
.isEqualTo(Snapshot.CommitKind.COMPACT);
assertThat(getIcebergResult())
.containsExactlyInAnyOrder("Record(1, 11)", "Record(2, 20)");

org.apache.iceberg.Table rebuilt = getIcebergTable();
assertThat(rebuilt.currentSnapshot().snapshotId()).isEqualTo(previousHead + 1);
for (long oldCheckpoint : new long[] {previousHead, checkpoint}) {
assertThatThrownBy(
() ->
rebuilt.newIncrementalAppendScan()
.fromSnapshotExclusive(oldCheckpoint)
.planFiles())
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("not a parent ancestor");
}
assertThat(rebuilt.currentSnapshot().parentId()).isNull();
}
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testInitialIcebergSnapshotCanBeReadAsAppend(boolean overwrite) throws Exception {
RowType rowType =
RowType.of(
new DataType[] {DataTypes.INT(), DataTypes.INT()}, new String[] {"k", "v"});
FileStoreTable table =
createPaimonTable(rowType, Collections.emptyList(), Collections.emptyList(), -1);

String commitUser = UUID.randomUUID().toString();
try (TableWriteImpl<?> write = table.newWrite(commitUser);
TableCommitImpl commit = table.newCommit(commitUser)) {
if (overwrite) {
commit.withOverwriteStaticPartitions(
Collections.singletonList(BinaryRow.EMPTY_ROW));
}
write.write(GenericRow.of(1, 10));
write.write(GenericRow.of(2, 20));
commit.commit(1, write.prepareCommit(false, 1));
}

assertThat(table.snapshotManager().latestSnapshot().commitKind())
.isEqualTo(overwrite ? Snapshot.CommitKind.OVERWRITE : Snapshot.CommitKind.APPEND);
org.apache.iceberg.Table icebergTable = getIcebergTable();
assertThat(icebergTable.currentSnapshot().parentId()).isNull();
try (CloseableIterable<FileScanTask> files =
icebergTable.newIncrementalAppendScan().planFiles()) {
assertThat(files).extracting(task -> task.file().recordCount()).containsExactly(2L);
}
assertThat(icebergTable.currentSnapshot().operation()).isEqualTo("append");
assertThat(getIcebergResult()).containsExactlyInAnyOrder("Record(1, 10)", "Record(2, 20)");
}

@Test
public void testDeletedEntryRecordsTheDeletingSnapshot() throws Exception {
RowType rowType =
Expand Down
Loading