Skip to content

Commit b30e958

Browse files
committed
Committing -> Committed
1 parent 7a132fe commit b30e958

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

nexus/db-queries/src/db/datastore/trust_quorum.rs

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,31 @@ impl DataStore {
606606
.await
607607
.map_err(|txn_error| txn_error.into_diesel(&err))?;
608608

609+
// Then get any members associated with the configuration
610+
let db_members = Self::tq_get_members_conn(
611+
opctx,
612+
&c,
613+
rack_id,
614+
db_config.epoch,
615+
)
616+
.await
617+
.map_err(|txn_error| txn_error.into_diesel(&err))?;
618+
619+
// If all members have acked their commits then mark the
620+
// configuration as committed.
621+
if db_members.iter().all(|(m, _)| {
622+
m.state == DbTrustQuorumMemberState::Committed
623+
}) {
624+
Self::update_tq_state_committed_in_txn(
625+
opctx,
626+
conn,
627+
db_config.rack_id,
628+
db_config.epoch,
629+
)
630+
.await
631+
.map_err(|txn_error| txn_error.into_diesel(&err))?;
632+
}
633+
609634
Ok(())
610635
}
611636
})
@@ -909,6 +934,27 @@ impl DataStore {
909934
Ok(num_rows_updated)
910935
}
911936

937+
/// Returns the number of rows update
938+
async fn update_tq_state_committed_in_txn(
939+
opctx: &OpContext,
940+
conn: &async_bb8_diesel::Connection<DbConnection>,
941+
rack_id: DbTypedUuid<RackKind>,
942+
epoch: i64,
943+
) -> Result<usize, TransactionError<Error>> {
944+
opctx.authorize(authz::Action::Modify, &authz::FLEET).await?;
945+
use nexus_db_schema::schema::trust_quorum_configuration::dsl;
946+
947+
let num_rows_updated = diesel::update(dsl::trust_quorum_configuration)
948+
.filter(dsl::rack_id.eq(rack_id))
949+
.filter(dsl::epoch.eq(epoch))
950+
.filter(dsl::state.eq(DbTrustQuorumConfigurationState::Committing))
951+
.set(dsl::state.eq(DbTrustQuorumConfigurationState::Committed))
952+
.execute_async(conn)
953+
.await?;
954+
955+
Ok(num_rows_updated)
956+
}
957+
912958
async fn update_tq_abort_state_in_txn(
913959
opctx: &OpContext,
914960
conn: &async_bb8_diesel::Connection<DbConnection>,
@@ -1321,7 +1367,7 @@ mod tests {
13211367
.expect("no error")
13221368
.expect("returned config");
13231369

1324-
// We've acked enough nodes and should have committed
1370+
// We've acked enough nodes and should have written our status to the DB
13251371
assert_eq!(read_config.epoch, config.epoch);
13261372
assert_eq!(read_config.state, TrustQuorumConfigState::Committing);
13271373
assert!(read_config.encrypted_rack_secrets.is_none());
@@ -1369,33 +1415,9 @@ mod tests {
13691415
.expect("returned config");
13701416

13711417
assert_eq!(read_config.epoch, config.epoch);
1372-
assert_eq!(read_config.state, TrustQuorumConfigState::Committing);
1373-
assert!(read_config.encrypted_rack_secrets.is_none());
1374-
assert!(
1375-
read_config.members.iter().all(
1376-
|(_, info)| info.state == TrustQuorumMemberState::Committed
1377-
)
1378-
);
1379-
1380-
// Repeating the same update and read succeeds
1381-
datastore
1382-
.tq_update_commit_status(
1383-
opctx,
1384-
rack_id,
1385-
config.epoch,
1386-
coordinator_config.members.keys().cloned().collect(),
1387-
)
1388-
.await
1389-
.unwrap();
1390-
1391-
let read_config = datastore
1392-
.tq_get_latest_config(opctx, rack_id)
1393-
.await
1394-
.expect("no error")
1395-
.expect("returned config");
1396-
1397-
assert_eq!(read_config.epoch, config.epoch);
1398-
assert_eq!(read_config.state, TrustQuorumConfigState::Committing);
1418+
// Now that all nodes have committed, we should see the config state
1419+
// change from `Committing` to Committed.
1420+
assert_eq!(read_config.state, TrustQuorumConfigState::Committed);
13991421
assert!(read_config.encrypted_rack_secrets.is_none());
14001422
assert!(
14011423
read_config.members.iter().all(

0 commit comments

Comments
 (0)