diff --git a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestSemanticAnalysis.java b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestSemanticAnalysis.java index 3cc548e..efe0c42 100644 --- a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestSemanticAnalysis.java +++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestSemanticAnalysis.java @@ -124,7 +124,7 @@ public void testUsNonExistentDB() throws CommandNeedRetryException { } @Test - public void testDatabaseOperations() throws MetaException, CommandNeedRetryException { + public void testDatabaseOperations() throws MetaException, TException, CommandNeedRetryException { List dbs = client.getAllDatabases(); String testDb1 = "testdatabaseoperatons1"; diff --git a/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java b/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java index c4b5971..13d05fb 100644 --- a/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java +++ b/hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java @@ -66,6 +66,9 @@ dbNames = hmsClient.getDatabases(pattern); } catch (MetaException exp) { throw new HCatException("MetaException while listing db names", exp); + } catch (TException exp) { + throw new ConnectionFailureException( + "TException while fetching database", exp); } return dbNames; } @@ -143,6 +146,9 @@ public void dropDatabase(String dbName, boolean ifExists, DropDBMode mode) } catch (MetaException e) { throw new HCatException( "MetaException while fetching table names.", e); + } catch (TException exp) { + throw new ConnectionFailureException( + "TException while fetching database", exp); } return tableNames; } diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 664dccd..8eaf9a8 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -821,24 +821,14 @@ public boolean dropType(String type) throws NoSuchObjectException, MetaException /** {@inheritDoc} */ @Override public List getDatabases(String databasePattern) - throws MetaException { - try { - return client.get_databases(databasePattern); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + throws TException { + return client.get_databases(databasePattern); } /** {@inheritDoc} */ @Override - public List getAllDatabases() throws MetaException { - try { - return client.get_all_databases(); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + public List getAllDatabases() throws TException { + return client.get_all_databases(); } /** @@ -1033,24 +1023,14 @@ public Type getType(String name) throws NoSuchObjectException, MetaException, TE /** {@inheritDoc} */ @Override - public List getTables(String dbname, String tablePattern) throws MetaException { - try { - return client.get_tables(dbname, tablePattern); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + public List getTables(String dbname, String tablePattern) throws TException { + return client.get_tables(dbname, tablePattern); } /** {@inheritDoc} */ @Override - public List getAllTables(String dbname) throws MetaException { - try { - return client.get_all_tables(dbname); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + public List getAllTables(String dbname) throws TException { + return client.get_all_tables(dbname); } @Override diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java b/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java index 5410b45..4b76208 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java @@ -35,6 +35,8 @@ import org.apache.thrift.protocol.TProtocolException; import org.apache.thrift.transport.TTransportException; +import javax.annotation.Nullable; + /** * RetryingMetaStoreClient. Creates a proxy for a IMetaStoreClient * implementation and retries calls to it on failure. @@ -91,15 +93,17 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl } catch (UndeclaredThrowableException e) { throw e.getCause(); } catch (InvocationTargetException e) { - if ((e.getCause() instanceof TApplicationException) || - (e.getCause() instanceof TProtocolException) || - (e.getCause() instanceof TTransportException)) { - caughtException = (TException) e.getCause(); - } else if ((e.getCause() instanceof MetaException) && - e.getCause().getMessage().matches("JDO[a-zA-Z]*Exception")) { - caughtException = (MetaException) e.getCause(); + final Throwable couse = e.getCause(); + if (isFatalException(couse)) { + caughtException = (TException) couse; + } else if ((couse instanceof MetaException) && + isFatalException(couse.getCause())) { + caughtException = (TException) couse.getCause(); + } else if ((couse instanceof MetaException) && + couse.getMessage().matches("JDO[a-zA-Z]*Exception")) { + caughtException = (MetaException) couse; } else { - throw e.getCause(); + throw couse; } } @@ -114,6 +118,14 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl return ret; } + private boolean isFatalException(@Nullable Throwable couse) { + if (couse == null) + return false; + return (couse instanceof TApplicationException) || + (couse instanceof TProtocolException) || + (couse instanceof TTransportException); + } + /** * Relogin if login user is logged in using keytab * Relogin is actually done by ugi code only if sufficient time has passed diff --git a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index a9d5902..60a1d1f 100644 --- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -28,13 +28,20 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.hadoop.hive.metastore.HiveMetaHook; +import org.apache.hadoop.hive.metastore.HiveMetaHookLoader; import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; import org.apache.hadoop.hive.metastore.IMetaStoreClient; +import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.ql.exec.FetchFormatter; import org.apache.hadoop.hive.ql.exec.ListSinkOperator; import org.apache.hadoop.hive.ql.history.HiveHistory; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.metadata.HiveStorageHandler; +import org.apache.hadoop.hive.ql.metadata.HiveUtils; import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.util.StringUtils; import org.apache.hive.common.util.HiveVersionInfo; import org.apache.hive.service.auth.HiveAuthFactory; import org.apache.hive.service.cli.FetchOrientation; @@ -56,6 +63,8 @@ import org.apache.hive.service.cli.operation.OperationManager; import org.apache.hive.service.cli.thrift.TProtocolVersion; +import static org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_STORAGE; + /** * HiveSession * @@ -171,7 +180,32 @@ public HiveConf getHiveConf() { public IMetaStoreClient getMetaStoreClient() throws HiveSQLException { if (metastoreClient == null) { try { - metastoreClient = new HiveMetaStoreClient(getHiveConf()); + final HiveConf hiveConf = getHiveConf(); + HiveMetaHookLoader hookLoader = new HiveMetaHookLoader() { + public HiveMetaHook getHook( + org.apache.hadoop.hive.metastore.api.Table tbl) + throws MetaException { + + try { + if (tbl == null) { + return null; + } + HiveStorageHandler storageHandler = + HiveUtils.getStorageHandler(hiveConf, + tbl.getParameters().get(META_TABLE_STORAGE)); + if (storageHandler == null) { + return null; + } + return storageHandler.getMetaHook(); + } catch (HiveException ex) { + LOG.error(StringUtils.stringifyException(ex)); + throw new MetaException( + "Failed to load storage handler: " + ex.getMessage()); + } + } + }; + metastoreClient = RetryingMetaStoreClient.getProxy(hiveConf, hookLoader, + HiveMetaStoreClient.class.getName()); } catch (MetaException e) { throw new HiveSQLException(e); }