rdblue commented on code in PR #5981:
URL: https://github.com/apache/iceberg/pull/5981#discussion_r999756396
##########
core/src/main/java/org/apache/iceberg/ReachableFileCleanup.java:
##########
@@ -63,39 +63,83 @@ public void cleanFiles(TableMetadata beforeExpiration,
TableMetadata afterExpira
}
}
}
-
- Set<ManifestFile> candidateManifestFilesForDeletion =
readManifests(expiredSnapshots);
- Set<ManifestFile> manifestFilesAfterExpiration =
readManifests(snapshotsAfterExpiration);
-
- Set<ManifestFile> manifestsToDelete = Sets.newHashSet();
- for (ManifestFile candidateManifestFile :
candidateManifestFilesForDeletion) {
- if (!manifestFilesAfterExpiration.contains(candidateManifestFile)) {
- manifestsToDelete.add(candidateManifestFile);
+ Set<ManifestFile> deletionCandidates = readManifests(expiredSnapshots);
+
+ if (!deletionCandidates.isEmpty()) {
+ Set<ManifestFile> currentManifests = ConcurrentHashMap.newKeySet();
+ Set<ManifestFile> manifestsToDelete =
+ pruneReferencedManifests(
+ snapshotsAfterExpiration, deletionCandidates,
currentManifests::add);
+
+ if (!manifestsToDelete.isEmpty()) {
+ Set<String> dataFilesToDelete = findFilesToDelete(manifestsToDelete,
currentManifests);
+ deleteFiles(dataFilesToDelete, "data");
+ Set<String> manifestPathsToDelete =
+
manifestsToDelete.stream().map(ManifestFile::path).collect(Collectors.toSet());
+ deleteFiles(manifestPathsToDelete, "manifest");
}
}
- Set<String> dataFilesToDelete =
- findFilesToDelete(manifestsToDelete, manifestFilesAfterExpiration);
- deleteFiles(dataFilesToDelete, "data");
- Set<String> manifestPathsToDelete =
-
manifestsToDelete.stream().map(ManifestFile::path).collect(Collectors.toSet());
-
- deleteFiles(manifestPathsToDelete, "manifest");
deleteFiles(manifestListsToDelete, "manifest list");
}
+ private Set<ManifestFile> pruneReferencedManifests(
+ Set<Snapshot> snapshots,
+ Set<ManifestFile> deletionCandidates,
+ Consumer<ManifestFile> currentManifestCallback) {
+ Set<ManifestFile> candidateSet = ConcurrentHashMap.newKeySet();
+ candidateSet.addAll(deletionCandidates);
+ Tasks.foreach(snapshots)
+ .retry(3)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(planExecutorService)
+ .onFailure(
+ (snapshot, exc) ->
+ LOG.warn(
+ "Failed to determine manifests for snapshot {}",
snapshot.snapshotId(), exc))
+ .run(
+ snapshot -> {
+ try (CloseableIterable<ManifestFile> manifestFiles =
readManifests(snapshot)) {
+ for (ManifestFile manifestFile : manifestFiles) {
+ candidateSet.remove(manifestFile);
+ if (candidateSet.isEmpty()) {
+ return;
+ }
+
+ currentManifestCallback.accept(manifestFile.copy());
Review Comment:
Very minor, but it seems weird to copy here rather than in the callback. If
the callback were a noop, we'd be doing work for nothing. Since we know it
needs to be copied, it seems fine though.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]