Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(connection): size metadata gate by real session pool capacity

Ghyper902356f85a2c776e
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index ff45092f67..1368a8265c 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -396,6 +396,29 @@ pub(crate) fn uses_metadata_gate(db_type: DatabaseType) -> bool {
matches!(db_type, DatabaseType::Mysql | DatabaseType::Postgres | DatabaseType::SqlServer)
}
+/// Session-scoped metadata gate allowance for a database type.
+///
+/// A non-empty `client_session_id` normally means the caller opened a
+/// dedicated single-connection session pool (for example MySQL tab sessions),
+/// so the gate allows only one in-flight metadata operation. PostgreSQL is the
+/// exception: `get_or_create_pool_for_session` builds a fresh full-size
+/// (10-connection) pool for each export session, so an allowance of 1 would
+/// serialize the database-export metadata prefetch (4 concurrent DDL/column
+/// lookups) and make three of them time out after METADATA_POOL_ACQUIRE_TIMEOUT
+/// with "DBX metadata pool is busy". Returning the pool's real capacity here
+/// flows into metadata_concurrency_limit, which caps the effective gate at
+/// METADATA_POOL_DEFAULT_LIMIT (6) -- still enough for the 4-wide prefetch and
+/// still isolated from the UI/base pool.
+fn metadata_gate_session_allowance(db_type: DatabaseType) -> usize {
+ if db_type == DatabaseType::Postgres {
+ // Matches db::postgres::connect's Pool::builder().max_size(10).
+ 10
+ } else {
+ // MySQL and other session-scoped pools are single-connection.
+ 1
+ }
+}
+
fn metadata_gate_key(
connection_id: &str,
database: Option<&str>,
@@ -1369,8 +1392,8 @@ impl AppState {
client_session_id: Option<&str>,
) -> Result<OwnedSemaphorePermit, String> {
let key = metadata_gate_key(connection_id, database, db_type, client_session_id);
- let max_connections =
- if client_session_id.map(str::trim).is_some_and(|session| !session.is_empty()) { 1 } else { 10 };
+ let has_session = client_session_id.map(str::trim).is_some_and(|session| !session.is_empty());
+ let max_connections = if has_session { metadata_gate_session_allowance(db_type) } else { 10 };
let limit = metadata_concurrency_limit(db_type, max_connections);
let gate = {
let mut gates = self.metadata_gates.lock().await;
@@ -7844,6 +7867,18 @@ mod tests {
assert_eq!(super::metadata_concurrency_limit(DatabaseType::SqlServer, 10), 1);
}
+ #[test]
+ fn session_metadata_gate_allowance_matches_session_pool_capacity() {
+ // PostgreSQL session pools are full-size (10 connections, see
+ // db/postgres.rs Pool::builder().max_size(10)), so the gate must not
+ // serialize the database-export prefetch down to one permit.
+ assert_eq!(super::metadata_gate_session_allowance(DatabaseType::Postgres), 10);
+ // MySQL and other session-scoped pools are single-connection.
+ assert_eq!(super::metadata_gate_session_allowance(DatabaseType::Mysql), 1);
+ // SQL Server gate is intentionally shared/serialized regardless.
+ assert_eq!(super::metadata_gate_session_allowance(DatabaseType::SqlServer), 1);
+ }
+
#[test]
fn metadata_gate_is_limited_to_supported_pool_drivers() {
assert!(super::uses_metadata_gate(DatabaseType::Mysql));