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 d67e03f..870896c 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java @@ -1929,4 +1929,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 29aa642..a83e12e 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -2737,7 +2737,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(); } @@ -2767,7 +2767,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; @@ -3302,12 +3302,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); } } } @@ -3331,12 +3327,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); } } } @@ -6782,8 +6774,10 @@ private void writeMPartitionColumnStatistics(Table table, Partition partition, try { List stats = getMTableColumnStatistics(table, colNames, queryWrapper); - for(MTableColumnStatistics cStat : stats) { - statsMap.put(cStat.getColName(), cStat); + if (stats != null) { + for(MTableColumnStatistics cStat : stats) { + statsMap.put(cStat.getColName(), cStat); + } } } finally { queryWrapper.close(); @@ -6946,7 +6940,7 @@ public boolean updatePartitionColumnStatistics(ColumnStatistics colStats, List mStats = getMTableColumnStatistics(getTable(), colNames, queryWrapper); - if (mStats.isEmpty()) return null; + if (mStats == null || mStats.isEmpty()) return null; // LastAnalyzed is stored per column, but thrift object has it per multiple columns. // Luckily, nobody actually uses it, so we will set to lowest value of all columns for now. ColumnStatisticsDesc desc = StatObjectConverter.getTableColumnStatisticsDesc(mStats.get(0)); @@ -7184,7 +7178,7 @@ public void flushCache() { if (ex instanceof MetaException) { throw (MetaException) ex; } - throw new MetaException(ex.getMessage()); + throw MetaStoreUtils.newMetaException(ex); } finally { if (!committed) { rollbackTransaction(); @@ -7662,7 +7656,7 @@ private MVersionTable getMSchemaVersion() throws NoSuchObjectException, MetaExce throw new MetaException("Version table not found. " + "The metastore is not upgraded to " + MetaStoreSchemaInfo.getHiveSchemaVersion()); } else { - throw e; + throw MetaStoreUtils.newMetaException(e); } } committed = commitTransaction(); diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java b/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java index f19ff6c..b1c8e39 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java @@ -153,8 +153,6 @@ public Result invokeInternal(final Object proxy, final Method method, final Obje } return new Result(object, retryCount); - } catch (javax.jdo.JDOException e) { - caughtException = e; } catch (UndeclaredThrowableException e) { if (e.getCause() != null) { if (e.getCause() instanceof javax.jdo.JDOException) {