Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch-2.1: [improvement](jdbc catalog) Optimize JDBC driver property settings #42923 #44405

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public abstract class BaseJdbcExecutor implements JdbcExecutor {
protected String jdbcDriverVersion;

public BaseJdbcExecutor(byte[] thriftParams) throws Exception {
setJdbcDriverSystemProperties();
TJdbcExecutorCtorParams request = new TJdbcExecutorCtorParams();
TDeserializer deserializer = new TDeserializer(PROTOCOL_FACTORY);
try {
Expand All @@ -93,7 +94,6 @@ 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 @@ -146,6 +146,10 @@ protected void abortReadConnection(Connection connection, ResultSet resultSet)
throws SQLException {
}

protected void setJdbcDriverSystemProperties() {
System.setProperty("com.zaxxer.hikari.useWeakReferences", "true");
}

public void cleanDataSource() {
if (hikariDataSource != null) {
hikariDataSource.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class MySQLJdbcExecutor extends BaseJdbcExecutor {

public MySQLJdbcExecutor(byte[] thriftParams) throws Exception {
super(thriftParams);
}

@Override
protected void setJdbcDriverSystemProperties() {
super.setJdbcDriverSystemProperties();
System.setProperty("com.mysql.cj.disableAbandonedConnectionCleanup", "true");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static JdbcClient createJdbcClient(JdbcClientConfig jdbcClientConfig) {
}

protected JdbcClient(JdbcClientConfig jdbcClientConfig) {
System.setProperty("com.zaxxer.hikari.useWeakReferences", "true");
setJdbcDriverSystemProperties();
this.catalogName = jdbcClientConfig.getCatalog();
this.jdbcUser = jdbcClientConfig.getUser();
this.isOnlySpecifiedDatabase = Boolean.parseBoolean(jdbcClientConfig.getOnlySpecifiedDatabase());
Expand All @@ -116,6 +116,10 @@ protected JdbcClient(JdbcClientConfig jdbcClientConfig) {
this.jdbcLowerCaseMetaMatching = new JdbcIdentifierMapping(isLowerCaseMetaNames, metaNamesMapping, this);
}

protected void setJdbcDriverSystemProperties() {
System.setProperty("com.zaxxer.hikari.useWeakReferences", "true");
}

// Initialize DataSource
private void initializeDataSource(JdbcClientConfig config) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class JdbcMySQLClient extends JdbcClient {

protected JdbcMySQLClient(JdbcClientConfig jdbcClientConfig) {
super(jdbcClientConfig);
// Disable abandoned connection cleanup
System.setProperty("com.mysql.cj.disableAbandonedConnectionCleanup", "true");
convertDateToNull = isConvertDatetimeToNull(jdbcClientConfig);
Connection conn = null;
Statement stmt = null;
Expand All @@ -74,6 +72,12 @@ protected JdbcMySQLClient(JdbcClientConfig jdbcClientConfig, String dbType) {
this.dbType = dbType;
}

@Override
protected void setJdbcDriverSystemProperties() {
super.setJdbcDriverSystemProperties();
System.setProperty("com.mysql.cj.disableAbandonedConnectionCleanup", "true");
}

@Override
public List<String> getDatabaseNameList() {
Connection conn = null;
Expand Down
Loading