incubator-hcatalog-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tof...@apache.org
Subject svn commit: r1373744 - in /incubator/hcatalog/branches/branch-0.4: ./ CHANGES.txt src/java/org/apache/hcatalog/common/HiveClientCache.java
Date Thu, 16 Aug 2012 06:54:54 GMT
Author: toffer
Date: Thu Aug 16 06:54:53 2012
New Revision: 1373744

URL: http://svn.apache.org/viewvc?rev=1373744&view=rev
Log:
merged from trunk: HCATALOG-469 HiveClientCache may return a closed client (amalakar via toffer)

Modified:
    incubator/hcatalog/branches/branch-0.4/   (props changed)
    incubator/hcatalog/branches/branch-0.4/CHANGES.txt
    incubator/hcatalog/branches/branch-0.4/src/java/org/apache/hcatalog/common/HiveClientCache.java

Propchange: incubator/hcatalog/branches/branch-0.4/
------------------------------------------------------------------------------
  Merged /incubator/hcatalog/trunk:r1373743

Modified: incubator/hcatalog/branches/branch-0.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hcatalog/branches/branch-0.4/CHANGES.txt?rev=1373744&r1=1373743&r2=1373744&view=diff
==============================================================================
--- incubator/hcatalog/branches/branch-0.4/CHANGES.txt (original)
+++ incubator/hcatalog/branches/branch-0.4/CHANGES.txt Thu Aug 16 06:54:53 2012
@@ -23,7 +23,9 @@ Trunk (unreleased changes)
   INCOMPATIBLE CHANGES
 
   NEW FEATURES
-  HCAT-370 Create a HiveMetaStoreClient cache in hcatalog (amalakar via toffer)
+  HCAT-469 HiveClientCache may return a closed client (amalakar via toffer)
+
+  HCAT-370 Create a HiveMetaStoreClient cache in hcatalog (amalakar via toffer) 
 
   HCAT-419 Java APIs for HCatalog DDL commands (avandana via toffer)
 

Modified: incubator/hcatalog/branches/branch-0.4/src/java/org/apache/hcatalog/common/HiveClientCache.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/branches/branch-0.4/src/java/org/apache/hcatalog/common/HiveClientCache.java?rev=1373744&r1=1373743&r2=1373744&view=diff
==============================================================================
--- incubator/hcatalog/branches/branch-0.4/src/java/org/apache/hcatalog/common/HiveClientCache.java
(original)
+++ incubator/hcatalog/branches/branch-0.4/src/java/org/apache/hcatalog/common/HiveClientCache.java
Thu Aug 16 06:54:53 2012
@@ -48,6 +48,8 @@ class HiveClientCache {
     final private Cache<HiveClientCacheKey, CacheableHiveMetaStoreClient> hiveCache;
     private static final Logger LOG = LoggerFactory.getLogger(HiveClientCache.class);
     private final int timeout;
+    // This lock is used to make sure removalListener won't close a client that is being
contemplated for returning by get()
+    private final Object CACHE_TEARDOWN_LOCK = new Object();
 
     private static final AtomicInteger nextId = new AtomicInteger(0);
 
@@ -75,8 +77,10 @@ class HiveClientCache {
                  public void onRemoval(RemovalNotification<HiveClientCacheKey, CacheableHiveMetaStoreClient>
notification) {
                      CacheableHiveMetaStoreClient hiveMetaStoreClient = notification.getValue();
                      if (hiveMetaStoreClient != null) {
-                         hiveMetaStoreClient.setExpiredFromCache();
-                         hiveMetaStoreClient.tearDownIfUnused();
+                         synchronized (CACHE_TEARDOWN_LOCK) {
+                            hiveMetaStoreClient.setExpiredFromCache();
+                            hiveMetaStoreClient.tearDownIfUnused();
+                         }
                      }
                  }
              };
@@ -130,12 +134,21 @@ class HiveClientCache {
      */
     public HiveMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException,
LoginException {
         final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId());
-        CacheableHiveMetaStoreClient hiveMetaStoreClient = getOrCreate(cacheKey);
-        if (!hiveMetaStoreClient.isOpen()) {
-            hiveCache.invalidate(cacheKey);
+        CacheableHiveMetaStoreClient hiveMetaStoreClient = null;
+        // the hmsc is not shared across threads. So the only way it could get closed while
we are doing healthcheck
+        // is if removalListener closes it. The synchronization takes care that removalListener
won't do it
+        synchronized (CACHE_TEARDOWN_LOCK) {
             hiveMetaStoreClient = getOrCreate(cacheKey);
+            hiveMetaStoreClient.acquire();
+        }
+        if (!hiveMetaStoreClient.isOpen()) {
+            synchronized (CACHE_TEARDOWN_LOCK) {
+                hiveCache.invalidate(cacheKey);
+                hiveMetaStoreClient.close();
+                hiveMetaStoreClient = getOrCreate(cacheKey);
+                hiveMetaStoreClient.acquire();
+            }
         }
-        hiveMetaStoreClient.acquire();
         return hiveMetaStoreClient;
     }
 



Mime
View raw message