-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: gracy destory datasource #579
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
The handling of unit testing is not reasonable.
-
Please add
Fixes #578
in the PR description to associate the corresponding issue.
// async destroy datasource | ||
ds.setGraceDestroy(true); | ||
ds.addDataSource(dataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(dataSourceProperty)); | ||
assertThat(ds.getDataSources().keySet()).contains("slave_1"); | ||
ds.removeDataSource("slave_1"); | ||
// close directly | ||
ds.setGraceDestroy(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Just a reminder, you can create a new unit test class or in a new unit test function body to narrow the scope of your unit tests.
-
It seems that the two codes in the unit test you changed are missing assertions.
// async destroy datasource | ||
ds.setGraceDestroy(true); | ||
ds.addDataSource(dataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(dataSourceProperty)); | ||
assertThat(ds.getDataSources().keySet()).contains("slave_1"); | ||
ds.removeDataSource("slave_1"); | ||
// close directly | ||
ds.setGraceDestroy(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The code here is missing assertions. And I recommend making assertions in separate unit tests rather than complicating existing unit tests.
What kind of change does this PR introduce? (check at least one)
The description of the PR:
Fixes #578
添加运行时优雅关闭数据源的功能,该特性可以通过配置spring.datasource.dynamic.gracy-destory = true 打开。
打开后,在运行时销毁数据源将会开启异步任务延迟销毁数据源。对HikariCP,druid,DHCP2能够支持检测是否含有活跃连接,在没有活跃连接的情况下立即关闭数据源,至多10s,超时后会直接强制关闭;对于不支持的数据源10s后再关闭数据源。
在dynamic-datasource调用destroy的时候强制销毁,不进行异步关闭。
优雅关闭数据源的代码中每次进行异步关闭都会开启一个线程池,从实际情况来看,覆盖数据源配置或者移除数据源配置是一个很低频的操作,并不会产生不良影响。
Other information:
更新了使用文档