From 7addefbfe8eddf9d73a83a25a14e133ce34e79f6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 26 Dec 2024 15:05:28 +0800 Subject: [PATCH] branch-2.1: [fix](mem leak) fe non_heap mem leak while use jdbc catalog #45806 (#45980) Cherry-picked from #45806 Co-authored-by: camby --- .../doris/datasource/jdbc/client/JdbcClient.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java index 08befe4561e8ac..bfa22b25ea6a67 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java @@ -47,6 +47,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; @Getter @@ -55,6 +56,8 @@ public abstract class JdbcClient { private static final int HTTP_TIMEOUT_MS = 10000; protected static final int JDBC_DATETIME_SCALE = 6; + private static final Map classLoaderMap = new ConcurrentHashMap<>(); + private String catalogName; protected String dbType; protected String jdbcUser; @@ -146,11 +149,16 @@ private void initializeDataSource(JdbcClientConfig config) { } } - private void initializeClassLoader(JdbcClientConfig config) { + private synchronized void initializeClassLoader(JdbcClientConfig config) { try { URL[] urls = {new URL(JdbcResource.getFullDriverUrl(config.getDriverUrl()))}; - ClassLoader parent = getClass().getClassLoader(); - this.classLoader = URLClassLoader.newInstance(urls, parent); + if (classLoaderMap.containsKey(urls[0])) { + this.classLoader = classLoaderMap.get(urls[0]); + } else { + ClassLoader parent = getClass().getClassLoader(); + this.classLoader = URLClassLoader.newInstance(urls, parent); + classLoaderMap.put(urls[0], this.classLoader); + } } catch (MalformedURLException e) { throw new RuntimeException("Error loading JDBC driver.", e); }