diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java index f00f08f..590e9ce 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java @@ -116,7 +116,7 @@ private static ReentrantReadWriteLock partitionColStatsCacheLock = new ReentrantReadWriteLock( true); private static AtomicBoolean isPartitionColStatsCacheDirty = new AtomicBoolean(false); - RawStore rawStore; + RawStore rawStore = null; Configuration conf; private PartitionExpressionProxy expressionProxy = null; // Default value set to 100 milliseconds for test purpose @@ -197,11 +197,13 @@ public CachedStore() { public void setConf(Configuration conf) { String rawStoreClassName = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORE_CACHED_RAW_STORE_IMPL, ObjectStore.class.getName()); - try { - rawStore = ((Class) MetaStoreUtils.getClass( - rawStoreClassName)).newInstance(); - } catch (Exception e) { - throw new RuntimeException("Cannot instantiate " + rawStoreClassName, e); + if (rawStore == null) { + try { + rawStore = ((Class) MetaStoreUtils.getClass( + rawStoreClassName)).newInstance(); + } catch (Exception e) { + throw new RuntimeException("Cannot instantiate " + rawStoreClassName, e); + } } rawStore.setConf(conf); Configuration oldConf = this.conf; @@ -330,8 +332,9 @@ public void run() { String rawStoreClassName = HiveConf.getVar(cachedStore.conf, HiveConf.ConfVars.METASTORE_CACHED_RAW_STORE_IMPL, ObjectStore.class.getName()); + RawStore rawStore = null; try { - RawStore rawStore = + rawStore = ((Class) MetaStoreUtils.getClass(rawStoreClassName)).newInstance(); rawStore.setConf(cachedStore.conf); List dbNames = rawStore.getAllDatabases(); @@ -356,6 +359,14 @@ public void run() { LOG.error("Updating CachedStore: error getting database names", e); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Cannot instantiate " + rawStoreClassName, e); + } finally { + try { + if (rawStore != null) { + rawStore.shutdown(); + } + } catch (Exception e) { + LOG.error("Error shutting down RawStore", e); + } } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java index 479a938..d7592bb 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java @@ -56,6 +56,7 @@ import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hadoop.hive.metastore.ObjectStore; import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj; +import org.apache.hadoop.hive.metastore.cache.CachedStore; import org.apache.hadoop.hive.ql.MapRedStats; import org.apache.hadoop.hive.ql.exec.Registry; import org.apache.hadoop.hive.ql.exec.Utilities; @@ -1684,7 +1685,9 @@ private void unCacheDataNucleusClassLoaders() { Hive threadLocalHive = Hive.get(sessionConf); if ((threadLocalHive != null) && (threadLocalHive.getMSC() != null) && (threadLocalHive.getMSC().isLocalMetaStore())) { - if (sessionConf.getVar(ConfVars.METASTORE_RAW_STORE_IMPL).equals(ObjectStore.class.getName())) { + if (sessionConf.getVar(ConfVars.METASTORE_RAW_STORE_IMPL).equals(ObjectStore.class.getName()) + || sessionConf.getVar(ConfVars.METASTORE_RAW_STORE_IMPL).equals(CachedStore.class.getName()) && + sessionConf.getVar(ConfVars.METASTORE_CACHED_RAW_STORE_IMPL).equals(ObjectStore.class.getName())) { ObjectStore.unCacheDataNucleusClassLoaders(); } }