congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
HiveClientCache
Code IndexAdd Tabnine to your IDE (free)

How to use
HiveClientCache
in
org.apache.hive.hcatalog.common

Best Java code snippets using org.apache.hive.hcatalog.common.HiveClientCache (Showing top 20 results out of 315)

origin: apache/hive

/**
 * Get or create a hive client depending on whether it exits in cache or not
 * @param hiveConf The hive configuration
 * @return the client
 * @throws MetaException When HiveMetaStoreClient couldn't be created
 * @throws IOException
 */
public static IMetaStoreClient getHiveMetastoreClient(HiveConf hiveConf)
  throws MetaException, IOException {
 if (hiveConf.getBoolean(HCatConstants.HCAT_HIVE_CLIENT_DISABLE_CACHE, false)){
  // If cache is disabled, don't use it.
  return HiveClientCache.getNonCachedHiveMetastoreClient(hiveConf);
 }
 // Singleton behaviour: create the cache instance if required.
 if (hiveClientCache == null) {
  synchronized (IMetaStoreClient.class) {
   if (hiveClientCache == null) {
    hiveClientCache = new HiveClientCache(hiveConf);
   }
  }
 }
 try {
  return hiveClientCache.get(hiveConf);
 } catch (LoginException e) {
  throw new IOException("Couldn't create hiveMetaStoreClient, Error getting UGI for user", e);
 }
}
origin: apache/hive

@Test
public void testCloseAllClients() throws IOException, MetaException, LoginException {
 final HiveClientCache cache = new HiveClientCache(1000);
 HiveClientCache.ICacheableMetaStoreClient client1 = (HiveClientCache.ICacheableMetaStoreClient) cache.get(hiveConf);
 hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, " "); // URIs are checked for string equivalence, even spaces make them different
 HiveClientCache.ICacheableMetaStoreClient client2 = (HiveClientCache.ICacheableMetaStoreClient) cache.get(hiveConf);
 cache.closeAllClientsQuietly();
 assertTrue(client1.isClosed());
 assertTrue(client2.isClosed());
}
origin: apache/hive

/**
 * Returns a cached client if exists or else creates one, caches and returns it. It also checks that the client is
 * healthy and can be reused
 * @param hiveConf
 * @return the hive client
 * @throws MetaException
 * @throws IOException
 * @throws LoginException
 */
public IMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException {
 final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId());
 ICacheableMetaStoreClient cacheableHiveMetaStoreClient = 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) {
  cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
  cacheableHiveMetaStoreClient.acquire();
 }
 if (!cacheableHiveMetaStoreClient.isOpen()) {
  synchronized (CACHE_TEARDOWN_LOCK) {
   hiveCache.invalidate(cacheKey);
   cacheableHiveMetaStoreClient.close();
   cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
   cacheableHiveMetaStoreClient.acquire();
  }
 }
 return cacheableHiveMetaStoreClient;
}
origin: apache/hive

@Test
public void testCacheMiss() throws IOException, MetaException, LoginException {
 HiveClientCache cache = new HiveClientCache(1000);
 IMetaStoreClient client = cache.get(hiveConf);
 assertNotNull(client);
 // Set different uri as it is one of the criteria deciding whether to return the same client or not
 hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, " "); // URIs are checked for string equivalence, even spaces make them different
 IMetaStoreClient client2 = cache.get(hiveConf);
 assertNotNull(client2);
 assertNotSame(client, client2);
}
origin: apache/hive

 @Override
 public void run() {
  LOG.debug("Cleaning up hive client cache in ShutDown hook");
  cleanupHandle.cancel(false); // Cancel the maintenance thread.
  closeAllClientsQuietly();
 }
};
origin: apache/hive

