Skip to content
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

Allow the r2d2 ConnectionManager to change URL dynamically #4005

Merged
merged 1 commit into from
May 3, 2024

Conversation

smklein
Copy link
Contributor

@smklein smklein commented Apr 30, 2024

Why

oxidecomputer/omicron#3763 has all the context for why I'm putting this PR up, but the short story is:

  • For databases with distributed backends, it's often a requirement that the "set of nodes queried" by Diesel changes over time. In the example issue above, this is for CockroachDB, where we query one of many nodes. But new nodes can be added, and existing nodes can go offline.
  • In cases where one of those nodes is known to go offline, it's nice to be able to update the URL being accessed without disrupting all existing connections that are currently communicating with healthy nodes.
  • We're using SRV-based DNS records, which libpq does not interpret, so "just refer to a DNS name" doesn't really work that well to find the database. My expectation is that someone trying to do this would use DNS resolution "above Diesel", and then call this new update_database_url function to change which backend(s) are being accessed.

What

This PR adds a single function to modify the URL for accessing the database within the ConnectionManager. This field database_url is only used in one spot: in the implementation of ManageConnection::connect, when creating new connections.

@weiznich
Copy link
Member

weiznich commented May 3, 2024

CI is currently broken due to rust-lang/rust#124396. I will merge this PR after the fix in #4008 landed.

@weiznich weiznich enabled auto-merge May 3, 2024 11:32
@weiznich weiznich added this pull request to the merge queue May 3, 2024
Merged via the queue into diesel-rs:master with commit aa1360b May 3, 2024
48 checks passed
@smklein smklein deleted the update_database_url branch May 6, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants