Repository navigation
build(native): drop the HikariCP metadata copy, keep our own HikariCP reflection - #824
Merged
huayanYu merged 2 commits intoOct 20, 2026
Merged
Conversation
…ke it com.zaxxer/HikariCP/6.3.3 mixed HikariCP's own metadata with reflection that dynamic-datasource itself does on HikariCP types. Move the latter into com.baomidou/dynamic-datasource-creator and com.baomidou/dynamic-datasource-spring, named after the module that makes each call, and condition every entry on the calling class instead of on the HikariCP type. In dynamic-datasource-creator, HikariDataSourceCreator.fetchMethod() and ConfigMergeCreator.setField() need the public methods of HikariConfig. The no-arg constructor that ConfigMergeCreator.create() calls moves over from com.baomidou/dynamic-datasource-native-metadata with its condition unchanged. In dynamic-datasource-spring, DefaultDataSourceDestroyer.destroy() and ItemDataSource.close() look up HikariDataSource.close(), and HikariDataSourceActiveDetector calls HikariDataSource.getHikariPoolMXBean() and HikariPool.getActiveConnections(). Only HikariCP's own two entries are left in com.zaxxer/HikariCP/6.3.3. Refs baomidou#820
…y covers The two entries left in com.zaxxer/HikariCP/6.3.3 are HikariCP's own: HikariConfig allDeclaredFields, which HikariConfig.copyStateTo() needs, and ConcurrentBag$IConcurrentBagEntry[]. oracle/graalvm-reachability-metadata has both in its HikariCP 7.0.2 metadata, and both starters enable that repository for nativeTest. Boot 4 resolves HikariCP 7.0.2. Boot 3.5.7 resolves 6.3.3, which is in no tested-versions list, so NBT falls back to the latest entry, 7.0.2, there too. Refs baomidou#820
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
说明为什么需要这个改动,而不只是改了什么;关联对应的 issue(
Fixes #123)。Refs #820. This is the HikariCP part. The Druid part still waits for oracle/graalvm-reachability-metadata#10927.
com.zaxxer/HikariCP/6.3.3indynamic-datasource-native-metadatamixed two kinds of entries. Some are HikariCP's own metadata, which belongs in oracle/graalvm-reachability-metadata and is already there. The others are reflection that dynamic-datasource itself does on HikariCP types. This PR keeps the second kind, under the name of the module that makes the call, and drops the first.This PR has two commits:
build(native): move our HikariCP reflection under the modules that make itcom.baomidou/dynamic-datasource-creator/reachability-metadata.json: the public methods ofHikariConfig, forHikariDataSourceCreator.fetchMethod()andConfigMergeCreator.setField(), and the no-arg constructor thatConfigMergeCreator.create()calls. The constructor entry moves over fromcom.baomidou/dynamic-datasource-native-metadatawith its condition unchanged.com.baomidou/dynamic-datasource-spring/reachability-metadata.json:HikariDataSource.close(), forDefaultDataSourceDestroyer.destroy()andItemDataSource.close(), andHikariDataSource.getHikariPoolMXBean()andHikariPool.getActiveConnections(), forHikariDataSourceActiveDetector.dynamic-datasource-native-metadata, which is still the one module the Boot 3/4 starters get their metadata from.build(native): drop the HikariCP metadata that the upstream repository covers: the two entries left,HikariConfigallDeclaredFieldsandConcurrentBag$IConcurrentBagEntry[], are in oracle's HikariCP 7.0.2 metadata. NBT selects that file for the test runtime classpath of both starters. Boot 4 resolves HikariCP 7.0.2. Boot 3.5.7 resolves 6.3.3, which is in notested-versionslist, so NBT falls back to thelatestentry, 7.0.2.Both commits update the layout comment in
dynamic-datasource-native-metadata/build.gradleand the note in CONTRIBUTING.md 2.1.影响面 / Impact on the core contracts
本框架的核心契约很窄,改动通常会波及其中之一,请勾选并说明:
@DS解析 /DynamicDataSourceContextHolder的切换与栈语义(含多层嵌套、同类内部调用)@DSTransactional、savepoint、XA/Atomikos、Seata)GroupDataSource、strategy)ENC(...)加解密 / 配置属性(新增或改名配置项)新增/改名配置项时,请同步文档 https://doc.xiuceyun.cn 与
DynamicDataSourceProperties的 Javadoc。The published
dynamic-datasource-native-metadatajar no longer carries HikariCP's own metadata. A native build now gets it from the GraalVM reachability metadata repository, which the NBT Gradle and Maven plugins enable by default. A build that turns the repository off losesHikariConfigallDeclaredFields, andnew HikariDataSource(config)then fails inHikariConfig.copyStateTo(), as the last removal check below shows. The POMs do not change.自检清单 / Checklist
./gradlew clean test通过(Gradle 客户端要求 17+;Boot 2 线模块由 JDK 8 toolchain 编译测试)./gradlew buildCopyright © 2018 organization baomidou)fix:/feat:/build:/docs:…),一个 commit 做一件事No test is added: the change only moves and removes metadata, and the existing
AddRemoveDatasourceTestand endpoint scenarios already fail innativeTestwithout it (see below). The only new files are the two JSON files, and JSON has no place for a license header, like the existing metadata files.其他信息 / Other information
Verified locally with GraalVM CE 25.4.4.1 (JDK 25.0.4.1) running Gradle, on
dev@ 7c321c1 plus this change. NBT used reachability metadata repository version 1.0.14../gradlew clean build --no-build-cache: all modules pass, with all 65 tasks executed (Boot 2/3/4 starters: 47/52/48 tests).nativeTestfordynamic-datasource-spring-boot3-starter(52 found, 46 passed, 6 skipped) anddynamic-datasource-spring-boot4-starter(48 found, 46 passed, 2 skipped): pass.nativeTestnotices each part, I ran the Boot 4nativeTestin a throwaway worktree with one part taken out at a time:com.baomidou/dynamic-datasource-spring, 10AddRemoveDatasourceTestcases fail. Eight getMissingReflectionRegistrationError: Cannot reflectively invoke method 'public void com.zaxxer.hikari.HikariDataSource.close()', and in the two graceful-removal cases the pool never closes.com.baomidou/dynamic-datasource-creator, 11 tests fail. Ten getCannot reflectively invoke constructor 'public com.zaxxer.hikari.HikariConfig()', and the endpoint test's context does not load.com.baomidou/dynamic-datasource-creator, 10 tests fail withCannot reflectively invoke method 'public void com.zaxxer.hikari.HikariConfig.setConnectionTimeout(long)'.excludedModules.add('com.zaxxer:HikariCP')inmetadataRepository, 11 tests fail withCannot reflectively read or write field 'private volatile int com.zaxxer.hikari.HikariConfig.maxPoolSize'.HikariDataSource(HikariConfig)callscopyStateTo(), which copies every declared field by reflection.CollectReachabilityMetadatatask registered on each starter'stestRuntimeClasspaththrough an init script copied oracle's HikariCP 7.0.2 file for both starters, byte for byte.Two of the entries are not reached by any test, before or after this PR:
ItemDataSource.close(). A stack trace printed from it during the Boot 4 JVM tests never showed up. So theHikariDataSource.close()entry conditioned onItemDataSourceis not exercised.lazy: true, soHikariDataSourceCreator.createDataSource()never callscopyStateTothroughconfigCopyMethod. TheHikariConfigpublic methods it needs are registered under bothHikariDataSourceCreatorandConfigMergeCreator. Both conditions are met as soon asHikariDataSourceCreatorinitialises, so the checks above cannot tell the two entries apart.