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

[db] Access DB via connections, not via pool #4140

Merged
merged 17 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ api_identity = { path = "api_identity" }
approx = "0.5.1"
assert_matches = "1.5.0"
assert_cmd = "2.0.12"
async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "be3d9bce50051d8c0e0c06078e8066cc27db3001" }
# TODO: Update with a revision before merging
smklein marked this conversation as resolved.
Show resolved Hide resolved
async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", branch = "less-pool" }
async-trait = "0.1.73"
authz-macros = { path = "nexus/authz-macros" }
backoff = { version = "0.4.0", features = [ "tokio" ] }
Expand Down
14 changes: 8 additions & 6 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ async fn cmd_db_disk_list(
.filter(dsl::time_deleted.is_null())
.limit(i64::from(u32::from(limit)))
.select(Disk::as_select())
.load_async(datastore.pool_for_tests().await?)
.load_async(&*datastore.pool_connection_for_tests().await?)
.await
.context("loading disks")?;

Expand Down Expand Up @@ -398,11 +398,13 @@ async fn cmd_db_disk_info(

use db::schema::disk::dsl as disk_dsl;

let conn = datastore.pool_connection_for_tests().await?;

let disk = disk_dsl::disk
.filter(disk_dsl::id.eq(args.uuid))
.limit(1)
.select(Disk::as_select())
.load_async(datastore.pool_for_tests().await?)
.load_async(&*conn)
.await
.context("loading requested disk")?;

Expand All @@ -422,7 +424,7 @@ async fn cmd_db_disk_info(
.filter(instance_dsl::id.eq(instance_uuid))
.limit(1)
.select(Instance::as_select())
.load_async(datastore.pool_for_tests().await?)
.load_async(&*conn)
.await
.context("loading requested instance")?;

Expand Down Expand Up @@ -756,7 +758,7 @@ async fn load_zones_version(
.filter(dsl::version.eq(nexus_db_model::Generation::from(version)))
.limit(1)
.select(DnsVersion::as_select())
.load_async(datastore.pool_for_tests().await?)
.load_async(&*datastore.pool_connection_for_tests().await?)
.await
.context("loading requested version")?;

Expand Down Expand Up @@ -798,7 +800,7 @@ async fn cmd_db_dns_diff(
.filter(dsl::version_added.eq(version.version))
.limit(i64::from(u32::from(limit)))
.select(DnsName::as_select())
.load_async(datastore.pool_for_tests().await?)
.load_async(&*datastore.pool_connection_for_tests().await?)
.await
.context("loading added names")?;
check_limit(&added, limit, || "loading added names");
Expand All @@ -808,7 +810,7 @@ async fn cmd_db_dns_diff(
.filter(dsl::version_removed.eq(version.version))
.limit(i64::from(u32::from(limit)))
.select(DnsName::as_select())
.load_async(datastore.pool_for_tests().await?)
.load_async(&*datastore.pool_connection_for_tests().await?)
.await
.context("loading added names")?;
check_limit(&added, limit, || "loading removed names");
Expand Down
8 changes: 4 additions & 4 deletions nexus/db-macros/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,11 @@ fn generate_database_functions(config: &Config) -> TokenStream {
#lookup_filter
.select(nexus_db_model::#resource_name::as_select())
.get_result_async(
datastore.pool_authorized(opctx).await?
&*datastore.pool_connection_authorized(opctx).await?
)
.await
.map_err(|e| {
public_error_from_diesel_pool(
public_error_from_diesel(
e,
ErrorHandler::NotFoundByLookup(
ResourceType::#resource_name,
Expand Down Expand Up @@ -891,10 +891,10 @@ fn generate_database_functions(config: &Config) -> TokenStream {
#soft_delete_filter
#(.filter(dsl::#pkey_column_names.eq(#pkey_names.clone())))*
.select(nexus_db_model::#resource_name::as_select())
.get_result_async(datastore.pool_authorized(opctx).await?)
.get_result_async(&*datastore.pool_connection_authorized(opctx).await?)
.await
.map_err(|e| {
public_error_from_diesel_pool(
public_error_from_diesel(
e,
ErrorHandler::NotFoundByLookup(
ResourceType::#resource_name,
Expand Down
Loading