You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by za...@apache.org on 2023/02/02 20:32:18 UTC
[hive] branch master updated: HIVE-26935: Expose root cause of MetaException in RetryingHMSHandler (Wechar Yu reviewed by Stamatis Zampetakis)
This is an automated email from the ASF dual-hosted git repository.
zabetak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new ed6f5a88ab3 HIVE-26935: Expose root cause of MetaException in RetryingHMSHandler (Wechar Yu reviewed by Stamatis Zampetakis)
ed6f5a88ab3 is described below
commit ed6f5a88ab32f3933ab01b0d8e47378b3218b57e
Author: wecharyu <yu...@gmail.com>
AuthorDate: Thu Jan 12 01:38:12 2023 +0800
HIVE-26935: Expose root cause of MetaException in RetryingHMSHandler (Wechar Yu reviewed by Stamatis Zampetakis)
Closes #3938
---
.../hadoop/hive/metastore/RetryingHMSHandler.java | 7 +++--
.../metastore/TestRetriesInRetryingHMSHandler.java | 33 ++++++++++++++++++++++
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java
index d0cc5b39081..5aac50e8e30 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java
@@ -203,11 +203,12 @@ public class RetryingHMSHandler implements InvocationHandler {
}
}
+ Throwable rootCause = ExceptionUtils.getRootCause(caughtException);
+ String errorMessage = ExceptionUtils.getMessage(caughtException) +
+ (rootCause == null ? "" : ("\nRoot cause: " + rootCause));
if (retryCount >= retryLimit) {
LOG.error("HMSHandler Fatal error: " + ExceptionUtils.getStackTrace(caughtException));
- MetaException me = new MetaException(caughtException.toString());
- me.initCause(caughtException);
- throw me;
+ throw new MetaException(errorMessage);
}
assert (retryInterval >= 0);
diff --git a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestRetriesInRetryingHMSHandler.java b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestRetriesInRetryingHMSHandler.java
index f81ce882369..771af9dfd6d 100644
--- a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestRetriesInRetryingHMSHandler.java
+++ b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestRetriesInRetryingHMSHandler.java
@@ -20,15 +20,21 @@ package org.apache.hadoop.hive.metastore;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.sql.BatchUpdateException;
+import java.sql.SQLException;
+import java.sql.SQLIntegrityConstraintViolationException;
import java.util.concurrent.TimeUnit;
import javax.jdo.JDOException;
+import javax.jdo.JDOUserException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.datanucleus.exceptions.NucleusDataStoreException;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -108,4 +114,31 @@ public class TestRetriesInRetryingHMSHandler {
RetryingHMSHandler.getProxy(conf, mockBaseHandler, false);
Mockito.verify(mockBaseHandler, Mockito.times(2)).init();
}
+
+ @Test
+ public void testGetRootCauseInMetaException() throws MetaException {
+ IHMSHandler mockBaseHandler = Mockito.mock(IHMSHandler.class);
+ Mockito.when(mockBaseHandler.getConf()).thenReturn(conf);
+ SQLIntegrityConstraintViolationException sqlException =
+ new SQLIntegrityConstraintViolationException("Cannot delete or update a parent row");
+ BatchUpdateException updateException = new BatchUpdateException(sqlException);
+ NucleusDataStoreException nucleusException = new NucleusDataStoreException(
+ "Clear request failed: DELETE FROM `PARTITION_PARAMS` WHERE `PART_ID`=?", updateException);
+ JDOUserException jdoException = new JDOUserException(
+ "One or more instances could not be deleted", nucleusException);
+ // SQLIntegrityConstraintViolationException wrapped in BatchUpdateException wrapped in
+ // NucleusDataStoreException wrapped in JDOUserException wrapped in MetaException wrapped in InvocationException
+ MetaException me = new MetaException("Dummy exception");
+ me.initCause(jdoException);
+ InvocationTargetException ex = new InvocationTargetException(me);
+ Mockito.doThrow(me).when(mockBaseHandler).getMS();
+
+ IHMSHandler retryingHandler = RetryingHMSHandler.getProxy(conf, mockBaseHandler, false);
+ try {
+ retryingHandler.getMS();
+ Assert.fail("should throw the mocked MetaException");
+ } catch (MetaException e) {
+ Assert.assertTrue(e.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException"));
+ }
+ }
}