Skip to content

[db] turn @sunshowers' limit-reached query into a reusable thing#10889

Merged
hawkw merged 5 commits into
mainfrom
eliza/limit-reached
Jul 22, 2026
Merged

[db] turn @sunshowers' limit-reached query into a reusable thing#10889
hawkw merged 5 commits into
mainfrom
eliza/limit-reached

Conversation

@hawkw

@hawkw hawkw commented Jul 21, 2026

Copy link
Copy Markdown
Member

This commit factors out the main logic of @sunshowers' DataStore::check_blueprint_limit_reached query into a reusable query fragment, because I wanted to use a similar query in my implementation of #9384 and felt this was nicer than copying and pasting it, even if it took much more fighting with Diesel than just copying it would have.

Fixes #10896

@hawkw
hawkw requested a review from sunshowers July 21, 2026 23:03
@hawkw hawkw self-assigned this Jul 21, 2026
@hawkw hawkw added database Related to database access fault-management Everything related to the fault-management initiative (RFD480 and others) labels Jul 21, 2026
@hawkw

hawkw commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

I'm putting this up for review now so that I can get @sunshowers' opinion on it: in particular, I'm considering changing it a bit more so that check_if_limit_reached_async takes a TransactionRetryHelper rather than a db connection, so that the abstraction can also abstract over the need to run the ALLOW_FULL_TABLE_SCAN_SQL first, as well as abstracting over the reason we consider it okay to do that. What do you think?

@hawkw
hawkw requested review from jgallagher and smklein July 22, 2026 00:00
@hawkw

hawkw commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

I'm putting this up for review now so that I can get @sunshowers' opinion on it: in particular, I'm considering changing it a bit more so that check_if_limit_reached_async takes a TransactionRetryHelper rather than a db connection, so that the abstraction can also abstract over the need to run the ALLOW_FULL_TABLE_SCAN_SQL first, as well as abstracting over the reason we consider it okay to do that. What do you think?

@smklein et al, Rain said they have a moderate preference for leaving this as-is and keeping the query composable with other stuff that might want to run in the same transaction, even if it comes at the cost of requiring the user to have to remember they must ALLOW_FULL_TABLE_SCANS_SQL in order to not have it fail at runtime. But, we'd both love to get your opinion on that.

@hawkw

hawkw commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

I'm putting this up for review now so that I can get @sunshowers' opinion on it: in particular, I'm considering changing it a bit more so that check_if_limit_reached_async takes a TransactionRetryHelper rather than a db connection, so that the abstraction can also abstract over the need to run the ALLOW_FULL_TABLE_SCAN_SQL first, as well as abstracting over the reason we consider it okay to do that. What do you think?

@smklein et al, Rain said they have a moderate preference for leaving this as-is and keeping the query composable with other stuff that might want to run in the same transaction, even if it comes at the cost of requiring the user to have to remember they must ALLOW_FULL_TABLE_SCANS_SQL in order to not have it fail at runtime. But, we'd both love to get your opinion on that.

Update on this: now that I have started actually trying to write code that uses this thing, I have quickly realized that it is quite valuable to be able to run the limit-reached check query in a transaction that does other things --- I would like to be able to delete records only if over the limit, and that is, of course, hard to do outside a transaction (or CTE) which ensures that the check if over the limit and the deletion of the records occurs atomically. So, I think I'm going to leave this PR as it is.

Comment thread nexus/src/app/background/tasks/blueprint_planner.rs
Comment thread nexus/db-queries/src/db/mod.rs Outdated
Comment thread nexus/db-queries/src/db/check_if_limit_reached.rs Outdated
Comment thread nexus/db-queries/src/db/datastore/deployment.rs Outdated
Comment thread nexus/db-queries/src/db/check_if_limit_reached.rs
Comment thread nexus/db-queries/src/db/check_if_limit_reached.rs Outdated
Comment thread nexus/db-queries/src/db/check_if_limit_reached.rs Outdated

@sunshowers sunshowers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@hawkw
hawkw enabled auto-merge (squash) July 22, 2026 20:39
@hawkw
hawkw merged commit a7fb00f into main Jul 22, 2026
19 checks passed
@hawkw
hawkw deleted the eliza/limit-reached branch July 22, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database Related to database access fault-management Everything related to the fault-management initiative (RFD480 and others)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check_blueprint_limit_reached query's transaction won't ever actually be retried

2 participants