Skip to content

Commit

Permalink
Fix port; add user pool mode (#395)
Browse files Browse the repository at this point in the history
* Fix port; add user pool mode

* will probably break our session/transaction mode tests
  • Loading branch information
levkk authored Apr 5, 2023
1 parent 89e15f0 commit a62f6b0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions pgcat.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ password = "sharding_user"
# is the sum of pool_size across all users.
pool_size = 9


# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
# 0 means it is disabled.
statement_timeout = 0
Expand Down
1 change: 1 addition & 0 deletions src/auth_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl AuthPassthrough {
password: Some(self.password.clone()),
pool_size: 1,
statement_timeout: 0,
pool_mode: None,
};

let user = &address.username;
Expand Down
23 changes: 18 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub struct User {
pub username: String,
pub password: Option<String>,
pub pool_size: u32,
pub pool_mode: Option<PoolMode>,
#[serde(default)] // 0
pub statement_timeout: u64,
}
Expand All @@ -190,6 +191,7 @@ impl Default for User {
password: None,
pool_size: 15,
statement_timeout: 0,
pool_mode: None,
}
}
}
Expand All @@ -201,7 +203,7 @@ pub struct General {
pub host: String,

#[serde(default = "General::default_port")]
pub port: i16,
pub port: u16,

pub enable_prometheus_exporter: Option<bool>,
pub prometheus_exporter_port: i16,
Expand Down Expand Up @@ -261,7 +263,7 @@ impl General {
"0.0.0.0".into()
}

pub fn default_port() -> i16 {
pub fn default_port() -> u16 {
5432
}

Expand Down Expand Up @@ -356,6 +358,7 @@ pub enum PoolMode {
#[serde(alias = "session", alias = "Session")]
Session,
}

impl ToString for PoolMode {
fn to_string(&self) -> String {
match *self {
Expand Down Expand Up @@ -816,8 +819,9 @@ impl Config {
.to_string()
);
info!(
"[pool: {}] Pool mode: {:?}",
pool_name, pool_config.pool_mode
"[pool: {}] Default pool mode: {}",
pool_name,
pool_config.pool_mode.to_string()
);
info!(
"[pool: {}] Load Balancing mode: {:?}",
Expand Down Expand Up @@ -868,7 +872,16 @@ impl Config {
info!(
"[pool: {}][user: {}] 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(),
}
);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ impl ConnectionPool {
server_info: Arc::new(RwLock::new(BytesMut::new())),
auth_hash: pool_auth_hash,
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,
// shards: pool_config.shards.clone(),
shards: shard_ids.len(),
Expand Down

0 comments on commit a62f6b0

Please sign in to comment.