From 53e48315cf38041f219066b3131ba92c3dd3f4f0 Mon Sep 17 00:00:00 2001 From: Alexander Kolbasov Date: Thu, 19 Jul 2018 23:36:06 -0700 Subject: [PATCH 1/1] HIVE-20194: HiveMetastoreClient should use reflection to instantiate embedded HMS instance --- .../java/org/apache/hadoop/hive/metastore/HiveMetaStore.java | 8 +++----- .../org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java | 10 +++++++--- .../hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 3e4428fa4a..8bff90fc60 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -8738,15 +8738,13 @@ private static IHMSHandler newRetryingHMSHandler(IHMSHandler baseHandler, Config * using reflection. It can not be removed and its arguments can't be changed without matching * change in HiveMetastoreClient and HiveMetaStoreClientPreCatalog. * - * @param name HMS name * @param conf configuration to use - * @param local whether it is using local or remote metastore * @throws MetaException */ - static Iface newRetryingHMSHandler(String name, Configuration conf, boolean local) + static Iface newRetryingHMSHandler(Configuration conf) throws MetaException { - HMSHandler baseHandler = new HiveMetaStore.HMSHandler(name, conf, false); - return RetryingHMSHandler.getProxy(conf, baseHandler, local); + HMSHandler baseHandler = new HiveMetaStore.HMSHandler("hive client", conf, false); + return RetryingHMSHandler.getProxy(conf, baseHandler, true); } /** diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index bc7820bce9..eb29ed6dbe 100644 --- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -196,14 +196,18 @@ public HiveMetaStoreClient(Configuration conf, HiveMetaHookLoader hookLoader, Bo Class clazz = Class.forName(HIVE_METASTORE_CLASS); //noinspection JavaReflectionMemberAccess Method method = clazz.getDeclaredMethod(HIVE_METASTORE_CREATE_HANDLER_METHOD, - String.class, Configuration.class, Boolean.TYPE); + Configuration.class); method.setAccessible(true); client = - (ThriftHiveMetastore.Iface)method.invoke(null, "hive client", this.conf, true); + (ThriftHiveMetastore.Iface) method.invoke(null, this.conf); + } catch (InvocationTargetException e) { + if (e.getCause() != null) { + MetaStoreUtils.logAndThrowMetaException((Exception)e.getCause()); + } + MetaStoreUtils.logAndThrowMetaException(e); } catch (ClassNotFoundException | NoSuchMethodException - | InvocationTargetException | IllegalAccessException e) { MetaStoreUtils.logAndThrowMetaException(e); } diff --git a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java index f0b1d77949..47c8b05e71 100644 --- a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java +++ b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClientPreCatalog.java @@ -189,7 +189,7 @@ public HiveMetaStoreClientPreCatalog(Configuration conf, HiveMetaHookLoader hook method.setAccessible(true); client = - (ThriftHiveMetastore.Iface)method.invoke(null, "hive client", this.conf, true); + (ThriftHiveMetastore.Iface)method.invoke(null, this.conf); } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException -- 2.16.3