Skip to content

Commit

Permalink
branch-3.0: [fix](mem leak) fe non_heap mem leak while use jdbc catalog
Browse files Browse the repository at this point in the history
#45806 (#45979)

Cherry-picked from #45806

Co-authored-by: camby <[email protected]>
  • Loading branch information
github-actions[bot] and cambyzju authored Dec 26, 2024
1 parent 0cfdf4b commit 3c5797b
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

@Getter
Expand All @@ -56,6 +57,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<URL, ClassLoader> classLoaderMap = new ConcurrentHashMap<>();

private String catalogName;
protected String dbType;
protected String jdbcUser;
Expand Down Expand Up @@ -147,11 +150,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);
}
Expand Down

0 comments on commit 3c5797b

Please sign in to comment.