-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not unban replicas if a primary is available #843
Conversation
@magec We had incidents in the past where this failover to primary behavior made matters worse so I am wondering if we should put this behind a config or only enable that behavior if |
Reading through your example, you probably want |
We have The behavior we want was achieved by setting With the change, everything goes as expected, primary works as a failover of the replica, and replica gets retried every "ban_time" seconds. What issues did you encounter with primaries? I dont fully understand. Another approach, as you mention, is making "unban all teplicas when all banned" configurable and true by default (current behavior) that would also do the trick. That said, I think this use-case should be supported, we want protect ourselves from host errors on replicas. |
8ef81cc
to
cb0291e
Compare
…havior.
cb0291e
to
f2ed12e
Compare
@drdrsh I changed the PR so now is a configuration change. I still would like to add an integration test for this, but just wanted to know whether we were aligned. |
That looks good to me. |
Ok, so writing the test I realized there are many things to be taken care of here. Mostly because current main is bugged I reckon as |
I opened another PR with a test for fixing the default_role thing. Now, I am wondering whether it would be better implementing this using
What do you think? |
Well, in the end, I tried the |
This reverts commit cdcfa99.
Our current infrastructure consists in several shards composed by 1 primary and 1 replica each (some shards have more than one replica but this is irrelevant here). Our PgCat configuration permits accessing to each of them (we do not leverage on PgCat for load balancing/etc), i.e. we declare 1 pool per server. Something like:
This is because we cannot use automatic query load balancing due to latency on the replica. Given that our applications already had the notion of 'read only replicas' this schema has been working for us for quite some time.
Now, we are looking for leveraging pgcat to do automatic failover when a replica fails, the approach here would be configuring like:
This way, given that
db_x0_ro
has a default_role ofreplica
it will always use the replica (which is intended), and the primary will only be used when replica is banned.This is what I would expect as normal behavior given this configuration but the code is defending itself from 'all replicas being banned' and it automatically unbans the replica.
I understand that this is a fail safe mechanism to defend pgcat against false positives on replicas being down. My point is that, if we have a primary configured for this pool, we can afford having all replicas banned for a while, once the ban_timeout is reached they will be rechecked and added back to the pool.
This change loosens up this restriction to be only done when the pool has no primaries at all.