/**
 * Check that a *new* client is created if asked from different threads even with
 * the same hive configuration
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test
public void testMultipleThreadAccess() throws ExecutionException, InterruptedException {
 final HiveClientCache cache = new HiveClientCache(1000);
 class GetHiveClient implements Callable<IMetaStoreClient> {
  @Override
  public IMetaStoreClient call() throws IOException, MetaException, LoginException {
   return cache.get(hiveConf);
  }
 }
 ExecutorService executor = Executors.newFixedThreadPool(2);
 Callable<IMetaStoreClient> worker1 = new GetHiveClient();
 Callable<IMetaStoreClient> worker2 = new GetHiveClient();
 Future<IMetaStoreClient> clientFuture1 = executor.submit(worker1);
 Future<IMetaStoreClient> clientFuture2 = executor.submit(worker2);
 IMetaStoreClient client1 = clientFuture1.get();
 IMetaStoreClient client2 = clientFuture2.get();
 assertNotNull(client1);
 assertNotNull(client2);
 assertNotSame(client1, client2);
}
origin: apache/hive

/**
 * Check that a new client is returned for the same configuration after the expiry time.
 * Also verify that the expiry time configuration is honoured
 */
@Test
public void testCacheExpiry() throws IOException, MetaException, LoginException, InterruptedException {
 HiveClientCache cache = new HiveClientCache(1);
 HiveClientCache.ICacheableMetaStoreClient client = (HiveClientCache.ICacheableMetaStoreClient) cache.get(hiveConf);
 assertNotNull(client);
 Thread.sleep(2500);
 HiveClientCache.ICacheableMetaStoreClient client2 = (HiveClientCache.ICacheableMetaStoreClient) cache.get(hiveConf);
 client.close();
 assertTrue(client.isClosed()); // close() after *expiry time* and *a cache access* should  have tore down the client
 assertNotNull(client2);
 assertNotSame(client, client2);
}
origin: org.spark-project.hive.hcatalog/hive-hcatalog-core

 @Override
 public void run() {
  LOG.debug("Cleaning up hive client cache in ShutDown hook");
  cleanupHandle.cancel(false); // Cancel the maintenance thread.
  closeAllClientsQuietly();
 }
};
origin: org.apache.hive.hcatalog/hive-hcatalog-core

/**
 * Get or create a hive client depending on whether it exits in cache or not
 * @param hiveConf The hive configuration
 * @return the client
 * @throws MetaException When HiveMetaStoreClient couldn't be created
 * @throws IOException
 */
public static IMetaStoreClient getHiveMetastoreClient(HiveConf hiveConf)
  throws MetaException, IOException {
 if (hiveConf.getBoolean(HCatConstants.HCAT_HIVE_CLIENT_DISABLE_CACHE, false)){
  // If cache is disabled, don't use it.
  return HiveClientCache.getNonCachedHiveMetastoreClient(hiveConf);
 }
 // Singleton behaviour: create the cache instance if required.
 if (hiveClientCache == null) {
  synchronized (IMetaStoreClient.class) {
   if (hiveClientCache == null) {
    hiveClientCache = new HiveClientCache(hiveConf);
   }
  }
 }
 try {
  return hiveClientCache.get(hiveConf);
 } catch (LoginException e) {
  throw new IOException("Couldn't create hiveMetaStoreClient, Error getting UGI for user", e);
 }
}
origin: apache/hive

@Test
public void testCacheHit() throws IOException, MetaException, LoginException {
 HiveClientCache cache = new HiveClientCache(1000);
 HiveClientCache.ICacheableMetaStoreClient client = (HiveClientCache.ICacheableMetaStoreClient) cache.get(hiveConf);
 assertNotNull(client);
 client.close(); // close shouldn't matter
 // Setting a non important configuration should return the same client only
 hiveConf.setIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTS, 10);
 HiveClientCache.ICacheableMetaStoreClient client2 = (HiveClientCache.ICacheableMetaStoreClient) cache.get(hiveConf);
 assertNotNull(client2);
 assertSame(client, client2);
 assertEquals(client.getUsers(), client2.getUsers());
 client2.close();
}
origin: org.apache.hive.hcatalog/hive-hcatalog-core

/**
 * Returns a cached client if exists or else creates one, caches and returns it. It also checks that the client is
 * healthy and can be reused
 * @param hiveConf
 * @return the hive client
 * @throws MetaException
 * @throws IOException
 * @throws LoginException
 */
public IMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException {
 final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId());
 ICacheableMetaStoreClient cacheableHiveMetaStoreClient = 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) {
  cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
  cacheableHiveMetaStoreClient.acquire();
 }
 if (!cacheableHiveMetaStoreClient.isOpen()) {
  synchronized (CACHE_TEARDOWN_LOCK) {
   hiveCache.invalidate(cacheKey);
   cacheableHiveMetaStoreClient.close();
   cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
   cacheableHiveMetaStoreClient.acquire();
  }
 }
 return cacheableHiveMetaStoreClient;
}
origin: org.apache.hive.hcatalog/hive-hcatalog-core

 @Override
 public void run() {
  LOG.debug("Cleaning up hive client cache in ShutDown hook");
  cleanupHandle.cancel(false); // Cancel the maintenance thread.
  closeAllClientsQuietly();
 }
};
origin: com.facebook.presto.hive/hive-apache

/**
 * Get or create a hive client depending on whether it exits in cache or not
 * @param hiveConf The hive configuration
 * @return the client
 * @throws MetaException When HiveMetaStoreClient couldn't be created
 * @throws IOException
 */
public static IMetaStoreClient getHiveMetastoreClient(HiveConf hiveConf)
  throws MetaException, IOException {
 if (hiveConf.getBoolean(HCatConstants.HCAT_HIVE_CLIENT_DISABLE_CACHE, false)){
  // If cache is disabled, don't use it.
  return HiveClientCache.getNonCachedHiveMetastoreClient(hiveConf);
 }
 // Singleton behaviour: create the cache instance if required.
 if (hiveClientCache == null) {
  synchronized (IMetaStoreClient.class) {
   if (hiveClientCache == null) {
    hiveClientCache = new HiveClientCache(hiveConf);
   }
  }
 }
 try {
  return hiveClientCache.get(hiveConf);
 } catch (LoginException e) {
  throw new IOException("Couldn't create hiveMetaStoreClient, Error getting UGI for user", e);
 }
}
origin: apache/hive

metaServer.start();
final HiveClientCache cache = new HiveClientCache(1000);
HiveClientCache.CacheableHiveMetaStoreClient client =
  (HiveClientCache.CacheableHiveMetaStoreClient) cache.get(metaServer.getHiveConf());
origin: org.spark-project.hive.hcatalog/hive-hcatalog-core

/**
 * Returns a cached client if exists or else creates one, caches and returns it. It also checks that the client is
 * healthy and can be reused
 * @param hiveConf
 * @return the hive client
 * @throws MetaException
 * @throws IOException
 * @throws LoginException
 */
public ICacheableMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException {
 final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId());
 ICacheableMetaStoreClient cacheableHiveMetaStoreClient = 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) {
  cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
  cacheableHiveMetaStoreClient.acquire();
 }
 if (!cacheableHiveMetaStoreClient.isOpen()) {
  synchronized (CACHE_TEARDOWN_LOCK) {
   hiveCache.invalidate(cacheKey);
   cacheableHiveMetaStoreClient.close();
   cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
   cacheableHiveMetaStoreClient.acquire();
  }
 }
 return cacheableHiveMetaStoreClient;
}
origin: com.github.hyukjinkwon.hcatalog/hive-hcatalog-core

 @Override
 public void run() {
  LOG.debug("Cleaning up hive client cache in ShutDown hook");
  cleanupHandle.cancel(false); // Cancel the maintenance thread.
  closeAllClientsQuietly();
 }
};
origin: com.github.hyukjinkwon.hcatalog/hive-hcatalog-core

/**
 * Get or create a hive client depending on whether it exits in cache or not
 * @param hiveConf The hive configuration
 * @return the client
 * @throws MetaException When HiveMetaStoreClient couldn't be created
 * @throws IOException
 */
