jsbali commented on a change in pull request #2677:
URL: https://github.com/apache/hudi/pull/2677#discussion_r600462395



##########
File path: 
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/io/TestHoodieTimelineArchiveLog.java
##########
@@ -491,6 +519,166 @@ public void testConvertCommitMetadata() {
     assertEquals(expectedCommitMetadata.getOperationType(), 
WriteOperationType.INSERT.toString());
   }
 
+  @Test
+  public void testArchiveCompletedClean() throws IOException {
+    HoodieWriteConfig cfg =
+            
HoodieWriteConfig.newBuilder().withPath(basePath).withSchema(HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA)
+                    .withParallelism(2, 2).forTable("test-trip-table")
+                    
.withCompactionConfig(HoodieCompactionConfig.newBuilder().retainCommits(1).archiveCommitsWith(2,
 3).build())
+                    .build();
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+
+    createCleanMetadata("10", false);
+    createCleanMetadata("11", false);
+    createCleanMetadata("12", false);
+    HoodieInstant notArchivedInstant1 = new HoodieInstant(State.COMPLETED, 
"clean", "12");
+    createCleanMetadata("13", false);
+    HoodieInstant notArchivedInstant2 = new HoodieInstant(State.COMPLETED, 
"clean", "13");
+
+    HoodieTable table = HoodieSparkTable.create(cfg, context, metaClient);
+    HoodieTimelineArchiveLog archiveLog = new HoodieTimelineArchiveLog(cfg, 
table);
+
+    archiveLog.archiveIfRequired(context);
+
+    List<HoodieInstant> notArchivedInstants = 
metaClient.getActiveTimeline().reload().getInstants().collect(Collectors.toList());
+    //There will be 3 * 2 files but due to TimelineLayoutV1 this will show as 
2.
+    assertEquals(2, notArchivedInstants.size(), "Not archived instants should 
be 2");
+    assertEquals(notArchivedInstants, Arrays.asList(notArchivedInstant1, 
notArchivedInstant2), "");
+  }
+
+  @Test
+  public void testArchiveCompletedRollback() throws IOException {
+    HoodieWriteConfig cfg =
+            
HoodieWriteConfig.newBuilder().withPath(basePath).withSchema(HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA)
+                    .withParallelism(2, 2).forTable("test-trip-table")
+                    
.withCompactionConfig(HoodieCompactionConfig.newBuilder().retainCommits(1).archiveCommitsWith(2,
 3).build())
+                    .build();
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+
+    createCommitAndRollbackFile("6", "10", false);
+    createCommitAndRollbackFile("8", "11", false);
+    createCommitAndRollbackFile("7", "12", false);
+    HoodieInstant notArchivedInstant1 = new HoodieInstant(State.COMPLETED, 
"rollback", "12");
+
+    createCommitAndRollbackFile("5", "13", false);
+    HoodieInstant notArchivedInstant2 = new HoodieInstant(State.COMPLETED, 
"rollback", "13");
+
+    HoodieTable table = HoodieSparkTable.create(cfg, context, metaClient);
+    HoodieTimelineArchiveLog archiveLog = new HoodieTimelineArchiveLog(cfg, 
table);
+
+    archiveLog.archiveIfRequired(context);
+
+    List<HoodieInstant> notArchivedInstants = 
metaClient.getActiveTimeline().reload().getRollbackTimeline().getInstants().collect(Collectors.toList());
+    //There will be 2 * 2 files but due to TimelineLayoutV1 this will show as 
2.
+    assertEquals(2, notArchivedInstants.size(), "Not archived instants should 
be 2");
+    assertEquals(notArchivedInstants, Arrays.asList(notArchivedInstant1, 
notArchivedInstant2), "");
+  }
+
+  @Test
+  public void 
testArchiveCompletedShouldRetainMinInstantsIfInstantsGreaterThanMaxtoKeep() 
throws IOException {
+    int minInstants = 2;
+    int maxInstants = 10;
+    HoodieWriteConfig cfg =
+            
HoodieWriteConfig.newBuilder().withPath(basePath).withSchema(HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA)
+                    .withParallelism(2, 2).forTable("test-trip-table")
+                    
.withCompactionConfig(HoodieCompactionConfig.newBuilder().retainCommits(1).archiveCommitsWith(minInstants,
 maxInstants).build())
+                    .build();
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+    for (int i = 0; i < maxInstants + 2; i++) {
+      createCleanMetadata(i + "", false);
+    }
+
+    HoodieTable table = HoodieSparkTable.create(cfg, context, metaClient);
+    HoodieTimelineArchiveLog archiveLog = new HoodieTimelineArchiveLog(cfg, 
table);
+
+    archiveLog.archiveIfRequired(context);
+    assertEquals(minInstants, 
metaClient.getActiveTimeline().reload().getInstants().count());
+  }
+
+  @Test
+  public void 
testArchiveCompletedShouldNotArchiveIfInstantsLessThanMaxtoKeep() throws 
IOException {
+    int minInstants = 2;
+    int maxInstants = 10;
+    HoodieWriteConfig cfg =
+            
HoodieWriteConfig.newBuilder().withPath(basePath).withSchema(HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA)
+                    .withParallelism(2, 2).forTable("test-trip-table")
+                    
.withCompactionConfig(HoodieCompactionConfig.newBuilder().retainCommits(1).archiveCommitsWith(minInstants,
 maxInstants).build())
+                    .build();
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+    for (int i = 0; i < maxInstants; i++) {
+      createCleanMetadata(i + "", false);
+    }
+
+    HoodieTable table = HoodieSparkTable.create(cfg, context, metaClient);
+    HoodieTimelineArchiveLog archiveLog = new HoodieTimelineArchiveLog(cfg, 
table);
+
+    archiveLog.archiveIfRequired(context);
+    assertEquals(maxInstants, 
metaClient.getActiveTimeline().reload().getInstants().count());
+  }
+
+  @Test
+  public void testArchiveCompletedRollbackAndClean() throws IOException {

Review comment:
       This one is specifically to add/show that max and min InstantsToKeep 
limits are applied at an action level for completed instants. 




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to