You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/03/11 20:25:19 UTC

[GitHub] [iceberg] lcspinter commented on a change in pull request #2325: Hive: Use HiveClientPool cache instead of HiveCatalog global cache.

lcspinter commented on a change in pull request #2325:
URL: https://github.com/apache/iceberg/pull/2325#discussion_r592696818



##########
File path: hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
##########
@@ -604,4 +596,34 @@ public void setConf(Configuration conf) {
   public Configuration getConf() {
     return conf;
   }
+
+  @VisibleForTesting
+  HiveClientPool loadHiveClientPool(Configuration configuration) {
+    String metastoreUri = configuration.get(HiveConf.ConfVars.METASTOREURIS.varname, "");
+    Pair<HiveClientPool, Long> cacheEntry = CLIENT_POOL_CACHE.getIfPresent(metastoreUri);
+    HiveClientPool clientPool = cacheEntry == null ? new HiveClientPool(configuration) : cacheEntry.first();
+    CLIENT_POOL_CACHE.put(metastoreUri, Pair.of(clientPool, System.currentTimeMillis()));
+    return clientPool;
+  }
+
+  private void scheduleCacheCleaner() {
+    if (cleaner == null) {
+      synchronized (HiveCatalog.class) {
+        if (cleaner == null) {
+          cleaner = Executors.newSingleThreadScheduledExecutor(
+                  new ThreadFactoryBuilder()
+                          .setDaemon(true)
+                          .setNameFormat("iceberg-client-pool-cache-cleaner-%d")
+                          .build());
+        }
+        ScheduledFuture<?> futures = cleaner.scheduleWithFixedDelay(() -> CLIENT_POOL_CACHE.asMap().entrySet().stream()
+                .filter(e -> e.getValue().second() + evictionInterval <= System.currentTimeMillis())

Review comment:
       Good idea. I changed the code accordingly. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org