Repository navigation
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Metal bench (arm64) failed. 155 of 520 measures outside bounds.
Counters per txn
Microbench: 353 of 507 measures within bounds. See verdict.json for the rest. Microbench latency: 18 benches changed more than 3%
Hot code per txn
pooler:
sharding-w2:
Logslb, microbench, pooler, sharding-w2, sharding-w8, verdict.json |
|
Metal bench (x86) failed. 152 of 520 measures outside bounds.
Counters per txn
Microbench: 355 of 507 measures within bounds. See verdict.json for the rest. Microbench latency: 21 benches changed more than 3%
Hot code per txn
pooler:
sharding-w2:
Logslb, microbench, pooler, sharding-w2, sharding-w8, verdict.json |
|
Going to wait on #2077 before merging. |
2a49b0c to
56897d2
Compare
| other.database_number = self.database_number; | ||
| other.passwords = self.passwords.clone(); | ||
| self == &other |
There was a problem hiding this comment.
should we add new fields to this check to avoid reconnections?
| /// Minimum replica LSN the client wants the replica to have | ||
| /// before allowing reads on it, in its 64-bit representation. | ||
| pub(crate) lsn: Option<u64>, |
There was a problem hiding this comment.
should we move lsn also to the LbRequest?
| ) -> Self { | ||
| Self { | ||
| request: PoolRequest::new(id, route, created_at), | ||
| label: route.label.clone(), |
There was a problem hiding this comment.
wonder if we can drop the clone here and make the LbRequest with lifetime instead.
| @@ -447,12 +457,14 @@ | |||
| return Err(Error::AllReplicasDown); | |||
There was a problem hiding this comment.
if we found no candidates for the label we'll get this error, which is not quite right and we probably need a separate error
| let replicas = LoadBalancer::new( | ||
| &None, | ||
| &[reporting, analytics, backup], | ||
| LoadBalancingStrategy::RoundRobin, | ||
| ReadWriteSplit::ExcludePrimary, | ||
| Default::default(), | ||
| ); |
There was a problem hiding this comment.
nit: I've added helper super::test_lb that maybe helpful
| let mut route = Route::read(ShardWithPriority::default()); | ||
| route.label = Some("reporting".into()); | ||
| let request = LbRequest::new(Default::default(), &route, false, Instant::now()); |
There was a problem hiding this comment.
nit: this probably could be put to function to reuse in tests instead of duplication
| // make sure we don't use the banned targets calculations, | ||
| // since it can skew the distribution when we have banned instances | ||
| // Let labeled requests use banned targets when no unbanned replica remains. | ||
| let ignore_ban = request.label.is_some() && !has_unbanned_replica(&candidates); |
There was a problem hiding this comment.
ok, this will probably won't work well if the primary has the label and all replicas with label are banned, we'll ignore the bans instead routing to primary in this case
There was a problem hiding this comment.
anyway, I'm worried about this approach of doing the fallback here, since any label misspell or config misconfiguration could show working queries instead of signaling of issues.
I faced the same controversy for the pgdog.role refactor - it sounds like the real cases may want different outcome (fail or use fallback) and not strict rule. I don't like very much that the routing can stop working as expected without visual signs
| candidates | ||
| .iter() | ||
| .for_each(|target| target.ban.unban(true, UnbanReason::AllTargetsBanned)); |
There was a problem hiding this comment.
oh, that may backfire with labels - if a single query with label doesn't find it's target, we'll unban the whole cluster here.
Description
Fix #2051
Support comment-based routing to specific set of replicas. This allows the caller to specify which replicas each query should use, based on a pre-configured label.
Example
The caller can select which database(s) each query uses as follows:
Implementation details
Labeled queries will ignore host bans if the number of replicas it can send the query to is 0. For example, if you have two "analytics" replicas, and one of them is banned, the other will serve all queries, but if both are, the bans will be ignored and the query will attempt to connect to one of them using
load_balancing_algorithm.We are re-using
pgdog_rolebecause the routing decision conflicts withprimary/replicaand the caller expects the label to respected over a read/write preference.Mandatory labels
By default, a query without a label will be routed between all replicas. This may not be desirable, e.g., you'd want to exclude some underpowered or special replicas from regular traffic.
You can do this with a config:
Queries without a label will not be routed to this replica.
Specifying labels
Labels can be specified in the query as follows:
/* pgdog_role: analytics */SET pgdog.role TO 'analytics'or via connection parameter, e.g.,-c pgdog.role=analyticsReviewer notes
Requestwas split up intoLbRequestandRequest, to avoid passing information to thePoolit doesn't need.