[fm] Introduce SitrepGuardedInsert.#10532
Closed
mergeconflict wants to merge 5 commits into
Closed
Conversation
This was referenced Jun 2, 2026
Add the `SitrepGuardedInsert` Diesel combinator and the
`SitrepGuardedResource` trait: a generic primitive for FM rendezvous to
insert a resource row idempotently and guarded against stale-sitrep
execution.
The combinator wraps a caller-supplied resource INSERT in a single CTE
statement that:
- aborts (StaleSitrep) unless the executor's expected generation still
equals the latest sitrep's generation column;
- short-circuits (AlreadyExists) if a creation marker already exists for
the resource id;
- on a successful insert, atomically writes a creation marker, gated by
`WHERE EXISTS (SELECT 1 FROM new_resource)` so a marker is never
fabricated for a pre-existing row.
All spliced SQL identifiers come from the trait's `&'static str` consts, so
the query is injection-safe. The result is surfaced as a
`SitrepGuardedInsertOutcome` of Created / AlreadyExists / StaleSitrep.
6663e70 to
c6e5904
Compare
hawkw
reviewed
Jun 2, 2026
| /// 5. `new_marker`: the marker INSERT, emitted inline by the | ||
| /// combinator using R's `&'static str` consts. This only runs when | ||
| /// `new_resource` actually produced a row. | ||
| fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> { |
Member
There was a problem hiding this comment.
It would be nice to have an expectorate test (and maybe also an EXPLAIN test) for the kind of queries that this generates.
Contributor
Author
There was a problem hiding this comment.
I've added an expectorate test in 365af00. I didn't bother with an EXPLAIN test yet, but I'm pondering it...
- generate table and column names from types, rather than hardcoding them as static strings - add expectorate test - use `Generation` type for generation values - style nit - don't tell lies
hawkw
reviewed
Jun 4, 2026
Comment on lines
+198
to
+201
| // Column names injected into the CTEs below. | ||
| let marker_id_column = <R::MarkerIdColumn as Column>::NAME; | ||
| let generation_column = <R::GenerationColumn as Column>::NAME; | ||
|
|
c4925ea to
0aded13
Compare
Contributor
Author
|
what the fuck github |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the
SitrepGuardedInsertDiesel combinator and theSitrepGuardedResourcetrait: a generic primitive for FM rendezvous to insert a resource row idempotently and guarded against stale-sitrep execution.The combinator wraps a caller-supplied resource INSERT in a single CTE statement that:
The result is surfaced as a
SitrepGuardedInsertOutcomeofCreated/AlreadyExists/StaleSitrep.Context: #10248. This is used in #10533 and #10535 which are split out in hopes of making the review somewhat less miserable.