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

For #8611, Close old datasource connection. #9212

Merged
merged 1 commit into from Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -119,16 +119,37 @@ public void init() {
@Override
public synchronized void reload() throws IOException {
try {
dataSourceList = new ExternalDataSourceProperties()
final List<JdbcTemplate> testJtListNew = new ArrayList<JdbcTemplate>();
final List<Boolean> isHealthListNew = new ArrayList<Boolean>();

List<HikariDataSource> dataSourceListNew = new ExternalDataSourceProperties()
.build(EnvUtil.getEnvironment(), (dataSource) -> {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setQueryTimeout(queryTimeout);
jdbcTemplate.setDataSource(dataSource);
testJtList.add(jdbcTemplate);
isHealthList.add(Boolean.TRUE);
testJtListNew.add(jdbcTemplate);
isHealthListNew.add(Boolean.TRUE);
});

final List<HikariDataSource> dataSourceListOld = dataSourceList;
final List<JdbcTemplate> testJtListOld = testJtList;
dataSourceList = dataSourceListNew;
testJtList = testJtListNew;
isHealthList = isHealthListNew;
new SelectMasterTask().run();
new CheckDbHealthTask().run();

//close old datasource.
if (dataSourceListOld != null && !dataSourceListOld.isEmpty()) {
for (HikariDataSource dataSource : dataSourceListOld) {
dataSource.close();
}
}
if (testJtListOld != null && !testJtListOld.isEmpty()) {
for (JdbcTemplate oldJdbc : testJtListOld) {
oldJdbc.setDataSource(null);
}
}
} catch (RuntimeException e) {
FATAL_LOG.error(DB_LOAD_ERROR_MSG, e);
throw new IOException(e);
Expand Down