Repository navigation
refactor: 将数据源解包逻辑抽成有序 SPI(承接 #804) - #808
Merged
Merged
Conversation
9 of 21 tasks
huayanYu
force-pushed
the
refactor/datasource-unwrapper-spi
branch
from
October 15, 2026 15:45
47e663e to
90dfdec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更类型 / What kind of change does this PR introduce?
描述 / The description of the PR
Fixes #792。承接 #804(原作者 @Pika-Yalei)。DynamicRoutingDataSource.closeDataSource原本把 P6Spy 与 Seata 的可选代理知识硬编码在自身(instanceof+ 反射读P6DataSource.realDataSource)。本 PR 把这部分知识抽成DataSourceUnwrapperSPI 与一条有序链,使新增代理式集成只需注册 Java service provider,无需改动路由数据源。代码内容与 #804 一致,本 PR 额外只做了一件事——把 #804 的两个提交线性重放到当前
dev上并解决冲突:maintainerCanModify,维护者无法直接更新其分支,因此在此重放同一组提交,并完整保留原作者信息(两个 commit 的 author 均为YaLei <pikapi010410@gmail.com>,已关联其 GitHub 账号)。DynamicRoutingDataSource:dev 侧(aed8872)把getPrimary()由protected改为public并补了 javadoc,而 refactor: extract datasource unwrapping into an ordered SPI #804 的第二个提交在同一锚点上方插入了setP6spy/setSeata/getDataSourceUnwrapperChain。两处互不干涉,取并集;冲突在第二个提交内解决。dev的差异仍为 19 文件 +1078/-18,与 refactor: extract datasource unwrapping into an ordered SPI #804 原始改动集一致(ahead_by: 2,behind_by: 0)。实现要点:
META-INF/services/com.baomidou.dynamic.datasource.unwrapper.DataSourceUnwrapper发现扩展,按Ordered排序ItemDataSource真实池快捷路径catch打 warn;immediate / graceful 销毁语义不变setP6spy/setSeata变更时失效重建ClassUtils.getDefaultClassLoader()(TCCL 优先、Spring 兜底)的类加载器策略影响面 / Impact on the core contracts
这是数据源销毁路径的重构,不改变数据源创建、事务行为、路由、配置项名称或生产依赖作用域。P6Spy / Seata 仍是
compileOnly,仅在测试作用域复用。核心新增字节码仍为 class-file major version 52(Java 8)。自检清单 / Checklist
./gradlew :dynamic-datasource-spring:test通过(100 tests, 0 failures, 0 skipped)Copyright © 2018 organization baomidou)HikariDataSource#getHikariPoolMXBean()与HikariPool#getActiveConnections()的条件化反射元数据,修复了 4 个优雅销毁用例在 native 下缺少 invocation metadata 的失败其他信息 / Other information
#804 与本 PR 内容等价,保留一个即可:合入本 PR 后请关闭 #804;若 @Pika-Yalei 更希望自行 rebase 原分支,也可以关掉本 PR。
评审要点(我在 #804 上的两条评论已记录,其中一条为自我更正):
ServiceLoader。经核实 Native Image 会自动注册构建期类路径上的 provider,且 reachability metadata 并无services类型,因此无需额外注册——这一点我最初判断有误,已在 refactor: extract datasource unwrapping into an ordered SPI #804 更正。