commit c316e237f69650531f9d0d7f07167553b6b76d30 Author: Dan Burkert Date: Fri Jun 30 17:21:15 2017 -0700 HIVE-17008: HiveMetastore.drop_database can return NPE if database does not exist diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 40cfa1a9fe..7a5e3595f3 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -1118,29 +1118,31 @@ private void drop_database_core(RawStore ms, } finally { if (!success) { ms.rollbackTransaction(); - } else if (deleteData) { - // Delete the data in the partitions which have other locations - deletePartitionData(partitionPaths); - // Delete the data in the tables which have other locations - for (Path tablePath : tablePaths) { - deleteTableData(tablePath); - } - // Delete the data in the database - try { - wh.deleteDir(new Path(db.getLocationUri()), true); - } catch (Exception e) { - LOG.error("Failed to delete database directory: " + db.getLocationUri() + - " " + e.getMessage()); + } else { + if (deleteData) { + // Delete the data in the partitions which have other locations + deletePartitionData(partitionPaths); + // Delete the data in the tables which have other locations + for (Path tablePath : tablePaths) { + deleteTableData(tablePath); + } + // Delete the data in the database + try { + wh.deleteDir(new Path(db.getLocationUri()), true); + } catch (Exception e) { + LOG.error("Failed to delete database directory: " + db.getLocationUri() + + " " + e.getMessage()); + } + // it is not a terrible thing even if the data is not deleted } - // it is not a terrible thing even if the data is not deleted - } - if (!listeners.isEmpty()) { - MetaStoreListenerNotifier.notifyEvent(listeners, - EventType.DROP_DATABASE, - new DropDatabaseEvent(db, success, this), - null, - transactionalListenerResponses); + if (!listeners.isEmpty()) { + MetaStoreListenerNotifier.notifyEvent(listeners, + EventType.DROP_DATABASE, + new DropDatabaseEvent(db, success, this), + null, + transactionalListenerResponses); + } } } }