In pgdog/src/backend/pool/lb/mod.rs:
let primary_reads = match self.rw_split {
IncludePrimary => true,
IncludePrimaryIfReplicaBanned => candidates.iter().any(|target| target.ban.banned()),
// Under PreferPrimary, default queries already route to the primary as writes;
// a read only reaches here when it explicitly opted into replicas, so honor it
// like ExcludePrimary and fall back to the primary only if there are no replicas.
ExcludePrimary | PreferPrimary => !candidates
.iter()
.any(|target| matches!(target.role(), Role::Replica | Role::Auto)),
};
if !primary_reads {
candidates.retain(|target| matches!(target.role(), Role::Replica | Role::Auto));
}
when candidates = [primary] (i.e. there's no replicas), all options evaluate to primary_reads = true - except for IncludePrimaryIfReplicaBanned, that evaluates to false and then removes the primary from candidates.
I propose that all branches evaluate to true in that case, e.g. IncludePrimaryIfReplicaBanned => candidates.len() <= 1 || candidates.iter().any(|target| target.ban.banned()), or even let primary_reads = candidates.len() <= 1 || match self.rw_split {
In
pgdog/src/backend/pool/lb/mod.rs:when
candidates = [primary](i.e. there's no replicas), all options evaluate toprimary_reads = true- except forIncludePrimaryIfReplicaBanned, that evaluates tofalseand then removes the primary fromcandidates.I propose that all branches evaluate to
truein that case, e.g.IncludePrimaryIfReplicaBanned => candidates.len() <= 1 || candidates.iter().any(|target| target.ban.banned()),or evenlet primary_reads = candidates.len() <= 1 || match self.rw_split {