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-queries] Convert virtual provisioning CTE to use raw SQL #5089

Merged
merged 30 commits into from
May 29, 2024

Conversation

smklein
Copy link
Collaborator

@smklein smklein commented Feb 16, 2024

@smklein smklein marked this pull request as ready for review May 28, 2024 23:21
@hawkw hawkw self-requested a review May 28, 2024 23:35
Copy link
Member

@hawkw hawkw left a 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.

Comment on lines +116 to +118
WITH
parent_silo AS (SELECT project.silo_id AS id FROM project WHERE project.id = ").param().sql("),")
.bind::<sql_types::Uuid, _>(project_id).sql("
Copy link
Member

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?

Copy link
Collaborator Author

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.

Base automatically changed from more-raw-cte-setup to main May 29, 2024 19:20
@smklein smklein enabled auto-merge (squash) May 29, 2024 21:00
@smklein smklein merged commit 7e84fd9 into main May 29, 2024
19 checks passed
@smklein smklein deleted the convert-virtual-provisioning branch May 29, 2024 21:25
smklein added a commit that referenced this pull request May 30, 2024
…#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.
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.

2 participants