fix: 连接池懒加载+有效性校验,驱动资源清理与友好错误提示#1
Merged
Merged
Conversation
针对 2.1.0 引入的连接池/驱动加载逻辑做健壮性修复: - QueryTool: 连接池由「一次性预建 10 个连接」改为懒加载,按需创建(上限 10)。 取连接时用 Connection.isValid() 校验,失效连接丢弃并按需重建,避免长时间空闲后 使用到被数据库侧断开的 stale 连接。单个连接创建失败只抛 SQLException 且不污染 连接池,不再首次查询即整体 RuntimeException;归还时校验是否已关闭。 - DataSourceDriverUtil: 跟踪注册的驱动 shim 与 URLClassLoader,新增 deregisterAllDrivers() 在 dispose 时反注册并关闭类加载器,避免长期驻留; 驱动未下载(ClassNotFound/NoClassDefFound)时给出可操作的友好提示,引导用户 先在 DataGrip 数据源里下载该驱动。 - DataPivotInitializer: 项目 dispose 时一并清理连接池与已注册驱动 (此前 closeAllConnections 从未被调用,连接会泄漏)。 - DataGripUtil: collectNamingNames 递归增加 node/group/child/name 的 null 防御。 - i18n: 新增驱动未下载、驱动注册失败的中英文提示文案。 https://claude.ai/code/session_01HYez8dwWXxDUsygNsoKWT9
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.
背景
针对
4ce8355 (chore: prepare 2.1.0 release)引入的连接池 / 驱动加载逻辑做健壮性修复。逐条核对了 review 中提出的 5 个问题,均确认存在,本 PR 全部处理。getOrCreateConnectionPool一次性预建 10 个连接,任一失败抛RuntimeException(首次查询即整体失败)。另外存在隐藏 bug:中途失败时已建连接泄漏、computeIfAbsent未缓存导致每次重试都重开 10 个poll/offer),长时间空闲后可能 staleURLClassLoader与DriverShim永不释放;且closeAllConnections()从未被调用,连接同样泄漏collectNamingNames递归未判child != nullIllegalStateException,提示不友好改动
QueryTool(问题 1、2) —— 连接池改为懒加载:MAX_CONNECTIONS=10),首次查询只建 1 个,不再一次性预建 10 个;Connection.isValid(2s)校验,失效则关闭丢弃并重建,规避数据库侧断连后的 stale 连接;SQLException、不污染连接池且不泄漏(预占的 slot 会回退),下次查询可正常恢复;DataSourceDriverUtil(问题 3、5):shim与URLClassLoader,新增deregisterAllDrivers(),dispose 时反注册并close()类加载器;ClassNotFoundException/NoClassDefFoundError)时给出可操作的友好提示,引导用户先在 DataGrip 数据源里下载该驱动;其余失败走通用提示。DataPivotInitializer(问题 3) —— 项目 dispose 时一并清理连接池与已注册驱动(此前closeAllConnections从未被注册,连接会一直泄漏)。DataGripUtil(问题 4) ——collectNamingNames递归补全node/group/child/name的 null 防御。i18n —— 新增
data.pivot.driver.not.downloaded、data.pivot.driver.register.fail的中英文文案(default / zh_CN / en_US)。验证
由于本环境网络策略屏蔽了 JetBrains 仓库(
download.jetbrains.com返回 403),无法跑完整 Gradle 构建。连接池是最易出错的部分,因此用与补丁完全一致的方法体(仅把createConnection换成可控的java.sql.Connection动态代理)写了独立用例验证,18 项断言全部通过:isValid=false)连接不下发、被关闭并重建,计数不漂移;SQLException不泄漏 slot,且后续可恢复;closeAll正确清空并归零计数。https://claude.ai/code/session_01HYez8dwWXxDUsygNsoKWT9
Generated by Claude Code