Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARCTIC-1095][AMS] Add the sequence number for the native iceberg table when the major optimizing commit #1101

Merged
merged 3 commits into from
Feb 14, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,31 @@ private void majorCommit(ArcticTable arcticTable,
}).filter(Objects::nonNull).collect(Collectors.toSet());

// rewrite DataFiles
RewriteFiles rewriteFiles = baseArcticTable.newRewrite();
rewriteFiles.set(SnapshotSummary.SNAPSHOT_PRODUCER, CommitMetaProducer.OPTIMIZE.name());
RewriteFiles rewriteDataFiles = baseArcticTable.newRewrite();
if (baseSnapshotId != TableOptimizeRuntime.INVALID_SNAPSHOT_ID) {
rewriteFiles.validateFromSnapshot(baseSnapshotId);
rewriteDataFiles.validateFromSnapshot(baseSnapshotId);
long sequenceNumber = arcticTable.asUnkeyedTable().snapshot(baseSnapshotId).sequenceNumber();
rewriteDataFiles.rewriteFiles(deleteDataFiles, addDataFiles, sequenceNumber);
} else {
rewriteDataFiles.rewriteFiles(deleteDataFiles, addDataFiles);
}
rewriteDataFiles.set(SnapshotSummary.SNAPSHOT_PRODUCER, CommitMetaProducer.OPTIMIZE.name());
rewriteDataFiles.commit();

// remove DeleteFiles additional
if (CollectionUtils.isNotEmpty(deleteDeleteFiles)) {
RewriteFiles rewriteDeleteFiles = baseArcticTable.newRewrite();
rewriteDeleteFiles.set(SnapshotSummary.SNAPSHOT_PRODUCER, CommitMetaProducer.OPTIMIZE.name());
rewriteDeleteFiles.rewriteFiles(Collections.emptySet(), deleteDeleteFiles,
Collections.emptySet(), Collections.emptySet());
try {
rewriteDeleteFiles.commit();
} catch (ValidationException e) {
// Iceberg will drop DeleteFiles that are older than the min Data sequence number. So some DeleteFiles
// maybe already dropped in the last commit, the exception can be ignored.
LOG.warn("Iceberg RewriteFiles commit failed, but ignore", e);
}
}
rewriteFiles.rewriteFiles(deleteDataFiles, deleteDeleteFiles, addDataFiles, Collections.emptySet());
rewriteFiles.commit();

LOG.info("{} major optimize committed, delete {} files [{} Delete files], " +
"add {} new files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public void testNoPartitionTableMajorOptimizeCommit() throws Exception {
try (CloseableIterable<FileScanTask> filesIterable = icebergNoPartitionTable.asUnkeyedTable().newScan()
.planFiles()) {
filesIterable.forEach(fileScanTask -> {
if (fileScanTask.file().fileSizeInBytes() <= 1000) {
oldDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> oldDeleteFilesPath.add((String) deleteFile.path()));
}
oldDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> oldDeleteFilesPath.add((String) deleteFile.path()));
});
}

Expand Down Expand Up @@ -108,6 +106,7 @@ public void testPartitionTableMajorOptimizeCommit() throws Exception {
.set(TableProperties.SELF_OPTIMIZING_FRAGMENT_RATIO,
TableProperties.SELF_OPTIMIZING_TARGET_SIZE_DEFAULT / 1000 + "")
.set(TableProperties.SELF_OPTIMIZING_MAJOR_TRIGGER_DUPLICATE_RATIO, "0")
.set(org.apache.iceberg.TableProperties.DEFAULT_WRITE_METRICS_MODE, "full")
.commit();
List<DataFile> dataFiles = insertDataFiles(icebergPartitionTable.asUnkeyedTable(), 10);
insertEqDeleteFiles(icebergPartitionTable.asUnkeyedTable(), 5);
Expand All @@ -116,10 +115,8 @@ public void testPartitionTableMajorOptimizeCommit() throws Exception {
Set<String> oldDeleteFilesPath = new HashSet<>();
try (CloseableIterable<FileScanTask> filesIterable = icebergPartitionTable.asUnkeyedTable().newScan().planFiles()) {
filesIterable.forEach(fileScanTask -> {
if (fileScanTask.file().fileSizeInBytes() <= 1000) {
oldDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> oldDeleteFilesPath.add((String) deleteFile.path()));
}
oldDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> oldDeleteFilesPath.add((String) deleteFile.path()));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ public void testNoPartitionTableMinorOptimizeCommit() throws Exception {
optimizeCommit.commit(icebergNoPartitionTable.asUnkeyedTable().currentSnapshot().snapshotId());

Set<String> newDataFilesPath = new HashSet<>();
Set<String> newDeleteFilesPath = new HashSet<>();
try (CloseableIterable<FileScanTask> filesIterable = icebergPartitionTable.asUnkeyedTable().newScan()
.planFiles()) {
filesIterable.forEach(fileScanTask -> {
if (fileScanTask.file().fileSizeInBytes() <= 1000) {
newDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> newDeleteFilesPath.add((String) deleteFile.path()));
}
});
}
Assert.assertNotEquals(oldDataFilesPath, newDataFilesPath);
Assert.assertNotEquals(oldDeleteFilesPath, newDeleteFilesPath);
}

@Test
Expand All @@ -113,10 +124,8 @@ public void testPartitionTableMinorOptimizeCommit() throws Exception {
try (CloseableIterable<FileScanTask> filesIterable = icebergPartitionTable.asUnkeyedTable().newScan()
.planFiles()) {
filesIterable.forEach(fileScanTask -> {
if (fileScanTask.file().fileSizeInBytes() <= 1000) {
oldDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> oldDeleteFilesPath.add((String) deleteFile.path()));
}
oldDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> oldDeleteFilesPath.add((String) deleteFile.path()));
});
}

Expand Down Expand Up @@ -160,6 +169,17 @@ public void testPartitionTableMinorOptimizeCommit() throws Exception {
optimizeCommit.commit(icebergPartitionTable.asUnkeyedTable().currentSnapshot().snapshotId());

Set<String> newDataFilesPath = new HashSet<>();
Set<String> newDeleteFilesPath = new HashSet<>();
try (CloseableIterable<FileScanTask> filesIterable = icebergPartitionTable.asUnkeyedTable().newScan()
.planFiles()) {
filesIterable.forEach(fileScanTask -> {
if (fileScanTask.file().fileSizeInBytes() <= 1000) {
newDataFilesPath.add((String) fileScanTask.file().path());
fileScanTask.deletes().forEach(deleteFile -> newDeleteFilesPath.add((String) deleteFile.path()));
}
});
}
Assert.assertNotEquals(oldDataFilesPath, newDataFilesPath);
Assert.assertNotEquals(oldDeleteFilesPath, newDeleteFilesPath);
}
}