diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/Deadline.java b/metastore/src/java/org/apache/hadoop/hive/metastore/Deadline.java index 71d336a..6149224 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/Deadline.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/Deadline.java @@ -86,15 +86,15 @@ public static void registerIfNot(long timeout) { */ public static void resetTimeout(long timeoutMs) throws MetaException { if (timeoutMs <= 0) { - throw newMetaException(new DeadlineException("The reset timeout value should be " + + throw MetaStoreUtils.newMetaException(new DeadlineException("The reset timeout value should be " + "larger than 0: " + timeoutMs)); } Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.timeoutNanos = timeoutMs * 1000000L; } else { - throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + - " please register it firstly.")); + throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + + " please register it first.")); } } @@ -105,8 +105,8 @@ public static void resetTimeout(long timeoutMs) throws MetaException { public static boolean startTimer(String method) throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline == null) { - throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + - " please register it firstly.")); + throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + + " please register it first.")); } if (deadline.startTime != NO_DEADLINE) return false; deadline.method = method; @@ -125,8 +125,8 @@ public static void stopTimer() throws MetaException { deadline.startTime = NO_DEADLINE; deadline.method = null; } else { - throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + - " please register it firstly.")); + throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + + " please register it first.")); } } @@ -146,7 +146,7 @@ public static void checkTimeout() throws MetaException { if (deadline != null) { deadline.check(); } else { - throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + + throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } } @@ -165,18 +165,7 @@ private void check() throws MetaException{ + (elapsedTime / 1000000L) + "ms exceeds " + (timeoutNanos / 1000000L) + "ms"); } } catch (DeadlineException e) { - throw newMetaException(e); + throw MetaStoreUtils.newMetaException(e); } } - - /** - * convert DeadlineException to MetaException - * @param e - * @return - */ - private static MetaException newMetaException(DeadlineException e) { - MetaException metaException = new MetaException(e.getMessage()); - metaException.initCause(e); - return metaException; - } } diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java index 1b701e0..e0b04ca 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java @@ -1937,4 +1937,28 @@ public static void mergeColStats(ColumnStatistics csNew, ColumnStatistics csOld) } csNew.setStatsObj(list); } + + /** + * convert Exception to MetaException, which sets the cause to such exception + * @param e cause of the exception + * @return the MetaException with the specified exception as the cause + */ + public static MetaException newMetaException(Exception e) { + return newMetaException(e != null ? e.getMessage() : null, e); + } + + /** + * convert Exception to MetaException, which sets the cause to such exception + * @param errorMessage the error message for this MetaException + * @param e cause of the exception + * @return the MetaException with the specified exception as the cause + */ + public static MetaException newMetaException(String errorMessage, Exception e) { + MetaException metaException = new MetaException(errorMessage); + if (e != null) { + metaException.initCause(e); + } + return metaException; + } + } diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index 8e79e4f..772f543 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -2807,7 +2807,7 @@ public T run(boolean initTable) throws MetaException, NoSuchObjectException { throw ex; } catch (Exception ex) { LOG.error("", ex); - throw new MetaException(ex.getMessage()); + throw MetaStoreUtils.newMetaException(ex); } finally { close(); } @@ -2837,7 +2837,7 @@ private void handleDirectSqlError(Exception ex) throws MetaException, NoSuchObje if (ex instanceof MetaException) { throw (MetaException)ex; } - throw new MetaException(ex.getMessage()); + throw MetaStoreUtils.newMetaException(ex); } if (!isInTxn) { JDOException rollbackEx = null; @@ -3382,12 +3382,8 @@ public void alterPartition(String dbname, String name, List part_vals, P } finally { if (!success) { rollbackTransaction(); - MetaException metaException = new MetaException( - "The transaction for alter partition did not commit successfully."); - if (e != null) { - metaException.initCause(e); - } - throw metaException; + throw MetaStoreUtils.newMetaException( + "The transaction for alter partition did not commit successfully.", e); } } } @@ -3411,12 +3407,8 @@ public void alterPartitions(String dbname, String name, List> part_ } finally { if (!success) { rollbackTransaction(); - MetaException metaException = new MetaException( - "The transaction for alter partition did not commit successfully."); - if (e != null) { - metaException.initCause(e); - } - throw metaException; + throw MetaStoreUtils.newMetaException( + "The transaction for alter partition did not commit successfully.", e); } } } @@ -7217,7 +7209,7 @@ public boolean updatePartitionColumnStatistics(ColumnStatistics colStats, List