yihua commented on code in PR #7921:
URL: https://github.com/apache/hudi/pull/7921#discussion_r1103483491


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieTableServiceClient.java:
##########
@@ -659,8 +662,46 @@ protected Map<String, Option<HoodiePendingRollbackInfo>> 
getPendingRollbackInfos
     return infoMap;
   }
 
+  /**
+   * Rolls back the failed delta commits corresponding to the indexing action.
+   * Such delta commits are identified based on the suffix 
`METADATA_INDEXER_TIME_SUFFIX` ("004").
+   * <p>
+   * TODO(HUDI-5733): This should be cleaned up once the proper fix of 
rollbacks
+   *  in the metadata table is landed.
+   *
+   * @return {@code true} if rollback happens; {@code false} otherwise.
+   */
+  protected boolean lazyRollbackFailedIndexing() {
+    HoodieTable table = createTable(config, hadoopConf);
+    List<String> instantsToRollback = 
getFailedIndexingToRollback(table.getMetaClient());
+    Map<String, Option<HoodiePendingRollbackInfo>> pendingRollbacks = 
getPendingRollbackInfos(table.getMetaClient());
+    instantsToRollback.forEach(entry -> pendingRollbacks.putIfAbsent(entry, 
Option.empty()));
+    rollbackFailedWrites(pendingRollbacks);
+    return !pendingRollbacks.isEmpty();
+  }
+
+  protected List<String> getFailedIndexingToRollback(HoodieTableMetaClient 
metaClient) {
+    Stream<HoodieInstant> inflightInstantsStream = 
metaClient.getCommitsTimeline()
+        .filter(instant -> !instant.isCompleted()
+            && isDeltaCommitFromIndexing(instant.getTimestamp()))
+        .getInstantsAsStream();
+    return inflightInstantsStream.filter(instant -> {
+      try {
+        return heartbeatClient.isHeartbeatExpired(instant.getTimestamp());
+      } catch (IOException io) {
+        throw new HoodieException("Failed to check heartbeat for instant " + 
instant, io);
+      }
+    }).map(HoodieInstant::getTimestamp).collect(Collectors.toList());
+  }
+
+  protected boolean isDeltaCommitFromIndexing(String instantTime) {

Review Comment:
   Fixed.



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