Skip to content

Commit

Permalink
[branch-2.1][fix](jdbc catalog) Fix Memory Leak by Enabling Weak Refe…
Browse files Browse the repository at this point in the history
…rences in HikariCP (#39833)

pick(#39582)
  • Loading branch information
zy-kkk authored Aug 23, 2024
1 parent 00e4f34 commit 4cb7122
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public BaseJdbcExecutor(byte[] thriftParams) throws Exception {
.setConnectionPoolMaxLifeTime(request.connection_pool_max_life_time)
.setConnectionPoolKeepAlive(request.connection_pool_keep_alive);
JdbcDataSource.getDataSource().setCleanupInterval(request.connection_pool_cache_clear_time);
System.setProperty("com.zaxxer.hikari.useWeakReferences", "true");
init(config, request.statement);
this.jdbcDriverVersion = getJdbcDriverVersion();
}
Expand Down Expand Up @@ -308,7 +309,7 @@ private void init(JdbcDataSourceConfig config, String sql) throws JdbcExecutorEx
ds.setKeepaliveTime(config.getConnectionPoolMaxLifeTime() / 5L); // default 6 min
}
hikariDataSource = ds;
JdbcDataSource.getDataSource().putSource(hikariDataSourceKey, ds);
JdbcDataSource.getDataSource().putSource(hikariDataSourceKey, hikariDataSource);
LOG.info("JdbcClient set"
+ " ConnectionPoolMinSize = " + config.getConnectionPoolMinSize()
+ ", ConnectionPoolMaxSize = " + config.getConnectionPoolMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public Map<String, HikariDataSource> getSourcesMap() {
}

public void setCleanupInterval(long interval) {
this.cleanupInterval = interval * 1000L;
restartCleanupTask();
if (this.cleanupInterval != interval * 1000L) {
this.cleanupInterval = interval * 1000L;
restartCleanupTask();
}
}

private synchronized void restartCleanupTask() {
Expand Down

0 comments on commit 4cb7122

Please sign in to comment.