/** * 连接池服务 - 管理数据库适配器的创建和复用 * 借鉴 DatabaseMcpServer 的 SqlSugarScope 设计 */ import type { DbAdapter } from '../types/adapter.js'; /** * 健康状态接口 */ export interface HealthStatus { /** 连接名称 */ name: string; /** 数据库类型 */ type: string; /** 是否已连接 */ connected: boolean; /** 响应时间(毫秒) */ responseTime: number; /** 最后检查时间 */ lastChecked: Date; /** 错误信息(如果有) */ error?: string; } /** * 连接池服务类 * 管理数据库适配器的生命周期,支持复用和健康检查 */ export declare class ConnectionPoolService { private pools; private connecting; /** * 获取或创建数据库适配器 * 使用连接池复用已创建的适配器 * @param connectionName 连接名称(可选,默认使用当前活动连接) * @returns 数据库适配器实例 */ getAdapter(connectionName?: string): Promise; /** * 创建并连接适配器 */ private createAndConnect; /** * 根据连接配置创建适配器实例 */ private createAdapter; /** * 关闭指定连接 * @param connectionName 连接名称 */ closeConnection(connectionName: string): Promise; /** * 关闭所有连接 */ closeAll(): Promise; /** * 对所有已连接的数据库执行健康检查 * @returns 健康状态列表 */ healthCheck(): Promise; /** * 测试单个连接 */ private testConnection; /** * 带重试的连接测试 * @param connectionName 连接名称 * @param maxRetries 最大重试次数 * @param baseDelayMs 基础延迟毫秒数 * @returns 健康状态 */ testConnectionWithRetry(connectionName: string, maxRetries?: number, baseDelayMs?: number): Promise; private sleep; /** * 获取连接池状态 */ getPoolStatus(): { name: string; connected: boolean; }[]; /** * 从 MongoDB URI 中提取第一个 host:port(用于 SSH 隧道建立) */ private extractFirstHostFromUri; /** * 将 MongoDB URI 中的所有 host:port 替换为本地隧道地址 * 集群模式下多节点会被合并为单个本地隧道入口 * * SSH 隧道场景下必须: * 1. 去掉 replicaSet 参数(隧道后驱动无法访问拓扑中的其他节点) * 2. 添加 directConnection=true(强制直连单节点,不做拓扑发现) */ private rewriteMongoUri; } export declare const connectionPool: ConnectionPoolService; //# sourceMappingURL=connection-pool.d.ts.map