amogh-jahagirdar commented on code in PR #4578:
URL: https://github.com/apache/iceberg/pull/4578#discussion_r867645902
##########
core/src/main/java/org/apache/iceberg/RemoveSnapshots.java:
##########
@@ -161,21 +173,101 @@ public List<Snapshot> apply() {
private TableMetadata internalApply() {
this.base = ops.refresh();
+ if (base.refs().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));
+ // Identify refs that should be removed
+ Set<String> retainedRefs = computeRetainedRefs(base.refs());
+ Set<Long> retainedRefIds = retainedRefs.stream()
+ .map(ref -> base.ref(ref).snapshotId())
+ .collect(Collectors.toSet());
+
+ for (long idToRemove : idsToRemove) {
+ Preconditions.checkArgument(!retainedRefIds.contains(idToRemove),
+ "Cannot expire %s. There is a reference to it", idToRemove);
+ }
+
+ idsToRetain.addAll(retainedRefIds);
+ Set<Long> branchSnapshotsToRetain =
computeAllBranchSnapshotsToRetain(base.refs());
Review Comment:
Updated
--
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]