gortiz commented on code in PR #12765:
URL: https://github.com/apache/pinot/pull/12765#discussion_r1547450666
##########
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:
I think the result should contain the list the tables and schemas that were
not deleted and ideally a short message indicating why.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]