yanghua commented on a change in pull request #1397: [HUDI-692] Add delete 
savepoint for cli
URL: https://github.com/apache/incubator-hudi/pull/1397#discussion_r390833231
 
 

 ##########
 File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/SavepointsCommand.java
 ##########
 @@ -127,6 +127,26 @@ public String refreshMetaClient() {
     return "Metadata for table " + 
HoodieCLI.getTableMetaClient().getTableConfig().getTableName() + " refreshed.";
   }
 
+  @CliCommand(value = "savepoint delete", help = "Delete the savepoint")
+  public String deleteSavepoint(@CliOption(key = {"commit"}, help = "Delete a 
savepoint") final String commitTime) throws Exception {
+    HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
+    HoodieTimeline completedInstants = 
metaClient.getActiveTimeline().getSavePointTimeline().filterCompletedInstants();
+    if (completedInstants.empty()) {
+      throw new HoodieException("There are no completed savepoint to run 
delete");
+    }
+    HoodieInstant savePoint = new HoodieInstant(false, 
HoodieTimeline.SAVEPOINT_ACTION, commitTime);
+
+    if (!completedInstants.containsInstant(savePoint)) {
+      return "Commit " + commitTime + " not found in Commits " + 
completedInstants;
+    }
+
+    JavaSparkContext jsc = SparkUtil.initJavaSparkConf("Delete Savepoint");
+    HoodieWriteClient client = createHoodieClient(jsc, 
metaClient.getBasePath());
+    client.deleteSavepoint(commitTime);
+    jsc.close();
 
 Review comment:
   `JavaSparkContext` implements `AutoCloseable` interface, can we use 
`try-with-resource` here to avoid the resource leak?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to