nsivabalan commented on code in PR #7605:
URL: https://github.com/apache/hudi/pull/7605#discussion_r1066311330


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java:
##########
@@ -857,11 +860,24 @@ public HoodieRestoreMetadata restoreToInstant(final 
String instantTime, boolean
         }
         return restoreMetadata;
       } else {
-        throw new HoodieRestoreException("Failed to restore " + 
config.getBasePath() + " to commit " + instantTime);
+        throw new HoodieRestoreException("Failed to restore " + 
config.getBasePath() + " to commit " + savepointToRestoreTimestamp);
       }
     } catch (Exception e) {
-      throw new HoodieRestoreException("Failed to restore to " + instantTime, 
e);
+      throw new HoodieRestoreException("Failed to restore to " + 
savepointToRestoreTimestamp, e);
+    }
+  }
+
+  /**
+   * Check if there is a failed restore with the same 
savepointToRestoreTimestamp. Reusing the commit instead of
+   * creating a new one will prevent causing some issues with the metadata 
table.
+   * */
+  private Pair<String, Option<HoodieRestorePlan>> getRestorePlan(final String 
savepointToRestoreTimestamp, HoodieTable<T, I, K, O> table) throws IOException {

Review Comment:
   minor. mayBeScheduleAndGetRestorePlan



##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/TestClientRollback.java:
##########
@@ -175,9 +187,78 @@ public void testSavepointAndRollback() throws Exception {
 
       dataFiles = partitionPaths.stream().flatMap(s -> 
view3.getAllBaseFiles(s).filter(f -> 
f.getCommitTime().equals("004"))).collect(Collectors.toList());
       assertEquals(0, dataFiles.size(), "The data files for commit 004 should 
be rolled back");
+
+      if (testFailedRestore) {
+        //test to make sure that restore commit is reused when the restore 
fails and is re-ran
+        HoodieInstant inst =  
table.getActiveTimeline().getRestoreTimeline().getInstants().get(0);
+        String restoreFile = table.getMetaClient().getBasePathV2().toString() 
+ "/.hoodie/" +  inst.getFileName();
+        File commitFile = new File(restoreFile);
+        commitFile.delete();
+        if (!failedRestoreInflight) {
+          File inflightFile = new File(restoreFile + ".inflight");
+          inflightFile.delete();
+        }
+        try (SparkRDDWriteClient newClient = getHoodieWriteClient(cfg)) {
+          //restore again
+          newClient.restoreToSavepoint(savepoint.getTimestamp());
+          metaClient = HoodieTableMetaClient.reload(metaClient);
+          table = HoodieSparkTable.create(getConfig(), context, metaClient);
+          //verify that there is only 1 restore commit
+          assertEquals(1, 
table.getActiveTimeline().getRestoreTimeline().getInstants().size());

Review Comment:
   lets also verify 
   that its complete. 
   and matches the first time restore instant time



##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/TestClientRollback.java:
##########
@@ -175,9 +187,78 @@ public void testSavepointAndRollback() throws Exception {
 
       dataFiles = partitionPaths.stream().flatMap(s -> 
view3.getAllBaseFiles(s).filter(f -> 
f.getCommitTime().equals("004"))).collect(Collectors.toList());
       assertEquals(0, dataFiles.size(), "The data files for commit 004 should 
be rolled back");
+
+      if (testFailedRestore) {
+        //test to make sure that restore commit is reused when the restore 
fails and is re-ran
+        HoodieInstant inst =  
table.getActiveTimeline().getRestoreTimeline().getInstants().get(0);
+        String restoreFile = table.getMetaClient().getBasePathV2().toString() 
+ "/.hoodie/" +  inst.getFileName();
+        File commitFile = new File(restoreFile);
+        commitFile.delete();
+        if (!failedRestoreInflight) {
+          File inflightFile = new File(restoreFile + ".inflight");

Review Comment:
   not sure what are we trying to do here. can u help me understand



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