You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hcatalog-commits@incubator.apache.org by to...@apache.org on 2012/08/16 06:51:59 UTC
svn commit: r1373743 - in /incubator/hcatalog/trunk: CHANGES.txt
src/java/org/apache/hcatalog/common/HiveClientCache.java
Author: toffer
Date: Thu Aug 16 06:51:59 2012
New Revision: 1373743
URL: http://svn.apache.org/viewvc?rev=1373743&view=rev
Log:
HCATALOG-469 HiveClientCache may return a closed client (amalakar via toffer)
Modified:
incubator/hcatalog/trunk/CHANGES.txt
incubator/hcatalog/trunk/src/java/org/apache/hcatalog/common/HiveClientCache.java
Modified: incubator/hcatalog/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/CHANGES.txt?rev=1373743&r1=1373742&r2=1373743&view=diff
==============================================================================
--- incubator/hcatalog/trunk/CHANGES.txt (original)
+++ incubator/hcatalog/trunk/CHANGES.txt Thu Aug 16 06:51:59 2012
@@ -23,6 +23,8 @@ Trunk (unreleased changes)
INCOMPATIBLE CHANGES
NEW FEATURES
+ 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/trunk/src/java/org/apache/hcatalog/common/HiveClientCache.java
URL: http://svn.apache.org/viewvc/incubator/hcatalog/trunk/src/java/org/apache/hcatalog/common/HiveClientCache.java?rev=1373743&r1=1373742&r2=1373743&view=diff
==============================================================================
--- incubator/hcatalog/trunk/src/java/org/apache/hcatalog/common/HiveClientCache.java (original)
+++ incubator/hcatalog/trunk/src/java/org/apache/hcatalog/common/HiveClientCache.java Thu Aug 16 06:51:59 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;
}