Skip to content

Commit

Permalink
[reconfigurator] Add rendezvous_debug_dataset table (oxidecomputer#7341)
Browse files Browse the repository at this point in the history
Also adds datastore methods and a library crate to populate it.

This is PR 1 of 2; the second PR will add both an RPW that calls this
library crate and adds a consumer of this table.
  • Loading branch information
jgallagher authored Jan 15, 2025
1 parent c03eb51 commit fbe043a
Showing 16 changed files with 898 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ members = [
"nexus/reconfigurator/execution",
"nexus/reconfigurator/planning",
"nexus/reconfigurator/preparation",
"nexus/reconfigurator/rendezvous",
"nexus/reconfigurator/simulation",
"nexus/saga-recovery",
"nexus/test-interface",
@@ -218,6 +219,7 @@ default-members = [
"nexus/reconfigurator/execution",
"nexus/reconfigurator/planning",
"nexus/reconfigurator/preparation",
"nexus/reconfigurator/rendezvous",
"nexus/reconfigurator/simulation",
"nexus/saga-recovery",
"nexus/test-interface",
@@ -479,6 +481,7 @@ nexus-reconfigurator-blippy = { path = "nexus/reconfigurator/blippy" }
nexus-reconfigurator-execution = { path = "nexus/reconfigurator/execution" }
nexus-reconfigurator-planning = { path = "nexus/reconfigurator/planning" }
nexus-reconfigurator-preparation = { path = "nexus/reconfigurator/preparation" }
nexus-reconfigurator-rendezvous = { path = "nexus/reconfigurator/rendezvous" }
nexus-reconfigurator-simulation = { path = "nexus/reconfigurator/simulation" }
nexus-saga-recovery = { path = "nexus/saga-recovery" }
nexus-sled-agent-shared = { path = "nexus-sled-agent-shared" }
2 changes: 2 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ mod physical_disk_state;
mod probe;
mod producer_endpoint;
mod project;
mod rendezvous_debug_dataset;
mod semver_version;
mod switch_interface;
mod switch_port;
@@ -186,6 +187,7 @@ pub use region_replacement_step::*;
pub use region_snapshot::*;
pub use region_snapshot_replacement::*;
pub use region_snapshot_replacement_step::*;
pub use rendezvous_debug_dataset::*;
pub use role_assignment::*;
pub use role_builtin::*;
pub use saga_types::*;
79 changes: 79 additions & 0 deletions nexus/db-model/src/rendezvous_debug_dataset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::schema::rendezvous_debug_dataset;
use crate::typed_uuid::DbTypedUuid;
use chrono::{DateTime, Utc};
use omicron_uuid_kinds::BlueprintKind;
use omicron_uuid_kinds::BlueprintUuid;
use omicron_uuid_kinds::DatasetKind;
use omicron_uuid_kinds::DatasetUuid;
use omicron_uuid_kinds::ZpoolKind;
use omicron_uuid_kinds::ZpoolUuid;
use serde::{Deserialize, Serialize};

/// Database representation of a Debug Dataset available for use.
#[derive(
Queryable,
Insertable,
Debug,
Clone,
Selectable,
Deserialize,
Serialize,
PartialEq,
)]
#[diesel(table_name = rendezvous_debug_dataset)]
pub struct RendezvousDebugDataset {
id: DbTypedUuid<DatasetKind>,
time_created: DateTime<Utc>,
time_tombstoned: Option<DateTime<Utc>>,
pool_id: DbTypedUuid<ZpoolKind>,
blueprint_id_when_created: DbTypedUuid<BlueprintKind>,
blueprint_id_when_tombstoned: Option<DbTypedUuid<BlueprintKind>>,
}

impl RendezvousDebugDataset {
pub fn new(
id: DatasetUuid,
pool_id: ZpoolUuid,
blueprint_id: BlueprintUuid,
) -> Self {
Self {
id: id.into(),
time_created: Utc::now(),
time_tombstoned: None,
pool_id: pool_id.into(),
blueprint_id_when_created: blueprint_id.into(),
blueprint_id_when_tombstoned: None,
}
}

pub fn id(&self) -> DatasetUuid {
self.id.into()
}

pub fn pool_id(&self) -> ZpoolUuid {
self.pool_id.into()
}

pub fn blueprint_id_when_created(&self) -> BlueprintUuid {
self.blueprint_id_when_created.into()
}

pub fn blueprint_id_when_tombstoned(&self) -> Option<BlueprintUuid> {
self.blueprint_id_when_tombstoned.map(From::from)
}

pub fn is_tombstoned(&self) -> bool {
// A CHECK constraint in the schema guarantees both the `*_tombstoned`
// fields are set or not set; document that check here with an
// assertion.
debug_assert_eq!(
self.time_tombstoned.is_some(),
self.blueprint_id_when_tombstoned.is_some()
);
self.time_tombstoned.is_some()
}
}
11 changes: 11 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
@@ -1059,6 +1059,17 @@ table! {

allow_tables_to_appear_in_same_query!(zpool, dataset);

table! {
rendezvous_debug_dataset (id) {
id -> Uuid,
time_created -> Timestamptz,
time_tombstoned -> Nullable<Timestamptz>,
pool_id -> Uuid,
blueprint_id_when_created -> Uuid,
blueprint_id_when_tombstoned -> Nullable<Uuid>,
}
}

table! {
region (id) {
id -> Uuid,
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ use std::collections::BTreeMap;
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(119, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(120, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
@@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(120, "rendezvous-debug-dataset"),
KnownVersion::new(119, "tuf-artifact-key-uuid"),
KnownVersion::new(118, "support-bundles"),
KnownVersion::new(117, "add-completing-and-new-region-volume"),
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ mod region;
mod region_replacement;
mod region_snapshot;
pub mod region_snapshot_replacement;
mod rendezvous_debug_dataset;
mod role;
mod saga;
mod silo;
Loading

0 comments on commit fbe043a

Please sign in to comment.