amogh-jahagirdar commented on code in PR #4578:
URL: https://github.com/apache/iceberg/pull/4578#discussion_r862538489


##########
core/src/main/java/org/apache/iceberg/RemoveSnapshots.java:
##########
@@ -163,21 +180,86 @@ private TableMetadata internalApply() {
     this.base = ops.refresh();
 
     Set<Long> idsToRetain = Sets.newHashSet();
-    List<Long> ancestorIds = SnapshotUtil.ancestorIds(base.currentSnapshot(), 
base::snapshot);
-    if (minNumSnapshots >= ancestorIds.size()) {
+    // Identify refs that should be removed
+    Set<String> refsToRemove = Sets.newHashSet();
+    for (String name : base.refs().keySet()) {
+      SnapshotRef ref = base.ref(name);
+      if (!name.equals(SnapshotRef.MAIN_BRANCH) && ref.maxRefAgeMs() != null) {
+        Snapshot snapshot = base.snapshot(ref.snapshotId());
+        if (removalTimeReference - snapshot.timestampMillis() >= 
ref.maxRefAgeMs()) {
+          refsToRemove.add(name);
+        }
+
+      }
+
+      if (!refsToRemove.contains(name) && 
!idsToRemove.contains(ref.snapshotId())) {

Review Comment:
   If I understand what you are saying we are distinguishing the 2 cases, 
   
   1.) the metadata operation to **remove** a snapshot should also drop any 
refs associated with it (which we do currently). 
   
   2.) **Expiration** of a snapshot which has references should result in 
failure
   
   This makes sense to me because removing implies a more "blunt" kind of 
operation where we actually intend on deleting that information. Expiration 
does not really have that implication, so it should be prevented. That way, 
someone unknowingly running an unsafe of a snapshot with refs is prevented.



-- 
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]

Reply via email to