You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/06/02 00:14:00 UTC

[jira] [Work logged] (HIVE-25055) Improve the exception handling in HMSHandler

     [ https://issues.apache.org/jira/browse/HIVE-25055?focusedWorklogId=604834&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-604834 ]

ASF GitHub Bot logged work on HIVE-25055:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Jun/21 00:13
            Start Date: 02/Jun/21 00:13
    Worklog Time Spent: 10m 
      Work Description: vihangk1 commented on a change in pull request #2218:
URL: https://github.com/apache/hive/pull/2218#discussion_r643488870



##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
##########
@@ -914,6 +914,7 @@ private boolean isViewTable(String catName, String dbName, String tblName) throw
     long queryTime = doTrace ? System.nanoTime() : 0;
     MetastoreDirectSqlUtils.timingTrace(doTrace, queryText, start, queryTime);
     if (sqlResult.isEmpty()) {
+      query.closeAll();

Review comment:
       It looks like this is fixing a unrelated bug. Can we move this out of this PR and create a different JIRA for this?

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ExceptionHandler.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.utils.JavaUtils;
+import org.apache.thrift.TException;
+
+import static java.util.Objects.requireNonNull;
+
+public final class ExceptionHandler {

Review comment:
       Can you add a class level comment?

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ExceptionHandler.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.utils.JavaUtils;
+import org.apache.thrift.TException;
+
+import static java.util.Objects.requireNonNull;
+
+public final class ExceptionHandler {
+  private final Exception e;
+
+  private ExceptionHandler(Exception e) {
+    this.e = e;
+  }
+
+  public static ExceptionHandler handleException(Exception e) {
+    requireNonNull(e, "Exception e is null");
+    return new ExceptionHandler(e);
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clz
+   */
+  public <T extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t) throws T {
+    if (t.isInstance(e)) {
+      throw t.cast(e);
+    }
+    return this;
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clzt or  class clze in order
+   */
+  public <T extends Exception, E extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t, Class<E> e) throws T, E {
+    throwIfInstance(t);
+    throwIfInstance(e);
+    return this;
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clzt or  clze or clzc in order
+   */
+  public <T extends Exception, E extends Exception, C extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t, Class<E> e, Class<C> c) throws T, E, C {
+    throwIfInstance(t);
+    throwIfInstance(e);
+    throwIfInstance(c);
+    return this;
+  }
+
+  /**
+   * Converts the input e if it is the instance of class from to the instance of class to and throws
+   */
+  public <T extends Exception, D extends TException> ExceptionHandler
+      convertIfInstance(Class<T> from, Class<D> to) throws D {
+    D targetException = null;
+    if (from.isInstance(e)) {
+      try {
+        targetException = JavaUtils.newInstance(to, new Class[]{String.class}, new Object[]{e.getMessage()});
+      } catch (Exception ex) {
+        // this should not happen
+        throw new RuntimeException(ex);
+      }
+    }
+    if (targetException != null) {
+      throw targetException;
+    }
+
+    return this;
+  }
+
+  /**
+   * Converts the input e if it is the instance of classes to MetaException with the given message
+   */
+  public ExceptionHandler convertToMetaExIfInstance(String message, Class<?>... classes)
+      throws MetaException {
+    if (classes != null && classes.length > 0) {
+      for (Class<?> clz : classes) {
+        if (clz.isInstance(e)) {
+          // throw the exception if matches
+          throw new MetaException(message);
+        }
+      }
+    }
+    return this;
+  }
+
+  public static TException rethrowException(Exception e) throws TException {

Review comment:
       semantically the name rethrowException suggests we are throwing some exception, however we are returning exception here as well. This causes weird reading statements like throw rethrowException(e); Can we fix this by throwing MetaException instead of returning defaultMetaException()? Also, a comment for this method will be helpful since it not very easily understandable otherwise.

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ExceptionHandler.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.utils.JavaUtils;
+import org.apache.thrift.TException;
+
+import static java.util.Objects.requireNonNull;
+
+public final class ExceptionHandler {
+  private final Exception e;
+
+  private ExceptionHandler(Exception e) {
+    this.e = e;
+  }
+
+  public static ExceptionHandler handleException(Exception e) {
+    requireNonNull(e, "Exception e is null");
+    return new ExceptionHandler(e);
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clz
+   */
+  public <T extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t) throws T {
+    if (t.isInstance(e)) {
+      throw t.cast(e);
+    }
+    return this;
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clzt or  class clze in order
+   */
+  public <T extends Exception, E extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t, Class<E> e) throws T, E {
+    throwIfInstance(t);
+    throwIfInstance(e);
+    return this;
+  }
+
+  /**
+   * Throws if the input e is the instance of the class clzt or  clze or clzc in order
+   */
+  public <T extends Exception, E extends Exception, C extends Exception> ExceptionHandler
+      throwIfInstance(Class<T> t, Class<E> e, Class<C> c) throws T, E, C {

Review comment:
       I see that you have a 2 argument and 3 argument version of this. Could we improve this by
   public <T extends Exception> ExceptionHandler throwIfInstance(Class<T> ... te) throws T {
      for (Class<T> t : te) {
          throwIfInstance(t);
       }
       return this;
   }

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandler.java
##########
@@ -667,15 +630,6 @@ public Configuration getConf() {
     return conf;
   }
 
-  private Map<String, String> getModifiedConf() {

Review comment:
       Thanks for cleaning this up. I sure looked confusing to me.

##########
File path: standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java
##########
@@ -1453,6 +1454,7 @@ public ColumnStatistics getTableStats(final String catName, final String dbName,
     };
     List<Object[]> list = Batchable.runBatched(batchSize, colNames, b);
     if (list.isEmpty()) {
+      b.closeAllQueries();

Review comment:
       Same as earlier comment.




-- 
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 604834)
    Time Spent: 1h 50m  (was: 1h 40m)

> Improve the exception handling in HMSHandler
> --------------------------------------------
>
>                 Key: HIVE-25055
>                 URL: https://issues.apache.org/jira/browse/HIVE-25055
>             Project: Hive
>          Issue Type: Improvement
>          Components: Standalone Metastore
>            Reporter: Zhihua Deng
>            Assignee: Zhihua Deng
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)