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

nexus: use all CockroachDB hosts from DNS to create DB connection URL. #3783

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions nexus/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,21 @@ impl ServerContext {
nexus_config::Database::FromUrl { url } => url.clone(),
nexus_config::Database::FromDns => {
info!(log, "Accessing DB url from DNS");
let address = loop {
// It's been requested but unfortunately not supported to directly
// connect using SRV based lookup.
// TODO-robustness: the set of cockroachdb hosts we'll use will be
// fixed to whatever we got back from DNS at Nexus start. This means
// a new cockroachdb instance won't picked up until Nexus restarts.
let addrs = loop {
match resolver
.lookup_socket_v6(ServiceName::Cockroach)
.lookup_all_socket_v6(ServiceName::Cockroach)
luqmana marked this conversation as resolved.
Show resolved Hide resolved
.await
{
Ok(address) => break address,
Ok(addrs) => break addrs,
Err(e) => {
warn!(
log,
"Failed to lookup cockroach address: {e}"
"Failed to lookup cockroach addresses: {e}"
);
tokio::time::sleep(std::time::Duration::from_secs(
1,
Expand All @@ -186,9 +191,14 @@ impl ServerContext {
}
}
};
info!(log, "DB address: {}", address);
let addrs_str = addrs
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",");
info!(log, "DB addresses: {}", addrs_str);
PostgresConfigWithUrl::from_str(&format!(
"postgresql://root@{address}/omicron?sslmode=disable",
"postgresql://root@{addrs_str}/omicron?sslmode=disable",
luqmana marked this conversation as resolved.
Show resolved Hide resolved
))
.map_err(|e| format!("Cannot parse Postgres URL: {}", e))?
}
Expand Down