-
Notifications
You must be signed in to change notification settings - Fork 40
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-queries] Convert virtual provisioning CTE to use raw SQL #5089
Conversation
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.
seems fine to me --- it's a tossup over which code is easier to understand, but if the raw SQL helps to avoid fighting the type checker, it's probably worth it. it might be worth getting a second opinion from someone who's not me, but i'm 👍 on this.
nexus/db-queries/src/db/queries/virtual_provisioning_collection_update.rs
Outdated
Show resolved
Hide resolved
WITH | ||
parent_silo AS (SELECT project.silo_id AS id FROM project WHERE project.id = ").param().sql("),") | ||
.bind::<sql_types::Uuid, _>(project_id).sql(" |
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.
IIUC it shouldn't really be necessary to format the query strings here identically to the format_sql
output, since we're still going to call format_sql
on them prior to testing that they match?
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.
Yeah, that's correct. My goal with the layout of code here is "make it as easy to grok as possible", which is super subjective with non-formatted interpolated strings, but I'm open to suggestions.
Regardless, yes, updating whitespace won't break the tests / change any saved outputs.
…#5830) Builds on #5081 and #5089 , but more out of convenience than necessity. # Summary This PR attempts to validate that, for the "virtual provisioning collection {insert, delete}" operations, they are idempotent. Currently, our usage of `max_instance_gen` only **partially** prevents updates during instance provisioning deletions: - If `max_instance_gen` is smaller than the observed instance generation number... - ... we avoid deleting the `virtual_provisioning_resource` record (which is great) - ... but we still decrement the `virtual_provisioning_collection` values (which is really not great). This basically means that we can "only cause the project/silo/fleet usage values to decrement arbitrarily, with no other changes". This has been, mechanically, the root cause of our observed underflows (e.g, #5525). # Details of this change - All the changes in `nexus/db-queries/src/db/datastore/virtual_provisioning_collection.rs` are tests validating idempotency of these operations. - All the changes in `nexus/db-queries/src/db/queries/virtual_provisioning_collection_update.rs` are actually changes to the query which change functionality. The objective of these changes is to preserve idempotency of the newly added tests, and to prevent undercounting of virtual provisioning resources. If these changes are reverted, the newly added tests start failing, showing a lack of coverage.
Builds on:
Converts the virtual provisioning CTE to use SQL more directly