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

[nexus] Make most transactions automatically retry #4487

Merged
merged 29 commits into from
Dec 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
66100a5
WIP: First attempt at txn retry
smklein Nov 11, 2023
10a021d
Add transaction retry helper
smklein Nov 15, 2023
d77b58c
More conversions (tests passing)
smklein Nov 15, 2023
64d46a4
More conversions (collections, network, switch_port)
smklein Nov 15, 2023
10865b1
Clippy lints (tests still passing)
smklein Nov 15, 2023
49b4aa4
address_lot, saml_identity_provider, rack_set_initialized, snapshot, …
smklein Nov 15, 2023
04aa337
Rack setup not ready for retry (nested transactions)
smklein Nov 16, 2023
5b19bc5
Fix error propagation
smklein Nov 16, 2023
ad3bc08
bgp, db_metadata, volume converted
smklein Nov 16, 2023
a209651
switch_interface
smklein Nov 16, 2023
dbec9aa
Point to branch
smklein Nov 16, 2023
650af84
Merge branch 'main' into txn-retry
smklein Nov 16, 2023
b319f1c
Catch one more possibly retryable error
smklein Nov 16, 2023
aaeb8ab
Not sure how it worked without that, but added my rand dep
smklein Nov 16, 2023
4625d8a
review feedback
smklein Nov 17, 2023
761e046
Add tests for transaction_retry producing samples
smklein Nov 20, 2023
1e763dc
Merge branch 'main' into txn-retry
smklein Nov 29, 2023
180c872
Propagate more retry errors
smklein Dec 1, 2023
9ea030c
Merge branch 'main' into txn-retry
smklein Dec 1, 2023
da33017
Start refactoring RetryHelper to help callsites become simpler
smklein Dec 1, 2023
eb30977
RetryHelper refactor
smklein Dec 1, 2023
246ac8a
use retry wrapper everywhere, even for schema changes
smklein Dec 1, 2023
d6f7692
one more error cleanup
smklein Dec 1, 2023
7fff381
Remove config.xml from tests
smklein Dec 1, 2023
d362a9e
Merge branch 'main' into txn-retry
smklein Dec 2, 2023
a54925e
Make tests happier
smklein Dec 2, 2023
ec9f450
Add more automated retries
smklein Dec 4, 2023
538d48c
review feedback
smklein Dec 4, 2023
2058492
update async-bb8-diesel version
smklein Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions nexus/db-queries/src/db/datastore/silo_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,40 @@ impl DataStore {

self.pool_connection_authorized(opctx)
.await?
.transaction_async(|conn| async move {
use db::schema::silo_group_membership::dsl;
.transaction_async_with_retry(
|conn| {
let silo_group_ids = silo_group_ids.clone();
async move {
use db::schema::silo_group_membership::dsl;

// Delete existing memberships for user
let silo_user_id = authz_silo_user.id();
diesel::delete(dsl::silo_group_membership)
.filter(dsl::silo_user_id.eq(silo_user_id))
.execute_async(&conn)
.await?;
// Delete existing memberships for user
let silo_user_id = authz_silo_user.id();
diesel::delete(dsl::silo_group_membership)
.filter(dsl::silo_user_id.eq(silo_user_id))
.execute_async(&conn)
.await?;

// Create new memberships for user
let silo_group_memberships: Vec<
db::model::SiloGroupMembership,
> = silo_group_ids
.iter()
.map(|group_id| db::model::SiloGroupMembership {
silo_group_id: *group_id,
silo_user_id,
})
.collect();
// Create new memberships for user
let silo_group_memberships: Vec<
db::model::SiloGroupMembership,
> = silo_group_ids
.iter()
.map(|group_id| db::model::SiloGroupMembership {
silo_group_id: *group_id,
silo_user_id,
})
.collect();

diesel::insert_into(dsl::silo_group_membership)
.values(silo_group_memberships)
.execute_async(&conn)
.await?;
diesel::insert_into(dsl::silo_group_membership)
.values(silo_group_memberships)
.execute_async(&conn)
.await?;

Ok(())
})
Ok(())
}
},
|| async { true },
smklein marked this conversation as resolved.
Show resolved Hide resolved
)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}
Expand Down
Loading