rdblue commented on code in PR #4578:
URL: https://github.com/apache/iceberg/pull/4578#discussion_r886267876
##########
core/src/main/java/org/apache/iceberg/RemoveSnapshots.java:
##########
@@ -161,21 +176,143 @@ public List<Snapshot> apply() {
private TableMetadata internalApply() {
this.base = ops.refresh();
+ if (base.snapshots().isEmpty()) {
+ return base;
+ }
Set<Long> idsToRetain = Sets.newHashSet();
- List<Long> ancestorIds = SnapshotUtil.ancestorIds(base.currentSnapshot(),
base::snapshot);
- if (minNumSnapshots >= ancestorIds.size()) {
- idsToRetain.addAll(ancestorIds);
- } else {
- idsToRetain.addAll(ancestorIds.subList(0, minNumSnapshots));
+
+ // Compute the snapshots for each reference
+ Map<SnapshotRef, Set<Long>> refSnapshots =
computeRefSnapshots(base.refs().values());
+
+ // Identify unreferenced snapshots which should be retained
+ Set<Long> unreferencedSnapshotsToRetain =
computeUnreferencedSnapshotsToRetain(refSnapshots);
Review Comment:
I think this should be passed a single set of retained snapshots and look
for any others, rather than using a complex map. Just do this analysis last,
after you know all the other snapshots that are retained for other reasons.
--
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]