shounakmk219 commented on code in PR #12765:
URL: https://github.com/apache/pinot/pull/12765#discussion_r1547716136


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotDatabaseRestletResource.java:
##########
@@ -59,4 +67,75 @@ public class PinotDatabaseRestletResource {
   public List<String> listDatabaseNames() {
     return _pinotHelixResourceManager.getDatabaseNames();
   }
+
+  @DELETE
+  @Produces(MediaType.APPLICATION_JSON)
+  @Path("/databases/{databaseName}")
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.DELETE_DATABASE)
+  @ApiOperation(value = "Delete all tables in given database name", notes = 
"Delete all tables in given database name")
+  public DeleteDatabaseResponse deleteTablesInDatabase(
+      @ApiParam(value = "Database name", required = true) 
@PathParam("databaseName") String databaseName,
+      @ApiParam(value = "Run in dryRun mode initially to know the list of 
tables that will be deleted in actual run. "
+          + "No tables will be deleted when dryRun=true", required = true)
+      @QueryParam("dryRun") boolean dryRun) {
+    List<String> tablesInDatabase = 
_pinotHelixResourceManager.getAllTables(databaseName);
+    List<String> deletedTables = new ArrayList<>(tablesInDatabase.size());
+    if (dryRun) {
+      deletedTables = tablesInDatabase;
+    } else {
+      for (String table : tablesInDatabase) {
+        boolean isSchemaDeleted = false;
+        try {
+          TableType tableType = 
TableNameBuilder.getTableTypeFromTableName(table);
+          String rawTableName = TableNameBuilder.extractRawTableName(table);
+          _pinotHelixResourceManager.deleteSchema(rawTableName);
+          LOGGER.info("Deleted schema: {}", rawTableName);
+          isSchemaDeleted = true;
+          _pinotHelixResourceManager.deleteTable(table, tableType, null);
+          LOGGER.info("Deleted table: {}", table);
+          deletedTables.add(table);
+        } catch (Exception e) {
+          if (isSchemaDeleted) {
+            LOGGER.error("Failed to delete table {}", table);
+          } else {
+            LOGGER.error("Failed to delete table and schema for {}", table);
+          }
+        }

Review Comment:
   That's a good point. Will add that info to the response payload.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to