-
Notifications
You must be signed in to change notification settings - Fork 808
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
Question: pool.Reset() alternative for v4 #1235
Comments
I don't remember if that was removed intentionally or it was just lost when the pool was rewritten. It can be more or less duplicated, but not as conveniently. Use |
What if there is no network outage but the server transitioned from a primary to read-only secondary? |
I suppose it would be worth re-implementing. The |
Funny enough, literally yesterday I was upset that this method was removed. I need a way to recreate connections after aws autora failover. |
Any specific high-level pointers? I could try getting something together in the next couple of weeks. |
It's a little subtle. Broadly speaking there are two approaches. The most obvious approach is to swap the underlying puddle pool. Unfortunately, this would require guarding all accesses to that pool with a mutex or using atomics. It may or may not make a significant performance difference but adding an synchronization to every pool access regardless of whether reset would ever be used is unfortunate. The other approach is to add But this approach is also complicated because I wasn't anticipating any further changes to puddle as used by pgx |
I have a similar problem as well. Line 456 in 91c9e84
|
Regarding It could probably be ported back to pgx |
Thanks for the update on Reset. That is awesome! What are your thoughts on adding a user over-ridable function pointer for custom validation in checkConnsHealth()? I am happy to write one if you think it is worth adding. I have seen these in many of the JDBC drivers/pools implementations and did not find anything equivalent in Go, so the request |
Your existing use of
I'm open to it in theory, but in practice I suspect it might be tricky. The health check code is rather subtle in that it tries to avoid avoid even temporarily going over max conns, tries to minimize going under min conns, and tries to minimize multiple connections being closed or opened in parallel. I don't know of an obvious, clean way to integrate a user level check into that system. One other subtlety that might affect this is there are different types of health checks. Checks such as detecting a connection is too old, or has been idle for too long, or there are too few connections in the pool detect sub-optimal but non-error conditions. If a connection is used a few seconds longer than its max age it doesn't really matter. But there are also errors such as a network failure or a database schema change that can immediately render all existing connections broken. The existing internal health check system is entirely focused on the former. The latter left to the application to handle with |
Those are both good points. Just for the sake of consistency it may not be a good idea to club 2 things whose behaviour and consequences may be different. On the trickiness aspect, I can take a look. Let me contemplate on this a bit more and if I am able to solve it well (IMHO), then I'll open a PR. I am away on vacation till August 19th. Looking forward to picking this up when I am back. I think the reset is still a great add. |
One of the reasons why I felt that it would be a good idea to implement it within core pgx Pool implementations was the integration with ORMs. As you know these days most people end up using an ORM (I am not a fan) and some of them have built integration with Pgx, so it may make it easier. |
In v3, there is a pool.Reset() to reset the connection pool in case of a change in networking configuration (or rather for any reason).
I don't see anything similar in v4.
Is there a way to achieve a similar effect in v4?
The text was updated successfully, but these errors were encountered: