You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "rtrivedi12 (via GitHub)" <gi...@apache.org> on 2026/08/03 16:20:28 UTC

[PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

rtrivedi12 opened a new pull request, #6672:
URL: https://github.com/apache/hive/pull/6672

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   Extract catalog CRUD operations from HMSHandler into three dedicated handler classes ( CreateCatalogHandler, DropCatalogHandler, AlterCatalogHandler) following the existing @RequestHandler / AbstractRequestHandler pattern used across HIVE-29402.
   
   
   ### Why are the changes needed?
   HMSHandler Refactoring work - HIVE-29402
   
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   ### How was this patch tested?
   mvn test -pl standalone-metastore/metastore-server -am \
     -Dtest=TestCatalogs
   


-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

Posted by "dengzhhu653 (via GitHub)" <gi...@apache.org>.
dengzhhu653 merged PR #6672:
URL: https://github.com/apache/hive/pull/6672


-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6672:
URL: https://github.com/apache/hive/pull/6672#issuecomment-5174547814

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6672) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6672&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6672&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6672&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6672&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6672&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6672)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6672:
URL: https://github.com/apache/hive/pull/6672#issuecomment-5169559060

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6672) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [4 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6672&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6672&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6672&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6672&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6672&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6672)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6672:
URL: https://github.com/apache/hive/pull/6672#discussion_r3710444832


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/handler/DropCatalogHandler.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.handler;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.metastore.HMSHandler;
+import org.apache.hadoop.hive.metastore.IHMSHandler;
+import org.apache.hadoop.hive.metastore.MetaStoreListenerNotifier;
+import org.apache.hadoop.hive.metastore.RawStore;
+import org.apache.hadoop.hive.metastore.api.Catalog;
+import org.apache.hadoop.hive.metastore.api.DropCatalogRequest;
+import org.apache.hadoop.hive.metastore.api.DropDatabaseRequest;
+import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.events.DropCatalogEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropCatalogEvent;
+import org.apache.hadoop.hive.metastore.messaging.EventMessage.EventType;
+import org.apache.thrift.TException;
+
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME;
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_NAME;
+import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.prependNotNullCatToDbName;
+
+@SuppressWarnings("unused")
+@RequestHandler(requestBody = DropCatalogRequest.class)
+public class DropCatalogHandler
+    extends AbstractRequestHandler<DropCatalogRequest, DropCatalogHandler.DropCatalogResult> {
+  private RawStore ms;
+  private Catalog cat;
+  private String catName;
+
+  DropCatalogHandler(IHMSHandler handler, DropCatalogRequest request) {
+    super(handler, false, request);
+  }
+
+  @Override
+  protected void beforeExecute() throws TException, IOException {
+    this.catName = request.getName();
+    this.ms = handler.getMS();
+    if (DEFAULT_CATALOG_NAME.equalsIgnoreCase(catName)) {
+      throw new MetaException("Can not drop " + DEFAULT_CATALOG_NAME + " catalog");
+    }
+  }
+
+  @Override
+  protected DropCatalogResult execute() throws TException, IOException {
+    boolean success = false;
+    Map<String, String> transactionalListenerResponses = Collections.emptyMap();
+    try {
+      ms.openTransaction();
+      cat = ms.getCatalog(catName);
+
+      ((HMSHandler) handler).firePreEvent(new PreDropCatalogEvent(handler, cat));
+
+      List<String> allDbs = ((HMSHandler) handler).get_databases(prependNotNullCatToDbName(catName, null));
+      if (allDbs != null && !allDbs.isEmpty()) {
+        // Only the default database may remain; drop it if it is empty
+        if (allDbs.size() == 1 && allDbs.get(0).equals(DEFAULT_DATABASE_NAME)) {
+          try {
+            DropDatabaseRequest req = new DropDatabaseRequest();
+            req.setName(DEFAULT_DATABASE_NAME);
+            req.setCatalogName(catName);
+            req.setDeleteData(true);
+            req.setCascade(false);
+            ((HMSHandler) handler).drop_database_req(req);
+          } catch (InvalidOperationException e) {
+            throw new InvalidOperationException("There are still objects in the default " +
+                "database for catalog " + catName);
+          }
+        } else {
+          throw new InvalidOperationException("There are non-default databases in the catalog " +
+              catName + " so it cannot be dropped.");
+        }
+      }
+
+      ms.dropCatalog(catName);
+      if (!handler.getTransactionalListeners().isEmpty()) {
+        transactionalListenerResponses =
+            MetaStoreListenerNotifier.notifyEvent(handler.getTransactionalListeners(),
+                EventType.DROP_CATALOG,
+                new DropCatalogEvent(true, handler, cat));
+      }
+
+      success = ms.commitTransaction();
+    } catch (NoSuchObjectException e) {
+      if (!request.isIfExists()) {
+        throw new NoSuchObjectException(e.getMessage());
+      }
+      success = true;
+    } finally {
+      if (success && cat != null) {
+        handler.getWh().deleteDir(handler.getWh().getDnsPath(new Path(cat.getLocationUri())), false, false);
+      } else {
+        ms.rollbackTransaction();
+      }
+    }
+    return new DropCatalogResult(success, transactionalListenerResponses);
+  }
+
+  @Override
+  protected void afterExecute(DropCatalogResult result) throws TException, IOException {
+    if (!handler.getListeners().isEmpty()) {
+      MetaStoreListenerNotifier.notifyEvent(handler.getListeners(),
+          EventType.DROP_CATALOG,
+          new DropCatalogEvent(result != null && result.success(), handler, cat),
+          null,
+          result != null ? result.transactionalListenerResponses() : Collections.emptyMap(), ms);
+    }
+    super.afterExecute(result);
+  }

Review Comment:
   In the ifExists=true / catalog-not-found case, execute() currently returns success=true (no exception) but `cat` remains null; afterExecute() then emits `DropCatalogEvent` with success=true and a null catalog. Previously (in HMSHandler.dropCatalogCore) the listener event used success=false when nothing was dropped. Suggest gating the event's success flag on `cat != null` so listeners don't interpret a no-op as a successful drop.



-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

Posted by "rtrivedi12 (via GitHub)" <gi...@apache.org>.
rtrivedi12 commented on code in PR #6672:
URL: https://github.com/apache/hive/pull/6672#discussion_r3722093877


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/handler/DropCatalogHandler.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.handler;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.metastore.HMSHandler;
+import org.apache.hadoop.hive.metastore.IHMSHandler;
+import org.apache.hadoop.hive.metastore.MetaStoreListenerNotifier;
+import org.apache.hadoop.hive.metastore.RawStore;
+import org.apache.hadoop.hive.metastore.api.Catalog;
+import org.apache.hadoop.hive.metastore.api.DropCatalogRequest;
+import org.apache.hadoop.hive.metastore.api.DropDatabaseRequest;
+import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.events.DropCatalogEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropCatalogEvent;
+import org.apache.hadoop.hive.metastore.messaging.EventMessage.EventType;
+import org.apache.thrift.TException;
+
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME;
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_NAME;
+import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.prependNotNullCatToDbName;
+
+@SuppressWarnings("unused")
+@RequestHandler(requestBody = DropCatalogRequest.class)
+public class DropCatalogHandler
+    extends AbstractRequestHandler<DropCatalogRequest, DropCatalogHandler.DropCatalogResult> {
+  private RawStore ms;
+  private Catalog cat;
+  private String catName;
+
+  DropCatalogHandler(IHMSHandler handler, DropCatalogRequest request) {
+    super(handler, false, request);
+  }
+
+  @Override
+  protected void beforeExecute() throws TException, IOException {
+    this.catName = request.getName();
+    this.ms = handler.getMS();
+    if (DEFAULT_CATALOG_NAME.equalsIgnoreCase(catName)) {
+      throw new MetaException("Can not drop " + DEFAULT_CATALOG_NAME + " catalog");
+    }
+  }
+
+  @Override
+  protected DropCatalogResult execute() throws TException, IOException {
+    boolean success = false;
+    Map<String, String> transactionalListenerResponses = Collections.emptyMap();
+    try {
+      ms.openTransaction();
+      cat = ms.getCatalog(catName);
+
+      ((HMSHandler) handler).firePreEvent(new PreDropCatalogEvent(handler, cat));
+
+      List<String> allDbs = ((HMSHandler) handler).get_databases(prependNotNullCatToDbName(catName, null));
+      if (allDbs != null && !allDbs.isEmpty()) {
+        // Only the default database may remain; drop it if it is empty
+        if (allDbs.size() == 1 && allDbs.get(0).equals(DEFAULT_DATABASE_NAME)) {
+          try {
+            DropDatabaseRequest req = new DropDatabaseRequest();
+            req.setName(DEFAULT_DATABASE_NAME);
+            req.setCatalogName(catName);
+            req.setDeleteData(true);
+            req.setCascade(false);
+            ((HMSHandler) handler).drop_database_req(req);
+          } catch (InvalidOperationException e) {
+            throw new InvalidOperationException("There are still objects in the default " +
+                "database for catalog " + catName);
+          }
+        } else {
+          throw new InvalidOperationException("There are non-default databases in the catalog " +
+              catName + " so it cannot be dropped.");
+        }
+      }
+
+      ms.dropCatalog(catName);
+      if (!handler.getTransactionalListeners().isEmpty()) {
+        transactionalListenerResponses =
+            MetaStoreListenerNotifier.notifyEvent(handler.getTransactionalListeners(),
+                EventType.DROP_CATALOG,
+                new DropCatalogEvent(true, handler, cat));
+      }
+
+      success = ms.commitTransaction();
+    } catch (NoSuchObjectException e) {
+      if (!request.isIfExists()) {
+        throw new NoSuchObjectException(e.getMessage());
+      }
+      success = true;
+    } finally {
+      if (success && cat != null) {
+        handler.getWh().deleteDir(handler.getWh().getDnsPath(new Path(cat.getLocationUri())), false, false);
+      } else {
+        ms.rollbackTransaction();
+      }
+    }
+    return new DropCatalogResult(success, transactionalListenerResponses);
+  }
+
+  @Override
+  protected void afterExecute(DropCatalogResult result) throws TException, IOException {
+    if (!handler.getListeners().isEmpty()) {
+      MetaStoreListenerNotifier.notifyEvent(handler.getListeners(),
+          EventType.DROP_CATALOG,
+          new DropCatalogEvent(result != null && result.success(), handler, cat),
+          null,
+          result != null ? result.transactionalListenerResponses() : Collections.emptyMap(), ms);
+    }
+    super.afterExecute(result);
+  }

Review Comment:
   Sure, will address this in #6674! Thanks for the review @dengzhhu653 !



-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29453: Separate create/drop catalog from HMSHandler [hive]

Posted by "dengzhhu653 (via GitHub)" <gi...@apache.org>.
dengzhhu653 commented on code in PR #6672:
URL: https://github.com/apache/hive/pull/6672#discussion_r3717553204


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/handler/DropCatalogHandler.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.handler;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.metastore.HMSHandler;
+import org.apache.hadoop.hive.metastore.IHMSHandler;
+import org.apache.hadoop.hive.metastore.MetaStoreListenerNotifier;
+import org.apache.hadoop.hive.metastore.RawStore;
+import org.apache.hadoop.hive.metastore.api.Catalog;
+import org.apache.hadoop.hive.metastore.api.DropCatalogRequest;
+import org.apache.hadoop.hive.metastore.api.DropDatabaseRequest;
+import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.events.DropCatalogEvent;
+import org.apache.hadoop.hive.metastore.events.PreDropCatalogEvent;
+import org.apache.hadoop.hive.metastore.messaging.EventMessage.EventType;
+import org.apache.thrift.TException;
+
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_CATALOG_NAME;
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_NAME;
+import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.prependNotNullCatToDbName;
+
+@SuppressWarnings("unused")
+@RequestHandler(requestBody = DropCatalogRequest.class)
+public class DropCatalogHandler
+    extends AbstractRequestHandler<DropCatalogRequest, DropCatalogHandler.DropCatalogResult> {
+  private RawStore ms;
+  private Catalog cat;
+  private String catName;
+
+  DropCatalogHandler(IHMSHandler handler, DropCatalogRequest request) {
+    super(handler, false, request);
+  }
+
+  @Override
+  protected void beforeExecute() throws TException, IOException {
+    this.catName = request.getName();
+    this.ms = handler.getMS();
+    if (DEFAULT_CATALOG_NAME.equalsIgnoreCase(catName)) {
+      throw new MetaException("Can not drop " + DEFAULT_CATALOG_NAME + " catalog");
+    }
+  }
+
+  @Override
+  protected DropCatalogResult execute() throws TException, IOException {
+    boolean success = false;
+    Map<String, String> transactionalListenerResponses = Collections.emptyMap();
+    try {
+      ms.openTransaction();
+      cat = ms.getCatalog(catName);
+
+      ((HMSHandler) handler).firePreEvent(new PreDropCatalogEvent(handler, cat));
+
+      List<String> allDbs = ((HMSHandler) handler).get_databases(prependNotNullCatToDbName(catName, null));
+      if (allDbs != null && !allDbs.isEmpty()) {
+        // Only the default database may remain; drop it if it is empty
+        if (allDbs.size() == 1 && allDbs.get(0).equals(DEFAULT_DATABASE_NAME)) {
+          try {
+            DropDatabaseRequest req = new DropDatabaseRequest();
+            req.setName(DEFAULT_DATABASE_NAME);
+            req.setCatalogName(catName);
+            req.setDeleteData(true);
+            req.setCascade(false);
+            ((HMSHandler) handler).drop_database_req(req);
+          } catch (InvalidOperationException e) {
+            throw new InvalidOperationException("There are still objects in the default " +
+                "database for catalog " + catName);
+          }
+        } else {
+          throw new InvalidOperationException("There are non-default databases in the catalog " +
+              catName + " so it cannot be dropped.");
+        }
+      }
+
+      ms.dropCatalog(catName);
+      if (!handler.getTransactionalListeners().isEmpty()) {
+        transactionalListenerResponses =
+            MetaStoreListenerNotifier.notifyEvent(handler.getTransactionalListeners(),
+                EventType.DROP_CATALOG,
+                new DropCatalogEvent(true, handler, cat));
+      }
+
+      success = ms.commitTransaction();
+    } catch (NoSuchObjectException e) {
+      if (!request.isIfExists()) {
+        throw new NoSuchObjectException(e.getMessage());
+      }
+      success = true;
+    } finally {
+      if (success && cat != null) {
+        handler.getWh().deleteDir(handler.getWh().getDnsPath(new Path(cat.getLocationUri())), false, false);
+      } else {
+        ms.rollbackTransaction();
+      }
+    }
+    return new DropCatalogResult(success, transactionalListenerResponses);
+  }
+
+  @Override
+  protected void afterExecute(DropCatalogResult result) throws TException, IOException {
+    if (!handler.getListeners().isEmpty()) {
+      MetaStoreListenerNotifier.notifyEvent(handler.getListeners(),
+          EventType.DROP_CATALOG,
+          new DropCatalogEvent(result != null && result.success(), handler, cat),
+          null,
+          result != null ? result.transactionalListenerResponses() : Collections.emptyMap(), ms);
+    }
+    super.afterExecute(result);
+  }

Review Comment:
   This is a minor change, if it's possible, please incorporate it to #6674 



-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org