fix(core): avoid holding pool registry locks during database I/O - #7783
Conversation
t8y2
left a comment
There was a problem hiding this comment.
Request changes.
remove_stale_connection_pool probes outside the registry lock, but it retains identity only for MySQL and Redis. For the other pool kinds, a failed probe reaches connection.rs:3704-3708 and removes by pool_key alone. If a reconnect or replacement inserts a fresh pool under the same key while the probe is in flight, the stale-probe cleanup can delete the new healthy pool.
Please retain an identity handle for every pool kind that can be detached by this path, and remove the entry only if it is still the exact pool that was probed. Add a concurrent replacement regression test for at least one non-MySQL/non-Redis pool.
462380c to
75c89e9
Compare
|
已按建议为所有连接池类型统一增加发布代际标识,并补充了非 MySQL/Redis 场景的并发替换测试。相关修改已推送。 |
# Conflicts: # crates/dbx-core/src/agent_kv.rs
t8y2
left a comment
There was a problem hiding this comment.
维护者补丁已推送:fd11fd7c8(原 head 75c89e9,先并入 main@7e24f4007 —— merge 提交 ff8d373)。冲突仅一处:crates/dbx-core/src/agent_kv.rs(main 的 72dcd83 etcd 重写新增了 agent_key 查找,与本分支改写的注册表读取相邻)。解法:完整保留 main 的 agent_key 块 + 采用本 PR 的 pool_handle 形态,删除被 pool_handle 取代的旧 connections.read().await.get(...) 行 —— etcd2 感知的错误提示与「I/O 期间不持注册表锁」两个行为同时保留;文件中已无残留 guard 读取。range-diff 确认 PR 补丁逐 hunk 完整保留,无被 base 吸收的改动。
附带一个清晰化修复:close_pool_with_timeout 中 self.connections.read().await.clone() 实际经 Deref 解析为内部 HashMap 的 clone(注册表类型本身不是 Clone),改为显式 registry.pools.clone(),锁的持有范围不变。
本地验证:rustfmt 干净、git diff --check 干净;完整 dbx-core 测试由本 head 的 Rust CI 作为合并门槛(本地长测试因磁盘环境受限中断,非代码问题)。
|
Thanks for the contribution! Merged in d6fc1fe, will be released in the next version. |
变更说明
修复长时间数据库操作持有全局连接池注册表锁,导致其他无关连接无法打开或重连的问题。以 MongoDB 4.2 Legacy Agent 执行
CreateIndex为例,索引创建阻塞时不再连带阻塞其他 MongoDB、SQL 或 Redis 数据源。Arc共享 Redis 连接状态,保留原有串行执行与集群扫描状态变更类型
涉及前端
本 PR 不涉及前端改动。
验证
make check通过make cargo-check-fast通过聚焦验证已通过:
cargo check -p dbx-core --libcargo check -p dbx-webcargo test -p dbx-core --lib pool_handle(2 项)cargo test -p dbx-core --lib stale_redis_generation_cannot_remove_replacementcargo test -p dbx-web --no-runCreateIndex注册表写入回归测试手动 E2E 已完成:
CreateIndex,期间其他 MongoDB 与 MySQL 连接均可正常展开CreateIndex期间,MySQL、PostgreSQL 与其他 MongoDB 连接均可正常展开BLPOP期间,MongoDB、MySQL 与 PostgreSQL 连接均可正常展开BLPOP阻塞期间断开并重新连接,新的 DB0 控制台执行PING正常返回PONG关联 Issue
Close #7720