Repository: incubator-gobblin
Updated Branches:
  refs/heads/master b01ec9cc9 -> 5cf4798dd


[GOBBLIN-502] make pool cache ttl configurable

Closes #2372 from
autumnust/configurablePoolCacheTTl


Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/5cf4798d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/5cf4798d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/5cf4798d

Branch: refs/heads/master
Commit: 5cf4798dd8bd0ec3fe32188882783f49c45923cb
Parents: b01ec9c
Author: Lei Sun <[email protected]>
Authored: Thu May 24 11:23:14 2018 -0700
Committer: Hung Tran <[email protected]>
Committed: Thu May 24 11:23:14 2018 -0700

----------------------------------------------------------------------
 .../gobblin/hive/HiveMetastoreClientPool.java   | 31 +++++++++++++-------
 1 file changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/5cf4798d/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java
----------------------------------------------------------------------
diff --git 
a/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java
 
b/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java
index 65cfc44..38bf9dc 100644
--- 
a/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java
+++ 
b/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java
@@ -56,17 +56,25 @@ public class HiveMetastoreClientPool {
   private final HiveRegProps hiveRegProps;
 
   private static final long DEFAULT_POOL_CACHE_TTL_MINUTES = 30;
-  private static final Cache<Optional<String>, HiveMetastoreClientPool> 
poolCache =
-      CacheBuilder.newBuilder()
-          .expireAfterAccess(DEFAULT_POOL_CACHE_TTL_MINUTES, TimeUnit.MINUTES)
-          .removalListener(new RemovalListener<Optional<String>, 
HiveMetastoreClientPool>() {
-        @Override
-        public void onRemoval(RemovalNotification<Optional<String>, 
HiveMetastoreClientPool> notification) {
-          if (notification.getValue() != null) {
-            notification.getValue().close();
+
+  public static final String POOL_CACHE_TTL_MINUTES_KEY = 
"hive.metaStorePoolCache.ttl";
+
+  public static Cache<Optional<String>, HiveMetastoreClientPool> poolCache = 
null;
+
+  private static final Cache<Optional<String>, HiveMetastoreClientPool> 
createPoolCache(final Properties properties) {
+    long duration = properties.containsKey(POOL_CACHE_TTL_MINUTES_KEY)
+        ? Long.parseLong(properties.getProperty(POOL_CACHE_TTL_MINUTES_KEY)) : 
DEFAULT_POOL_CACHE_TTL_MINUTES;
+    return CacheBuilder.newBuilder()
+        .expireAfterAccess(duration, TimeUnit.MINUTES)
+        .removalListener(new RemovalListener<Optional<String>, 
HiveMetastoreClientPool>() {
+          @Override
+          public void onRemoval(RemovalNotification<Optional<String>, 
HiveMetastoreClientPool> notification) {
+            if (notification.getValue() != null) {
+              notification.getValue().close();
+            }
           }
-        }
-      }).build();
+        }).build();
+  }
 
   /**
    * Get a {@link HiveMetastoreClientPool} for the requested metastore URI. 
Useful for using the same pools across
@@ -80,6 +88,9 @@ public class HiveMetastoreClientPool {
    */
   public static HiveMetastoreClientPool get(final Properties properties, final 
Optional<String> metastoreURI)
       throws IOException {
+    if (poolCache == null) {
+      poolCache = createPoolCache(properties);
+    }
     try {
       return poolCache.get(metastoreURI, new 
Callable<HiveMetastoreClientPool>() {
         @Override

Reply via email to