@Test public void testMultipleThreadAccess() throws ExecutionException, InterruptedException { final HiveClientCache cache = new HiveClientCache(1000); class GetHiveClient implements Callable<HiveMetaStoreClient> { @Override public HiveMetaStoreClient call() throws IOException, MetaException, LoginException { return cache.get(hiveConf); } } ExecutorService executor = Executors.newFixedThreadPool(2); Callable<HiveMetaStoreClient> worker1 = new GetHiveClient(); Callable<HiveMetaStoreClient> worker2 = new GetHiveClient(); Future<HiveMetaStoreClient> clientFuture1 = executor.submit(worker1); Future<HiveMetaStoreClient> clientFuture2 = executor.submit(worker2); HiveMetaStoreClient client1 = clientFuture1.get(); HiveMetaStoreClient client2 = clientFuture2.get(); assertNotNull(client1); assertNotNull(client2); assertNotSame(client1, client2); }
public HiveMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException { final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId()); CacheableHiveMetaStoreClient hiveMetaStoreClient = null; 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(); } } return hiveMetaStoreClient; }
HiveClientCache { public HiveMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException { final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId()); CacheableHiveMetaStoreClient hiveMetaStoreClient = null; 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(); } } return hiveMetaStoreClient; } }
HiveClientCache { public HiveMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException { final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId()); CacheableHiveMetaStoreClient hiveMetaStoreClient = null; 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(); } } return hiveMetaStoreClient; } HiveClientCache(HiveConf hiveConf);  HiveClientCache(final int timeout); }
HiveClientCache { public HiveMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException { final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId()); CacheableHiveMetaStoreClient hiveMetaStoreClient = null; 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(); } } return hiveMetaStoreClient; } HiveClientCache(HiveConf hiveConf);  HiveClientCache(final int timeout); static HiveMetaStoreClient getNonCachedHiveClient(HiveConf hiveConf); void cleanup(); HiveMetaStoreClient get(final HiveConf hiveConf); }
HiveClientCache { public HiveMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException { final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId()); CacheableHiveMetaStoreClient hiveMetaStoreClient = null; 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(); } } return hiveMetaStoreClient; } HiveClientCache(HiveConf hiveConf);  HiveClientCache(final int timeout); static HiveMetaStoreClient getNonCachedHiveClient(HiveConf hiveConf); void cleanup(); HiveMetaStoreClient get(final HiveConf hiveConf); final static int DEFAULT_HIVE_CACHE_EXPIRY_TIME_SECONDS; }