Skip to content

Commit 33e4ee6

Browse files
authored
Disable LB host banning when no alternative targets available
1 parent 3b5c98c commit 33e4ee6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pgdog/src/backend/databases.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,20 @@ pub(crate) fn new_pool(
370370
if let Some(shards) = shards {
371371
let mut shard_configs = vec![];
372372
for user_databases in shards {
373+
let has_single_replica = user_databases.len() == 1;
373374
let primary = user_databases
374375
.iter()
375376
.find(|d| d.role == Role::Primary)
376377
.map(|primary| PoolConfig {
377378
address: Address::new(primary, user),
378-
config: Config::new(general, primary, user),
379+
config: Config::new(general, primary, user, has_single_replica),
379380
});
380381
let replicas = user_databases
381382
.iter()
382383
.filter(|d| d.role == Role::Replica)
383384
.map(|replica| PoolConfig {
384385
address: Address::new(replica, user),
385-
config: Config::new(general, replica, user),
386+
config: Config::new(general, replica, user, has_single_replica),
386387
})
387388
.collect::<Vec<_>>();
388389

pgdog/src/backend/pool/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Config {
139139
}
140140

141141
/// Create from database/user configuration.
142-
pub fn new(general: &General, database: &Database, user: &User) -> Self {
142+
pub fn new(general: &General, database: &Database, user: &User, is_only_replica: bool) -> Self {
143143
Config {
144144
min: database
145145
.min_pool_size
@@ -182,6 +182,7 @@ impl Config {
182182
.read_only
183183
.unwrap_or(user.read_only.unwrap_or_default()),
184184
prepared_statements_limit: general.prepared_statements_limit,
185+
bannable: !is_only_replica,
185186
..Default::default()
186187
}
187188
}

0 commit comments

Comments
 (0)