public static IMetaStoreClient getHiveMetastoreClient(HiveConf hiveConf)
  throws MetaException, IOException {
 if (hiveConf.getBoolean(HCatConstants.HCAT_HIVE_CLIENT_DISABLE_CACHE, false)){
  // If cache is disabled, don't use it.
  return HiveClientCache.getNonCachedHiveMetastoreClient(hiveConf);
 }
 // Singleton behaviour: create the cache instance if required.
 if (hiveClientCache == null) {
  synchronized (IMetaStoreClient.class) {
   if (hiveClientCache == null) {
    hiveClientCache = new HiveClientCache(hiveConf);
   }
  }
 }
 try {
  return hiveClientCache.get(hiveConf);
 } catch (LoginException e) {
  throw new IOException("Couldn't create hiveMetaStoreClient, Error getting UGI for user", e);
 }
}
origin: com.github.hyukjinkwon.hcatalog/hive-hcatalog-core

/**
 * Returns a cached client if exists or else creates one, caches and returns it. It also checks that the client is
 * healthy and can be reused
 * @param hiveConf
 * @return the hive client
 * @throws MetaException
 * @throws IOException
 * @throws LoginException
 */
public ICacheableMetaStoreClient get(final HiveConf hiveConf) throws MetaException, IOException, LoginException {
 final HiveClientCacheKey cacheKey = HiveClientCacheKey.fromHiveConf(hiveConf, getThreadId());
 ICacheableMetaStoreClient cacheableHiveMetaStoreClient = 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) {
  cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
  cacheableHiveMetaStoreClient.acquire();
 }
 if (!cacheableHiveMetaStoreClient.isOpen()) {
  synchronized (CACHE_TEARDOWN_LOCK) {
   hiveCache.invalidate(cacheKey);
   cacheableHiveMetaStoreClient.close();
   cacheableHiveMetaStoreClient = getOrCreate(cacheKey);
   cacheableHiveMetaStoreClient.acquire();
  }
 }
 return cacheableHiveMetaStoreClient;
}
origin: com.facebook.presto.hive/hive-apache

 @Override
 public void run() {
  LOG.debug("Cleaning up hive client cache in ShutDown hook");
  cleanupHandle.cancel(false); // Cancel the maintenance thread.
  closeAllClientsQuietly();
 }
};
origin: org.spark-project.hive.hcatalog/hive-hcatalog-core

/**
 * Get or create a hive client depending on whether it exits in cache or not
 * @param hiveConf The hive configuration
 * @return the client
 * @throws MetaException When HiveMetaStoreClient couldn't be created
 * @throws IOException
 */
public static IMetaStoreClient getHiveMetastoreClient(HiveConf hiveConf)
  throws MetaException, IOException {
 if (hiveConf.getBoolean(HCatConstants.HCAT_HIVE_CLIENT_DISABLE_CACHE, false)){
  // If cache is disabled, don't use it.
  return HiveClientCache.getNonCachedHiveMetastoreClient(hiveConf);
 }
 // Singleton behaviour: create the cache instance if required.
 if (hiveClientCache == null) {
  synchronized (IMetaStoreClient.class) {
   if (hiveClientCache == null) {
    hiveClientCache = new HiveClientCache(hiveConf);
   }
  }
 }
 try {
  return hiveClientCache.get(hiveConf);
 } catch (LoginException e) {
  throw new IOException("Couldn't create hiveMetaStoreClient, Error getting UGI for user", e);
 }
}
org.apache.hive.hcatalog.commonHiveClientCache

Javadoc

A thread safe time expired cache for HiveMetaStoreClient

Most used methods

  • <init>
  • closeAllClientsQuietly
    Note: This doesn't check if they are being used or not, meant only to be called during shutdown etc.
  • get
    Returns a cached client if exists or else creates one, caches and returns it. It also checks that th
  • getNonCachedHiveMetastoreClient
  • getOrCreate
    Return from cache if exists else create/cache and return
  • getThreadId
  • cleanup
  • createCleanupThread
  • createRemovalListener
  • createShutdownHook

Popular in Java

  • Creating JSON documents from java classes using gson
  • onRequestPermissionsResult (Fragment)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • findViewById (Activity)
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • BoxLayout (javax.swing)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Join (org.hibernate.mapping)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now