chenboat commented on a change in pull request #4608: Unit tests and bug fixes
for DeleteTable rest API for controller.
URL: https://github.com/apache/incubator-pinot/pull/4608#discussion_r332288358
##########
File path:
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
##########
@@ -254,20 +254,49 @@ public SuccessResponse deleteTable(
List<String> tablesDeleted = new LinkedList<>();
try {
- if (tableType != TableType.REALTIME &&
!TableNameBuilder.REALTIME.tableHasTypeSuffix(tableName)) {
+ boolean tableExist = false;
+ if (verifyTableType(tableName, tableType, tableType.OFFLINE)) {
+ tableExist = _pinotHelixResourceManager.hasOfflineTable(tableName);
+ // Even the table name does not exist, still go on to delete remaining
table metadata in case a previous delete
+ // did not complete.
_pinotHelixResourceManager.deleteOfflineTable(tableName);
-
tablesDeleted.add(TableNameBuilder.OFFLINE.tableNameWithType(tableName));
+ if (tableExist) {
+
tablesDeleted.add(TableNameBuilder.OFFLINE.tableNameWithType(tableName));
+ }
}
- if (tableType != TableType.OFFLINE &&
!TableNameBuilder.OFFLINE.tableHasTypeSuffix(tableName)) {
+ if (verifyTableType(tableName, tableType, tableType.REALTIME)) {
+ tableExist = _pinotHelixResourceManager.hasRealtimeTable(tableName);
+ // Even the table name does not exist, still go on to delete remaining
table metadata in case a previous delete
+ // did not complete.
_pinotHelixResourceManager.deleteRealtimeTable(tableName);
-
tablesDeleted.add(TableNameBuilder.REALTIME.tableNameWithType(tableName));
+ if (tableExist) {
+
tablesDeleted.add(TableNameBuilder.REALTIME.tableNameWithType(tableName));
+ }
+ }
+ if (!tableExist) {
+ throw new ControllerApplicationException(LOGGER,
+ "Table '" + tableName + "' with type " + tableType + " does not
exist", Response.Status.NOT_FOUND);
}
return new SuccessResponse("Tables: " + tablesDeleted + " deleted");
} catch (Exception e) {
throw new ControllerApplicationException(LOGGER, e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR, e);
}
}
+ // Return true iff the table is of the expectedType based on the given
tableName and tableType. The truth table:
+ // tableType
TableNameBuilder.getTableTypeFromTableName(tableName) Return value
+ // 1. null null (i.e., table has no type
suffix) true
+ // 2. null not_null
typeFromTableName == expectedType
+ // 3. not_null null
tableType == expectedType
+ // 4. not_null not_null
tableType==typeFromTableName==expectedType
+ private boolean verifyTableType(String tableName, TableType tableType,
TableType expectedType) {
Review comment:
Use tab instead of space now. There is no template for comments as far as I
know.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]