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


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/restore/RestoreUtils.java:
##########
@@ -43,4 +46,24 @@ public static HoodieRestorePlan 
getRestorePlan(HoodieTableMetaClient metaClient,
     return TimelineMetadataUtils.deserializeAvroMetadata(
         
metaClient.getActiveTimeline().readRestoreInfoAsBytes(requested).get(), 
HoodieRestorePlan.class);
   }
+
+  /**
+   * Get the restore time for a restore instant
+   * @param table          the HoodieTable
+   * @param restoreInstant Instant referring to restore action
+   * @return restore time of the rollback instant
+   * @throws IOException
+   *
+   * */
+  public static String getRestoreTime(HoodieTable table, HoodieInstant 
restoreInstant) throws IOException {

Review Comment:
   getSavepointToRestoreTimestamp



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java:
##########
@@ -840,11 +841,25 @@ public boolean rollback(final String commitInstantTime, 
Option<HoodiePendingRoll
    */
   public HoodieRestoreMetadata restoreToInstant(final String instantTime, 
boolean initialMetadataTableIfNecessary) throws HoodieRestoreException {
     LOG.info("Begin restore to instant " + instantTime);
-    final String restoreInstantTime = 
HoodieActiveTimeline.createNewInstantTime();
+    final String restoreInstantTime;
     Timer.Context timerContext = metrics.getRollbackCtx();
+    Option<HoodieRestorePlan> restorePlanOption;
     try {
-      HoodieTable<T, I, K, O> table = initTable(WriteOperationType.UNKNOWN, 
Option.of(restoreInstantTime), initialMetadataTableIfNecessary);
-      Option<HoodieRestorePlan> restorePlanOption = 
table.scheduleRestore(context, restoreInstantTime, instantTime);
+      //Use the previous restore if it failed
+      HoodieTable<T, I, K, O> table = initTable(WriteOperationType.UNKNOWN, 
Option.empty(), initialMetadataTableIfNecessary);
+      Option<HoodieInstant> failedRestore = 
table.getRestoreTimeline().filterInflightsAndRequested().lastInstant();

Review Comment:
   makes sense. we are good



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java:
##########
@@ -840,11 +841,25 @@ public boolean rollback(final String commitInstantTime, 
Option<HoodiePendingRoll
    */
   public HoodieRestoreMetadata restoreToInstant(final String instantTime, 
boolean initialMetadataTableIfNecessary) throws HoodieRestoreException {
     LOG.info("Begin restore to instant " + instantTime);
-    final String restoreInstantTime = 
HoodieActiveTimeline.createNewInstantTime();
+    final String restoreInstantTime;
     Timer.Context timerContext = metrics.getRollbackCtx();
+    Option<HoodieRestorePlan> restorePlanOption;
     try {
-      HoodieTable<T, I, K, O> table = initTable(WriteOperationType.UNKNOWN, 
Option.of(restoreInstantTime), initialMetadataTableIfNecessary);
-      Option<HoodieRestorePlan> restorePlanOption = 
table.scheduleRestore(context, restoreInstantTime, instantTime);
+      //Use the previous restore if it failed
+      HoodieTable<T, I, K, O> table = initTable(WriteOperationType.UNKNOWN, 
Option.empty(), initialMetadataTableIfNecessary);
+      Option<HoodieInstant> failedRestore = 
table.getRestoreTimeline().filterInflightsAndRequested().lastInstant();
+      if (failedRestore.isPresent() && 
instantTime.equals(RestoreUtils.getRestoreTime(table, failedRestore.get()))) {
+        if (failedRestore.get().isRequested()) {
+          
table.getActiveTimeline().transitionRestoreRequestedToInflight(failedRestore.get());
+        }
+        restoreInstantTime = failedRestore.get().getTimestamp();
+        restorePlanOption = 
Option.of(RestoreUtils.getRestorePlan(table.getMetaClient(), 
failedRestore.get()));
+      } else {
+        restoreInstantTime = HoodieActiveTimeline.createNewInstantTime();
+        table = initTable(WriteOperationType.UNKNOWN, 
Option.of(restoreInstantTime), initialMetadataTableIfNecessary);
+        restorePlanOption = table.scheduleRestore(context, restoreInstantTime, 
instantTime);

Review Comment:
   can we move this to a separate private method to keep this main method lean. 



##########
hudi-common/src/main/avro/HoodieRestorePlan.avsc:
##########
@@ -29,9 +29,14 @@
              "items": "HoodieInstantInfo"
            }
     },
+    {
+            "name": "savepointTimestamp",

Review Comment:
   savepointToRestoreTimestamp



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