Skip to content

Commit a62f6b0

Browse files
authored
Fix port; add user pool mode (#395)
* Fix port; add user pool mode * will probably break our session/transaction mode tests
1 parent 89e15f0 commit a62f6b0

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

pgcat.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ password = "sharding_user"
134134
# is the sum of pool_size across all users.
135135
pool_size = 9
136136

137+
137138
# Maximum query duration. Dangerous, but protects against DBs that died in a non-obvious way.
138139
# 0 means it is disabled.
139140
statement_timeout = 0

src/auth_passthrough.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl AuthPassthrough {
7373
password: Some(self.password.clone()),
7474
pool_size: 1,
7575
statement_timeout: 0,
76+
pool_mode: None,
7677
};
7778

7879
let user = &address.username;

src/config.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub struct User {
179179
pub username: String,
180180
pub password: Option<String>,
181181
pub pool_size: u32,
182+
pub pool_mode: Option<PoolMode>,
182183
#[serde(default)] // 0
183184
pub statement_timeout: u64,
184185
}
@@ -190,6 +191,7 @@ impl Default for User {
190191
password: None,
191192
pool_size: 15,
192193
statement_timeout: 0,
194+
pool_mode: None,
193195
}
194196
}
195197
}
@@ -201,7 +203,7 @@ pub struct General {
201203
pub host: String,
202204

203205
#[serde(default = "General::default_port")]
204-
pub port: i16,
206+
pub port: u16,
205207

206208
pub enable_prometheus_exporter: Option<bool>,
207209
pub prometheus_exporter_port: i16,
@@ -261,7 +263,7 @@ impl General {
261263
"0.0.0.0".into()
262264
}
263265

264-
pub fn default_port() -> i16 {
266+
pub fn default_port() -> u16 {
265267
5432
266268
}
267269

@@ -356,6 +358,7 @@ pub enum PoolMode {
356358
#[serde(alias = "session", alias = "Session")]
357359
Session,
358360
}
361+
359362
impl ToString for PoolMode {
360363
fn to_string(&self) -> String {
361364
match *self {
@@ -816,8 +819,9 @@ impl Config {
816819
.to_string()
817820
);
818821
info!(
819-
"[pool: {}] Pool mode: {:?}",
820-
pool_name, pool_config.pool_mode
822+
"[pool: {}] Default pool mode: {}",
823+
pool_name,
824+
pool_config.pool_mode.to_string()
821825
);
822826
info!(
823827
"[pool: {}] Load Balancing mode: {:?}",
@@ -868,7 +872,16 @@ impl Config {
868872
info!(
869873
"[pool: {}][user: {}] Statement timeout: {}",
870874
pool_name, user.1.username, user.1.statement_timeout
871-
)
875+
);
876+
info!(
877+
"[pool: {}][user: {}] Pool mode: {}",
878+
pool_name,
879+
user.1.username,
880+
match user.1.pool_mode {
881+
Some(pool_mode) => pool_mode.to_string(),
882+
None => pool_config.pool_mode.to_string(),
883+
}
884+
);
872885
}
873886
}
874887
}

src/pool.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ impl ConnectionPool {
382382
server_info: Arc::new(RwLock::new(BytesMut::new())),
383383
auth_hash: pool_auth_hash,
384384
settings: PoolSettings {
385-
pool_mode: pool_config.pool_mode,
385+
pool_mode: match user.pool_mode {
386+
Some(pool_mode) => pool_mode,
387+
None => pool_config.pool_mode,
388+
},
386389
load_balancing_mode: pool_config.load_balancing_mode,
387390
// shards: pool_config.shards.clone(),
388391
shards: shard_ids.len(),

0 commit comments

Comments
 (0)