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 cf15ff2..4f53fcb 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 @@ -126,7 +126,7 @@ public void testUsNonExistentDB() throws CommandNeedRetryException { } @Test - public void testDatabaseOperations() throws MetaException, CommandNeedRetryException { + public void testDatabaseOperations() throws CommandNeedRetryException, TException { List dbs = client.getAllDatabases(); String testDb1 = "testdatabaseoperatons1"; 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 c5e7a5f..3a54f2d 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -1065,24 +1065,14 @@ public boolean dropType(String type) throws NoSuchObjectException, MetaException /** {@inheritDoc} */ @Override public List getDatabases(String databasePattern) - throws MetaException { - try { + throws MetaException, TException { return filterHook.filterDatabases(client.get_databases(databasePattern)); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; } /** {@inheritDoc} */ @Override - public List getAllDatabases() throws MetaException { - try { - return filterHook.filterDatabases(client.get_all_databases()); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + public List getAllDatabases() throws MetaException, TException { + return filterHook.filterDatabases(client.get_all_databases()); } /** @@ -1306,24 +1296,14 @@ public Type getType(String name) throws NoSuchObjectException, MetaException, TE /** {@inheritDoc} */ @Override - public List getTables(String dbname, String tablePattern) throws MetaException { - try { - return filterHook.filterTableNames(dbname, client.get_tables(dbname, tablePattern)); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + public List getTables(String dbname, String tablePattern) throws MetaException, TException { + return filterHook.filterTableNames(dbname, client.get_tables(dbname, tablePattern)); } @Override public List getTableMeta(String dbPatterns, String tablePatterns, List tableTypes) - throws MetaException { - try { - return filterNames(client.get_table_meta(dbPatterns, tablePatterns, tableTypes)); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + throws MetaException, TException { + return filterNames(client.get_table_meta(dbPatterns, tablePatterns, tableTypes)); } private List filterNames(List metas) throws MetaException { @@ -1348,13 +1328,8 @@ public Type getType(String name) throws NoSuchObjectException, MetaException, TE /** {@inheritDoc} */ @Override - public List getAllTables(String dbname) throws MetaException { - try { - return filterHook.filterTableNames(dbname, client.get_all_tables(dbname)); - } catch (Exception e) { - MetaStoreUtils.logAndThrowMetaException(e); - } - return null; + public List getAllTables(String dbname) throws MetaException, TException { + return filterHook.filterTableNames(dbname, 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 2b05837..3f5aea2 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/RetryingMetaStoreClient.java @@ -82,8 +82,26 @@ protected RetryingMetaStoreClient(HiveConf hiveConf, Class[] constructorArgTy String msUri = hiveConf.getVar(HiveConf.ConfVars.METASTOREURIS); localMetaStore = (msUri == null) || msUri.trim().isEmpty(); - reloginExpiringKeytabUser(); - this.base = (IMetaStoreClient) MetaStoreUtils.newInstance(msClientClass, constructorArgTypes, constructorArgs); + int retriesMade = 0; + IMetaStoreClient metaStoreClient = null; + while (true) { + try { + reloginExpiringKeytabUser(); + metaStoreClient = (IMetaStoreClient) MetaStoreUtils.newInstance(msClientClass, constructorArgTypes, constructorArgs); + break; + } catch (Exception e) { + if (retriesMade >= retryLimit) { + throw e; + } + retriesMade++; + LOG.warn("Construct for " + msClientClass + " failed, retrying.", e); + try { + Thread.sleep(retryDelaySeconds * 1000); + } catch (InterruptedException ie) { + } + } + } + this.base = metaStoreClient; } public static IMetaStoreClient getProxy(HiveConf hiveConf) throws MetaException { @@ -144,7 +162,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl while (true) { try { reloginExpiringKeytabUser(); - if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) { + if (!localMetaStore && (retriesMade > 0 || hasConnectionLifeTimeReached(method))) { base.reconnect(); lastConnectionTime = System.currentTimeMillis(); } @@ -180,6 +198,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl } else if ((t instanceof MetaException) && t.getMessage().matches( "(?s).*(JDO[a-zA-Z]*|TProtocol|TTransport)Exception.*")) { caughtException = (MetaException)t; + } else if (t instanceof TException) { + caughtException = (TException)t; } else { throw t; } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java index 581a919..b26ea53 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/SessionHiveMetaStoreClient.java @@ -125,7 +125,7 @@ protected void drop_table_with_environment_context(String dbname, String name, } @Override - public List getAllTables(String dbName) throws MetaException { + public List getAllTables(String dbName) throws MetaException, TException { List tableNames = super.getAllTables(dbName); // May need to merge with list of temp tables @@ -147,7 +147,7 @@ protected void drop_table_with_environment_context(String dbname, String name, } @Override - public List getTables(String dbName, String tablePattern) throws MetaException { + public List getTables(String dbName, String tablePattern) throws MetaException, TException { List tableNames = super.getTables(dbName, tablePattern); // May need to merge with list of temp tables @@ -177,7 +177,7 @@ protected void drop_table_with_environment_context(String dbname, String name, @Override public List getTableMeta(String dbPatterns, String tablePatterns, List tableTypes) - throws MetaException { + throws MetaException, TException { List tableMetas = super.getTableMeta(dbPatterns, tablePatterns, tableTypes); Map> tmpTables = getTempTables(); if (tmpTables.isEmpty()) {