Minor cleanup in admin command (#126)

* Minor cleanup in admin command

* Typo correction

* fix when the admin query is ending with semicolon
This commit is contained in:
Pradeep Chhetri
2022-08-17 01:01:46 +08:00
committed by GitHub
parent cea35db35c
commit d64f6793c1
3 changed files with 45 additions and 27 deletions

View File

@@ -92,10 +92,14 @@ password = "postgres"
# is the sum of pool_size across all users. # is the sum of pool_size across all users.
pool_size = 9 pool_size = 9
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
statement_timeout = 0
[pools.sharded.users.1] [pools.sharded.users.1]
username = "postgres" username = "postgres"
password = "postgres" password = "postgres"
pool_size = 21 pool_size = 21
statement_timeout = 15000
# Shard 0 # Shard 0
[pools.sharded.shards.0] [pools.sharded.shards.0]
@@ -133,6 +137,7 @@ sharding_function = "pg_bigint_hash"
username = "postgres" username = "postgres"
password = "postgres" password = "postgres"
pool_size = 5 pool_size = 5
statement_timeout = 0
[pools.simple_db.shards.0] [pools.simple_db.shards.0]
servers = [ servers = [

View File

@@ -92,7 +92,7 @@ password = "sharding_user"
# is the sum of pool_size across all users. # is the sum of pool_size across all users.
pool_size = 9 pool_size = 9
# Maximum query duration. Dangerous, but protetcts against DBs that died and a non-obvious way. # Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
statement_timeout = 0 statement_timeout = 0
[pools.sharded_db.users.1] [pools.sharded_db.users.1]

View File

@@ -44,32 +44,45 @@ where
trace!("Admin query: {}", query); trace!("Admin query: {}", query);
if query.starts_with("SHOW STATS") { let query_parts: Vec<&str> = query.trim_end_matches(';').split_whitespace().collect();
trace!("SHOW STATS");
show_stats(stream).await match query_parts[0] {
} else if query.starts_with("RELOAD") { "RELOAD" => {
trace!("RELOAD"); trace!("RELOAD");
reload(stream, client_server_map).await reload(stream, client_server_map).await
} else if query.starts_with("SHOW CONFIG") { }
trace!("SHOW CONFIG"); "SET" => {
show_config(stream).await trace!("SET");
} else if query.starts_with("SHOW DATABASES") { ignore_set(stream).await
trace!("SHOW DATABASES"); }
show_databases(stream).await "SHOW" => match query_parts[1] {
} else if query.starts_with("SHOW POOLS") { "CONFIG" => {
trace!("SHOW POOLS"); trace!("SHOW CONFIG");
show_pools(stream).await show_config(stream).await
} else if query.starts_with("SHOW LISTS") { }
trace!("SHOW LISTS"); "DATABASES" => {
show_lists(stream).await trace!("SHOW DATABASES");
} else if query.starts_with("SHOW VERSION") { show_databases(stream).await
trace!("SHOW VERSION"); }
show_version(stream).await "LISTS" => {
} else if query.starts_with("SET ") { trace!("SHOW LISTS");
trace!("SET"); show_lists(stream).await
ignore_set(stream).await }
} else { "POOLS" => {
error_response(stream, "Unsupported query against the admin database").await trace!("SHOW POOLS");
show_pools(stream).await
}
"STATS" => {
trace!("SHOW STATS");
show_stats(stream).await
}
"VERSION" => {
trace!("SHOW VERSION");
show_version(stream).await
}
_ => error_response(stream, "Unsupported SHOW query against the admin database").await,
},
_ => error_response(stream, "Unsupported query against the admin database").await,
} }
} }