boneanxs commented on code in PR #7568:
URL: https://github.com/apache/hudi/pull/7568#discussion_r1061100539


##########
hudi-common/src/main/java/org/apache/hudi/common/util/ClusteringUtils.java:
##########
@@ -224,4 +225,37 @@ public static List<HoodieInstant> 
getPendingClusteringInstantTimes(HoodieTableMe
   public static boolean isPendingClusteringInstant(HoodieTableMetaClient 
metaClient, HoodieInstant instant) {
     return getClusteringPlan(metaClient, instant).isPresent();
   }
+
+  /**
+   * Checks whether the latest clustering instant has a subsequent cleaning 
action. Returns
+   * the clustering instant if there is such cleaning action or empty.
+   *
+   * @param activeTimeline The active timeline
+   * @return the oldest instant to retain for clustering
+   */
+  public static Option<HoodieInstant> 
getOldestInstantToRetainForClustering(HoodieActiveTimeline activeTimeline)
+      throws IOException {
+    HoodieTimeline replaceTimeline = 
activeTimeline.getCompletedReplaceTimeline();
+    if (!replaceTimeline.empty()) {
+      Option<HoodieInstant> cleanInstantOpt =
+          activeTimeline.getCleanerTimeline().filter(instant -> 
!instant.isCompleted()).firstInstant();
+      if (cleanInstantOpt.isPresent()) {
+        // The first clustering instant of which timestamp is greater than or 
equal to the earliest commit to retain of
+        // the clean metadata.
+        HoodieInstant cleanInstant = cleanInstantOpt.get();
+        String earliestCommitToRetain =

Review Comment:
   `earliestCommitToRetain` might be null if we use 
`KEEP_LATEST_FILE_VERSIONS`, here we need to check it.
   
   Also, if we use `KEEP_LATEST_FILE_VERSIONS`, not sure if this logic still is 
valid.



-- 
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: commits-unsubscr...@hudi.apache.org

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

Reply via email to