-
Notifications
You must be signed in to change notification settings - Fork 468
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
adapter: refactor max connection handling #30624
adapter: refactor max connection handling #30624
Conversation
* pull connection handling out of the sql crate and into pgwire_common * refactor SystemVars to have a set of callbacks to notify interested folks in changes to variables * refactor max connection handling so we don't panic if the limit drops to less than current number of connections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, had a couple of small questions and nits. It also might be good to add a test where we lower the connection limit with a bunch of connections open to repro the panic.
src/adapter/src/coord.rs
Outdated
// If superuser_reserved > max_connections, prefer max_connections. | ||
let superuser_reserved = std::cmp::min(limit, superuser_reserved); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If superuser_reserved > max_connections
is true, then that means only super users could connect to the database right? i.e., all connections are reserved for superusers and normal users will be locked out. That feels like a bad enough situation that we should add an error log here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great call, added a soft assert here!
* add some extra asserts * update comments * add test case to make sure we don't panic when dropping below number of open connections
Added a test that previously repro'd the panic! |
This PR refactors our max connection handling in a few ways:
sql
crate and moves it into thepgwire_common
crate. AFAICT this logic lived in thesql
crate so it could be updated viaSystemVars
.SystemVars
to contain a generic set of callbacks so anyone can register to be notified about changes to a system variable, not just connection handling.It also fixes a bug that has occurred in production. Previously if the max connection limit dropped below the number of current connections (e.g. reducing the LaunchDarkly flag) we could panic.
Motivation
Fixes a known panic and refactors the code.
Tips for reviewer
I would start by reviewing the changes in
sql/src/session/vars.rs
to see how SystemVars changed, then look at the changes inpgwire-common/src/conn.rs
.Checklist
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way), then it is tagged with aT-proto
label.