amogh-jahagirdar commented on code in PR #13614:
URL: https://github.com/apache/iceberg/pull/13614#discussion_r2227358908
##########
core/src/test/java/org/apache/iceberg/TestRemoveSnapshots.java:
##########
@@ -1829,6 +1879,91 @@ public void testRemoveSnapshotsNoOp() throws Exception {
.isSameAs(current);
}
+ @TestTemplate
+ public void testFileCleanupOnAllRefsAgedOff() {
+ table.newAppend().appendFile(FILE_A).commit();
+ Set<String> expectedDeleteFiles =
+ ImmutableSet.of(table.currentSnapshot().manifestListLocation());
+ String tag = "tag";
+ long tagAgeMs = 20;
+ table
+ .manageSnapshots()
+ .createTag(tag, table.currentSnapshot().snapshotId())
+ .setMaxRefAgeMs(tag, tagAgeMs)
+ .commit();
+ long currentTime = System.currentTimeMillis();
+ table.newAppend().appendFile(FILE_B).appendFile(FILE_C).commit();
+
+ waitUntilAfter(currentTime + tagAgeMs);
+
+ Set<String> deletedFiles = Sets.newHashSet();
+ removeSnapshots(table)
+ .cleanExpiredFiles(true)
+ .expireOlderThan(System.currentTimeMillis())
+ .deleteWith(deletedFiles::add)
+ .commit();
+ assertThat(deletedFiles).isEqualTo(expectedDeleteFiles);
+ }
+
+ @TestTemplate
+ public void testCannotIncrementallyCleanupBranchBeforeExpiration() {
+ assumeThat(incrementalCleanup).isTrue();
+
+ table.newAppend().appendFile(FILE_A).commit();
+ String branch = "test";
+ long branchAgeMs = 20;
+ table
+ .manageSnapshots()
+ .createBranch(branch)
+ .setMaxRefAgeMs(branch, branchAgeMs)
+ .setMinSnapshotsToKeep(branch, 1)
+ .commit();
+ table.newDelete().deleteFile(FILE_A).commit();
+
+ Set<String> deletedFiles = Sets.newHashSet();
+ assertThatThrownBy(
+ () ->
+ removeSnapshots(table)
+ .deleteWith(deletedFiles::add)
+ .expireOlderThan(System.currentTimeMillis())
+ .commit())
+ .isInstanceOf(UnsupportedOperationException.class)
+ .hasMessage(
+ "Cannot incrementally clean files when metadata before expiration
has other branches");
+ }
+
+ @TestTemplate
+ public void testReachableCleanupWhenBranchAgedOff() {
+ assumeThat(incrementalCleanup).isFalse();
+
+ table.newAppend().appendFile(FILE_A).commit();
+ String branch = "test";
+ long branchAgeMs = 20;
+ table
+ .manageSnapshots()
+ .createBranch(branch)
+ .setMaxRefAgeMs(branch, branchAgeMs)
+ .setMinSnapshotsToKeep(branch, 1)
+ .commit();
+ table.newDelete().deleteFile(FILE_A).commit();
+ Snapshot latestTestSnapshot = table.snapshot(branch);
+ long currentTime = System.currentTimeMillis();
+ waitUntilAfter(currentTime + branchAgeMs);
+
+ Set<String> expectedDeletedFiles =
+ ImmutableSet.of(
+ latestTestSnapshot.manifestListLocation(),
+
Iterables.getOnlyElement(latestTestSnapshot.allManifests(table.io())).path(),
+ FILE_A.location());
Review Comment:
Previously, we'd select incremental and miss out on cleaning up FILE_A
because the check was only limited to currently active refs. Now, we'll use the
reachable analysis to determine that FILE_A can be cleaned up since the branch
aged off and on the main branch it's deleted.
--
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]