Fix port; add user pool mode (#395)

* Fix port; add user pool mode

* will probably break our session/transaction mode tests
This commit is contained in:
Lev Kokotov
2023-04-05 15:06:19 -07:00
committed by GitHub
parent 89e15f09b5
commit a62f6b0eea
4 changed files with 24 additions and 6 deletions

View File

@@ -134,6 +134,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 protects against DBs that died in a non-obvious way. # Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
# 0 means it is disabled. # 0 means it is disabled.
statement_timeout = 0 statement_timeout = 0

View File

@@ -73,6 +73,7 @@ impl AuthPassthrough {
password: Some(self.password.clone()), password: Some(self.password.clone()),
pool_size: 1, pool_size: 1,
statement_timeout: 0, statement_timeout: 0,
pool_mode: None,
}; };
let user = &address.username; let user = &address.username;

View File

@@ -179,6 +179,7 @@ pub struct User {
pub username: String, pub username: String,
pub password: Option<String>, pub password: Option<String>,
pub pool_size: u32, pub pool_size: u32,
pub pool_mode: Option<PoolMode>,
#[serde(default)] // 0 #[serde(default)] // 0
pub statement_timeout: u64, pub statement_timeout: u64,
} }
@@ -190,6 +191,7 @@ impl Default for User {
password: None, password: None,
pool_size: 15, pool_size: 15,
statement_timeout: 0, statement_timeout: 0,
pool_mode: None,
} }
} }
} }
@@ -201,7 +203,7 @@ pub struct General {
pub host: String, pub host: String,
#[serde(default = "General::default_port")] #[serde(default = "General::default_port")]
pub port: i16, pub port: u16,
pub enable_prometheus_exporter: Option<bool>, pub enable_prometheus_exporter: Option<bool>,
pub prometheus_exporter_port: i16, pub prometheus_exporter_port: i16,
@@ -261,7 +263,7 @@ impl General {
"0.0.0.0".into() "0.0.0.0".into()
} }
pub fn default_port() -> i16 { pub fn default_port() -> u16 {
5432 5432
} }
@@ -356,6 +358,7 @@ pub enum PoolMode {
#[serde(alias = "session", alias = "Session")] #[serde(alias = "session", alias = "Session")]
Session, Session,
} }
impl ToString for PoolMode { impl ToString for PoolMode {
fn to_string(&self) -> String { fn to_string(&self) -> String {
match *self { match *self {
@@ -816,8 +819,9 @@ impl Config {
.to_string() .to_string()
); );
info!( info!(
"[pool: {}] Pool mode: {:?}", "[pool: {}] Default pool mode: {}",
pool_name, pool_config.pool_mode pool_name,
pool_config.pool_mode.to_string()
); );
info!( info!(
"[pool: {}] Load Balancing mode: {:?}", "[pool: {}] Load Balancing mode: {:?}",
@@ -868,7 +872,16 @@ impl Config {
info!( info!(
"[pool: {}][user: {}] Statement timeout: {}", "[pool: {}][user: {}] Statement timeout: {}",
pool_name, user.1.username, user.1.statement_timeout pool_name, user.1.username, user.1.statement_timeout
) );
info!(
"[pool: {}][user: {}] Pool mode: {}",
pool_name,
user.1.username,
match user.1.pool_mode {
Some(pool_mode) => pool_mode.to_string(),
None => pool_config.pool_mode.to_string(),
}
);
} }
} }
} }

View File

@@ -382,7 +382,10 @@ impl ConnectionPool {
server_info: Arc::new(RwLock::new(BytesMut::new())), server_info: Arc::new(RwLock::new(BytesMut::new())),
auth_hash: pool_auth_hash, auth_hash: pool_auth_hash,
settings: PoolSettings { settings: PoolSettings {
pool_mode: pool_config.pool_mode, pool_mode: match user.pool_mode {
Some(pool_mode) => pool_mode,
None => pool_config.pool_mode,
},
load_balancing_mode: pool_config.load_balancing_mode, load_balancing_mode: pool_config.load_balancing_mode,
// shards: pool_config.shards.clone(), // shards: pool_config.shards.clone(),
shards: shard_ids.len(), shards: shard_ids.len(),