zhuanshenbsj1 commented on code in PR #9039:
URL: https://github.com/apache/hudi/pull/9039#discussion_r1241018239


##########
hudi-common/src/main/java/org/apache/hudi/common/util/CompactionUtils.java:
##########
@@ -345,22 +345,34 @@ public static Option<Pair<HoodieTimeline, HoodieInstant>> 
getDeltaCommitsSinceLa
    * @return the oldest instant to keep for MOR compaction.
    */
   public static Option<HoodieInstant> getOldestInstantToRetainForCompaction(
-      HoodieActiveTimeline activeTimeline, int maxDeltaCommits) {
+      HoodieActiveTimeline activeTimeline, HoodieTableMetaClient metaClient, 
int maxDeltaCommits) throws IOException {
+    Option<HoodieInstant> oldestDeltaCommitToRetain = Option.empty();
     Option<Pair<HoodieTimeline, HoodieInstant>> deltaCommitsInfoOption =
         CompactionUtils.getDeltaCommitsSinceLatestCompaction(activeTimeline);
     if (deltaCommitsInfoOption.isPresent()) {
       Pair<HoodieTimeline, HoodieInstant> deltaCommitsInfo = 
deltaCommitsInfoOption.get();
       HoodieTimeline deltaCommitTimeline = deltaCommitsInfo.getLeft();
       int numDeltaCommits = deltaCommitTimeline.countInstants();
       if (numDeltaCommits < maxDeltaCommits) {
-        return Option.of(deltaCommitsInfo.getRight());
+        oldestDeltaCommitToRetain = Option.of(deltaCommitsInfo.getRight());
       } else {
         // delta commits with the last one to keep
         List<HoodieInstant> instants = 
deltaCommitTimeline.getInstantsAsStream()
             .limit(numDeltaCommits - maxDeltaCommits + 
1).collect(Collectors.toList());
-        return Option.of(instants.get(instants.size() - 1));
+        oldestDeltaCommitToRetain = Option.of(instants.get(instants.size() - 
1));
       }
     }
-    return Option.empty();
+
+    HoodieTimeline completedCompactionTimeLine = 
activeTimeline.getCommitTimeline()
+            .filterCompletedInstants();
+    Option<HoodieInstant> oldestInstantToRetain = 
CleanerUtils.getOldestInstantToRetainFromTimeline(activeTimeline, metaClient, 
completedCompactionTimeLine);
+
+    Option<HoodieInstant> finalOldestDeltaCommitToRetain = 
oldestDeltaCommitToRetain;
+    if (oldestDeltaCommitToRetain.isPresent()
+            && oldestInstantToRetain.map(instant -> 
instant.compareTo(finalOldestDeltaCommitToRetain.get()) > 0).orElse(true)) {
+      oldestInstantToRetain = oldestDeltaCommitToRetain;
+    }
+
+    return oldestInstantToRetain;

Review Comment:
   > Not sure which code snippet guards the correctness, for clustering with 
incremental cleaning, the `instant to retain` is specifically fixed by fetching 
the instant from the `CleanPlan`, what's the nuances for compaction?
   
   
https://github.com/apache/hudi/blob/8a5288202e510e9d4d551b5cb588af62677496ba/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/clean/CleanPlanActionExecutor.java#L108
   
   Regardless of clustering or compaction,  incremental cleanup must use the 
instant before getEarliestCommitToRetain to obtain which partitions to clean 
up.  If the compaction instant is archived and has not yet been cleaned up,  
and the compaction instant is the last instant of the previous partition ,then 
the relevant logs cannot be cleared.
   



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

Reply via email to