suryaprasanna commented on code in PR #19023:
URL: https://github.com/apache/hudi/pull/19023#discussion_r3425668291


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/utils/TransactionUtils.java:
##########
@@ -141,6 +145,28 @@ public static Option<Pair<HoodieInstant, Map<String, 
String>>> getLastCompletedT
     return getHoodieInstantAndMetaDataPair(metaClient, hoodieInstantOption);
   }
 
+  /**
+   * Get the last completed transaction hoodie instant before the given 
instant time.
+   * The returned instant has both requested time and completion time less 
than the given instant time,
+   * ensuring it was fully completed before the given instant was created.
+   *
+   * @param metaClient table meta client
+   * @param currentInstantTime the requested time of the current inflight 
instant
+   * @return the last completed instant before the given instant, with its 
extra metadata
+   */
+  public static Option<Pair<HoodieInstant, Map<String, String>>> 
getLastCompletedTxnInstantAndMetadata(
+      HoodieTableMetaClient metaClient, String currentInstantTime) {
+    Option<HoodieInstant> hoodieInstantOption = Option.fromJavaOptional(
+        metaClient.getActiveTimeline().getCommitsTimeline()
+            .filterCompletedInstants()
+            .findInstantsBefore(currentInstantTime)
+            .getInstantsAsStream()
+            .filter(instant -> instant.getCompletionTime() != null
+                && compareTimestamps(instant.getCompletionTime(), LESSER_THAN, 
currentInstantTime))

Review Comment:
   @wombatu-kun  thanks for the review, responded for this in the below comment 
please check and let me know your thoughts.



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/utils/TransactionUtils.java:
##########
@@ -141,6 +144,28 @@ public static Option<Pair<HoodieInstant, Map<String, 
String>>> getLastCompletedT
     return getHoodieInstantAndMetaDataPair(metaClient, hoodieInstantOption);
   }
 
+  /**
+   * Get the last completed transaction hoodie instant before the given 
instant time.
+   * The returned instant has both requested time and completion time less 
than the given instant time,
+   * ensuring it was fully completed before the given instant was created.
+   *
+   * @param metaClient table meta client
+   * @param currentInstantTime the requested time of the current inflight 
instant
+   * @return the last completed instant before the given instant, with its 
extra metadata
+   */
+  public static Option<Pair<HoodieInstant, Map<String, String>>> 
getLastCompletedTxnInstantAndMetadata(
+      HoodieTableMetaClient metaClient, String currentInstantTime) {
+    Option<HoodieInstant> hoodieInstantOption = Option.fromJavaOptional(
+        metaClient.getActiveTimeline().getCommitsTimeline()
+            .filterCompletedInstants()
+            .findInstantsBefore(currentInstantTime)
+            .getInstantsAsStream()
+            .filter(instant -> instant.getCompletionTime() != null
+                && compareTimestamps(instant.getCompletionTime(), LESSER_THAN, 
currentInstantTime))
+            .max(Comparator.comparing(HoodieInstant::getCompletionTime)));

Review Comment:
   I feel OCC strategy is unnecessarily complicating the conflict resolution 
behavior. During conflict resolution, we should only care for completed commits 
that are committed after the current instant started, apart from that rest of 
the instants can be ignored. With that approach we can even remove the tracking 
of pendingInstants during the commit window and also 
timelineRefreshedWithinTransaction variables. So, I think we should make the 
change to fix it there as well. Let me know, if you think the same.



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/utils/TransactionUtils.java:
##########
@@ -141,6 +144,28 @@ public static Option<Pair<HoodieInstant, Map<String, 
String>>> getLastCompletedT
     return getHoodieInstantAndMetaDataPair(metaClient, hoodieInstantOption);
   }
 
+  /**
+   * Get the last completed transaction hoodie instant before the given 
instant time.
+   * The returned instant has both requested time and completion time less 
than the given instant time,
+   * ensuring it was fully completed before the given instant was created.
+   *
+   * @param metaClient table meta client
+   * @param currentInstantTime the requested time of the current inflight 
instant
+   * @return the last completed instant before the given instant, with its 
extra metadata
+   */
+  public static Option<Pair<HoodieInstant, Map<String, String>>> 
getLastCompletedTxnInstantAndMetadata(
+      HoodieTableMetaClient metaClient, String currentInstantTime) {
+    Option<HoodieInstant> hoodieInstantOption = Option.fromJavaOptional(
+        metaClient.getActiveTimeline().getCommitsTimeline()
+            .filterCompletedInstants()
+            .findInstantsBefore(currentInstantTime)
+            .getInstantsAsStream()
+            .filter(instant -> instant.getCompletionTime() != null
+                && compareTimestamps(instant.getCompletionTime(), LESSER_THAN, 
currentInstantTime))
+            .max(Comparator.comparing(HoodieInstant::getCompletionTime)));

Review Comment:
   CC @wombatu-kun 



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