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

feat: gracy destory datasource #579

Merged
merged 5 commits into from
Oct 23, 2023
Merged

Conversation

alvinkwok1
Copy link
Contributor

@alvinkwok1 alvinkwok1 commented Oct 18, 2023

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style
  • Refactor
  • Doc
  • Other, please describe:

The description of the PR:

Fixes #578

添加运行时优雅关闭数据源的功能,该特性可以通过配置spring.datasource.dynamic.gracy-destory = true 打开。

打开后,在运行时销毁数据源将会开启异步任务延迟销毁数据源。对HikariCP,druid,DHCP2能够支持检测是否含有活跃连接,在没有活跃连接的情况下立即关闭数据源,至多10s,超时后会直接强制关闭;对于不支持的数据源10s后再关闭数据源。

在dynamic-datasource调用destroy的时候强制销毁,不进行异步关闭。

优雅关闭数据源的代码中每次进行异步关闭都会开启一个线程池,从实际情况来看,覆盖数据源配置或者移除数据源配置是一个很低频的操作,并不会产生不良影响。

Other information:

更新了使用文档

@alvinkwok1 alvinkwok1 changed the title feat: gracy destory datasource #578 feat: gracy destory datasource Oct 18, 2023
Copy link
Contributor

@linghengqian linghengqian left a 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.

Comment on lines +56 to +62
// 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);
Copy link
Contributor

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.

Comment on lines +56 to +62
// 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);
Copy link
Contributor

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.

@huayanYu huayanYu merged commit 03c7cff into baomidou:master Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

是否考虑关闭数据源的时候延迟关闭数据源?
3 participants