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

Conversation

smklein
Copy link
Collaborator

@smklein smklein commented Sep 25, 2023

  • Accesses the DB via connections explicitly, rather than using a pool
  • This change reduces generics slightly, and simplifies error handling. Callers can deal with "pool errors" when checking out the connection, and can deal with "query errors" separately when issuing the queries themselves.

Depends on oxidecomputer/async-bb8-diesel#52
Fixes #4132

Cargo.toml Outdated Show resolved Hide resolved
@smklein smklein requested a review from davepacheco September 25, 2023 18:50
Copy link
Collaborator

@davepacheco davepacheco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is a cleaner interface. I reviewed the datastore/mod.rs, error.rs, and a few other areas, but I did not review most of nexus/db-queries/src/db because there's so much delta here that's mechanical but non-trivial.

nexus/db-queries/src/db/datastore/mod.rs Outdated Show resolved Hide resolved
nexus/db-queries/src/db/datastore/mod.rs Outdated Show resolved Hide resolved
nexus/db-queries/src/db/datastore/mod.rs Show resolved Hide resolved
Copy link
Collaborator

@davepacheco davepacheco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

@smklein
Copy link
Collaborator Author

smklein commented Sep 27, 2023

I ran the following command:

cargo build -p omicron-nexus && touch nexus/src/lib.rs  && cargo build -p omicron-nexus --timings

(AKA, do a clean build, touch one file, rebuild validating timings).

This is what I saw on my Linux laptop on main:

image

This is what I saw with this PR:

image

I'm surprised by this result, and think I might need to do a deep dive into why this is happening.

@smklein
Copy link
Collaborator Author

smklein commented Sep 28, 2023

Huh, well, that's... interesting. I tried using https://blog.rust-lang.org/inside-rust/2020/02/25/intro-rustc-self-profile.html to dig into "why did this make the build slower", and here's what I found:

I basically wanted to run cargo rustc -- -Zself-profile -Zself-profile-events=default,args , but doing to caused rustc to ICE, so I just queries the default events, and things seemed to work. Note: Running these commands required nightly, and I used:

 $ rustup run nightly rustc --version
rustc 1.74.0-nightly (e7c502d93 2023-09-27)

I ran the following command:

cargo +nightly rustc -p omicron-nexus --lib && touch nexus/src/lib.rs && cargo +nightly rustc -p omicron-nexus --lib -- -Zself-profile -Zself-profile-events=default

(just like before -- build, touch one file, rebuild)

I ran this on both main and this branch. Comparing these results, I was not able to reproduce this PR building slower -- it was actually a small improvement over main!

Since I was forced to use the nightly compiler, I figured I'd redo the build --timings comparison too. Here are the results, using the rustc 1.74.0-nightly (e7c502d93 2023-09-27) toolchain:

main

image

This PR

image

My takeaway

I think this PR is safe to land? It seems that the issues causing build speeds to regress are more related to our rust version than the commit itself.

@smklein smklein merged commit 2a6ef48 into main Sep 29, 2023
23 checks passed
@smklein smklein deleted the diesel-less-generic branch September 29, 2023 19:24
@davepacheco
Copy link
Collaborator

In case it's helpful for anybody else, I had a branch with changes that needed to be updated after merging with this change and this worked to update my branch:

  • replace calls to public_error_from_diesel_pool() with public_error_from_diesel()
  • replace calls to pool_authorized() with calls to pool_connection_authorized()
  • replace use of TransactionError::Pool with TransactionError::Connection

smklein added a commit that referenced this pull request Oct 12, 2023
Depends on oxidecomputer/async-bb8-diesel#54

As of #4140 , we check out
connections before issuing queries to the underlying database. This
means that when we receive errors from the database, they are not
overloaded as "connection checkout" OR "database" errors - they are now
always database errors.
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.

[nexus] Access DB via "connection", not "pool"
2 participants