Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2513] fix: Fix thread pool leak in CachedClientPool (#2520)

Qi Yuca1714eb5cc8
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/CachedClientPool.java b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/CachedClientPool.java
index 07d58647a7..c68545a7e9 100644
--- a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/CachedClientPool.java
+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/CachedClientPool.java
@@ -54,19 +54,19 @@ public class CachedClientPool implements ClientPool<IMetaStoreClient, TException
private final Configuration conf;
private final int clientPoolSize;
+ private final ScheduledThreadPoolExecutor scheduler;
CachedClientPool(int clientPoolSize, Configuration conf, long evictionInterval) {
this.conf = conf;
this.clientPoolSize = clientPoolSize;
// Since Caffeine does not ensure that removalListener will be involved after expiration
// We use a scheduler with one thread to clean up expired clients.
+ scheduler = new ScheduledThreadPoolExecutor(1, newDaemonThreadFactory());
this.clientPoolCache =
Caffeine.newBuilder()
.expireAfterAccess(evictionInterval, TimeUnit.MILLISECONDS)
.removalListener((ignored, value, cause) -> ((HiveClientPool) value).close())
- .scheduler(
- Scheduler.forScheduledExecutorService(
- new ScheduledThreadPoolExecutor(1, newDaemonThreadFactory())))
+ .scheduler(Scheduler.forScheduledExecutorService(scheduler))
.build();
}
@@ -136,5 +136,6 @@ public class CachedClientPool implements ClientPool<IMetaStoreClient, TException
public void close() {
clientPoolCache.invalidateAll();
+ scheduler.shutdownNow();
}
}