You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by we...@apache.org on 2017/05/30 21:17:18 UTC

[09/12] hive git commit: HIVE-16779 : achedStore leak PersistenceManager resources (Daniel Dai, via Thejas Nair)

HIVE-16779 : achedStore leak PersistenceManager resources (Daniel Dai, via Thejas Nair)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/bbf0629a
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/bbf0629a
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/bbf0629a

Branch: refs/heads/hive-14535
Commit: bbf0629a5a2e43531c4fd5e17d727497e89d267d
Parents: a18e772
Author: Thejas M Nair <th...@hortonworks.com>
Authored: Sun May 28 11:44:59 2017 -0700
Committer: Thejas M Nair <th...@hortonworks.com>
Committed: Sun May 28 11:44:59 2017 -0700

----------------------------------------------------------------------
 .../hive/metastore/cache/CachedStore.java       | 25 ++++++++++++++------
 .../hadoop/hive/ql/session/SessionState.java    |  5 +++-
 2 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/bbf0629a/metastore/src/java/org/apache/hadoop/hive/metastore/cache/CachedStore.java
----------------------------------------------------------------------
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 @@ public class CachedStore implements RawStore, Configurable {
   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 class CachedStore implements RawStore, Configurable {
   public void setConf(Configuration conf) {
     String rawStoreClassName = HiveConf.getVar(conf, HiveConf.ConfVars.METASTORE_CACHED_RAW_STORE_IMPL,
         ObjectStore.class.getName());
-    try {
-      rawStore = ((Class<? extends RawStore>) MetaStoreUtils.getClass(
-          rawStoreClassName)).newInstance();
-    } catch (Exception e) {
-      throw new RuntimeException("Cannot instantiate " + rawStoreClassName, e);
+    if (rawStore == null) {
+      try {
+        rawStore = ((Class<? extends RawStore>) 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 class CachedStore implements RawStore, Configurable {
       String rawStoreClassName =
           HiveConf.getVar(cachedStore.conf, HiveConf.ConfVars.METASTORE_CACHED_RAW_STORE_IMPL,
               ObjectStore.class.getName());
+      RawStore rawStore = null;
       try {
-        RawStore rawStore =
+        rawStore =
             ((Class<? extends RawStore>) MetaStoreUtils.getClass(rawStoreClassName)).newInstance();
         rawStore.setConf(cachedStore.conf);
         List<String> dbNames = rawStore.getAllDatabases();
@@ -356,6 +359,14 @@ public class CachedStore implements RawStore, Configurable {
         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);
+        }
       }
     }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/bbf0629a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
----------------------------------------------------------------------
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;
 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 @@ public class SessionState {
       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();
         }
       }