Skip to content

Commit

Permalink
Merge branch 'main' into dap/tld-clients
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Oct 5, 2023
2 parents c1141bb + 6cf8181 commit 448e4e5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ members = [
"clients/wicketd-client",
"common",
"crdb-seed",
"deploy",
"dev-tools/omdb",
"dev-tools/omicron-dev",
"dev-tools/thing-flinger",
"dev-tools/xtask",
"dns-server",
"end-to-end-tests",
Expand Down Expand Up @@ -83,9 +83,9 @@ default-members = [
"clients/sled-agent-client",
"clients/wicketd-client",
"common",
"deploy",
"dev-tools/omdb",
"dev-tools/omicron-dev",
"dev-tools/thing-flinger",
"dev-tools/xtask",
"dns-server",
"gateway-cli",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 42 additions & 9 deletions nexus/tests/integration_tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,47 @@ async fn test_setup<'a>(
builder
}

// Attempts to apply an update as a transaction.
//
// Only returns an error if the transaction failed to commit.
async fn apply_update_as_transaction_inner(
client: &omicron_test_utils::dev::db::Client,
sql: &str,
) -> Result<(), tokio_postgres::Error> {
client.batch_execute("BEGIN;").await.expect("Failed to BEGIN transaction");
client.batch_execute(&sql).await.expect("Failed to execute update");
client.batch_execute("COMMIT;").await?;
Ok(())
}

// Applies an update as a transaction.
//
// Automatically retries transactions that can be retried client-side.
async fn apply_update_as_transaction(
log: &Logger,
client: &omicron_test_utils::dev::db::Client,
sql: &str,
) {
loop {
match apply_update_as_transaction_inner(client, sql).await {
Ok(()) => break,
Err(err) => {
client
.batch_execute("ROLLBACK;")
.await
.expect("Failed to ROLLBACK failed transaction");
if let Some(code) = err.code() {
if code == &tokio_postgres::error::SqlState::T_R_SERIALIZATION_FAILURE {
warn!(log, "Transaction retrying");
continue;
}
}
panic!("Failed to apply update: {err}");
}
}
}
}

async fn apply_update(
log: &Logger,
crdb: &CockroachInstance,
Expand All @@ -87,15 +128,7 @@ async fn apply_update(

for _ in 0..times_to_apply {
for sql in sqls.iter() {
client
.batch_execute("BEGIN;")
.await
.expect("Failed to BEGIN update");
client.batch_execute(&sql).await.expect("Failed to execute update");
client
.batch_execute("COMMIT;")
.await
.expect("Failed to COMMIT update");
apply_update_as_transaction(log, &client, sql).await;
}
}

Expand Down

0 comments on commit 448e4e5

Please sign in to comment.