vamsikarnika commented on code in PR #621:
URL: https://github.com/apache/incubator-xtable/pull/621#discussion_r1907511873
##########
xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergConversionTarget.java:
##########
@@ -211,18 +222,34 @@ public void syncFilesForDiff(DataFilesDiff dataFilesDiff)
{
@Override
public void completeSync() {
- transaction
- .expireSnapshots()
- .expireOlderThan(
- Instant.now().minus(snapshotRetentionInHours,
ChronoUnit.HOURS).toEpochMilli())
- .deleteWith(this::safeDelete) // ensures that only metadata files are
deleted
- .cleanExpiredFiles(true)
- .commit();
+ boolean useInternalIcebergCleaner = useInternalCleaner();
+ ExpireSnapshots expireSnapshots =
+ transaction
+ .expireSnapshots()
+ .expireOlderThan(
+ Instant.now().minus(snapshotRetentionInHours,
ChronoUnit.HOURS).toEpochMilli())
+ .cleanExpiredFiles(!useInternalIcebergCleaner); // is internal
cleaner is enabled, disable iceberg cleaner
+ List<Snapshot> removedSnapshots = expireSnapshots.apply();
+ expireSnapshots.commit();
transaction.commitTransaction();
+ // after commit is complete, clean up the manifest files
+ if (useInternalIcebergCleaner) {
+ cleanExpiredSnapshots(removedSnapshots);
+ }
transaction = null;
internalTableState = null;
}
+ private boolean useInternalCleaner() {
+ return useInternalMetadataCleaner && table.refs().size() == 1;
+ }
+
+ private void cleanExpiredSnapshots(List<Snapshot> removedSnapshots) {
+ IcebergMetadataCleanupStrategy cleanupStrategy = new
IcebergMetadataFileCleaner(transaction.table().io(), deleteExecutorService,
planExecutorService, this::safeDelete);
+ cleanupStrategy.cleanFiles(table, removedSnapshots);
+ }
Review Comment:
This can be run in async to further improve the performance
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]