Skip to content

Commit 42adbe5

Browse files
authored
[2/n] [reconfigurator-sim] rename state uuid type (#9364)
We're going to introduce another kind of reconfigurator sim UUID called `ReconfiguratorSimOpUuid`.
1 parent be54f37 commit 42adbe5

File tree

7 files changed

+61
-53
lines changed

7 files changed

+61
-53
lines changed

dev-tools/reconfigurator-cli/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use omicron_repl_utils::run_repl_from_file;
6363
use omicron_repl_utils::run_repl_on_stdin;
6464
use omicron_uuid_kinds::GenericUuid;
6565
use omicron_uuid_kinds::OmicronZoneUuid;
66-
use omicron_uuid_kinds::ReconfiguratorSimUuid;
66+
use omicron_uuid_kinds::ReconfiguratorSimStateUuid;
6767
use omicron_uuid_kinds::SledUuid;
6868
use omicron_uuid_kinds::VnicUuid;
6969
use omicron_uuid_kinds::{BlueprintUuid, MupdateOverrideUuid};
@@ -92,7 +92,7 @@ struct ReconfiguratorSim {
9292
// The simulator currently being used.
9393
sim: Simulator,
9494
// The current state.
95-
current: ReconfiguratorSimUuid,
95+
current: ReconfiguratorSimStateUuid,
9696
// The current system state
9797
log: slog::Logger,
9898
}
@@ -1024,38 +1024,38 @@ impl From<CollectionIdOpt> for CollectionId {
10241024
}
10251025

10261026
#[derive(Clone, Debug)]
1027-
enum ReconfiguratorSimIdOpt {
1027+
enum ReconfiguratorSimStateIdOpt {
10281028
/// use a specific reconfigurator sim state by full UUID
1029-
Id(ReconfiguratorSimUuid),
1029+
Id(ReconfiguratorSimStateUuid),
10301030
/// use a reconfigurator sim state by UUID prefix
10311031
Prefix(String),
10321032
}
10331033

1034-
impl FromStr for ReconfiguratorSimIdOpt {
1034+
impl FromStr for ReconfiguratorSimStateIdOpt {
10351035
type Err = Infallible;
10361036

10371037
fn from_str(s: &str) -> Result<Self, Self::Err> {
1038-
match s.parse::<ReconfiguratorSimUuid>() {
1039-
Ok(id) => Ok(ReconfiguratorSimIdOpt::Id(id)),
1040-
Err(_) => Ok(ReconfiguratorSimIdOpt::Prefix(s.to_owned())),
1038+
match s.parse::<ReconfiguratorSimStateUuid>() {
1039+
Ok(id) => Ok(ReconfiguratorSimStateIdOpt::Id(id)),
1040+
Err(_) => Ok(ReconfiguratorSimStateIdOpt::Prefix(s.to_owned())),
10411041
}
10421042
}
10431043
}
10441044

1045-
impl fmt::Display for ReconfiguratorSimIdOpt {
1045+
impl fmt::Display for ReconfiguratorSimStateIdOpt {
10461046
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10471047
match self {
1048-
ReconfiguratorSimIdOpt::Id(id) => id.fmt(f),
1049-
ReconfiguratorSimIdOpt::Prefix(prefix) => prefix.fmt(f),
1048+
ReconfiguratorSimStateIdOpt::Id(id) => id.fmt(f),
1049+
ReconfiguratorSimStateIdOpt::Prefix(prefix) => prefix.fmt(f),
10501050
}
10511051
}
10521052
}
10531053

1054-
impl From<ReconfiguratorSimIdOpt> for ReconfiguratorSimId {
1055-
fn from(value: ReconfiguratorSimIdOpt) -> Self {
1054+
impl From<ReconfiguratorSimStateIdOpt> for ReconfiguratorSimId {
1055+
fn from(value: ReconfiguratorSimStateIdOpt) -> Self {
10561056
match value {
1057-
ReconfiguratorSimIdOpt::Id(id) => ReconfiguratorSimId::Id(id),
1058-
ReconfiguratorSimIdOpt::Prefix(prefix) => {
1057+
ReconfiguratorSimStateIdOpt::Id(id) => ReconfiguratorSimId::Id(id),
1058+
ReconfiguratorSimStateIdOpt::Prefix(prefix) => {
10591059
ReconfiguratorSimId::Prefix(prefix)
10601060
}
10611061
}
@@ -1519,7 +1519,7 @@ enum StateArgs {
15191519
struct StateLogArgs {
15201520
/// Starting state ID (defaults to current state)
15211521
#[clap(long)]
1522-
from: Option<ReconfiguratorSimUuid>,
1522+
from: Option<ReconfiguratorSimStateUuid>,
15231523

15241524
/// Limit number of states to display
15251525
#[clap(long, short = 'n', requires = "from")]
@@ -1533,7 +1533,7 @@ struct StateLogArgs {
15331533
#[derive(Debug, Args)]
15341534
struct StateSwitchArgs {
15351535
/// The state ID or unique prefix to switch to
1536-
state_id: ReconfiguratorSimIdOpt,
1536+
state_id: ReconfiguratorSimStateIdOpt,
15371537
}
15381538

15391539
#[derive(Debug, Args)]

nexus/reconfigurator/simulation/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::collections::BTreeSet;
77
use indent_write::indentable::Indentable as _;
88
use itertools::Itertools;
99
use omicron_common::api::external::{Generation, Name};
10-
use omicron_uuid_kinds::ReconfiguratorSimUuid;
10+
use omicron_uuid_kinds::ReconfiguratorSimStateUuid;
1111
use swrite::{SWrite, swriteln};
1212
use thiserror::Error;
1313

@@ -166,7 +166,7 @@ impl UnknownZoneNamesError {
166166
#[derive(Clone, Debug)]
167167
pub struct StateMatch {
168168
/// The state ID.
169-
pub id: ReconfiguratorSimUuid,
169+
pub id: ReconfiguratorSimStateUuid,
170170
/// The state generation.
171171
pub generation: Generation,
172172
/// The state description.
@@ -186,7 +186,7 @@ pub enum StateIdResolveError {
186186

187187
/// State not found by ID.
188188
#[error("state not found: {0}")]
189-
NotFound(ReconfiguratorSimUuid),
189+
NotFound(ReconfiguratorSimStateUuid),
190190
}
191191

192192
fn format_matches(matches: &[StateMatch]) -> String {

nexus/reconfigurator/simulation/src/render_graph.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::collections::{HashMap, HashSet};
88

9-
use omicron_uuid_kinds::ReconfiguratorSimUuid;
9+
use omicron_uuid_kinds::ReconfiguratorSimStateUuid;
1010
use renderdag::{Ancestor, GraphRowRenderer, Renderer};
1111
use swrite::{SWrite, swrite, swriteln};
1212

@@ -17,12 +17,12 @@ use crate::{SimState, Simulator, utils::DisplayUuidPrefix};
1717
pub struct GraphRenderOptions {
1818
verbose: bool,
1919
starting_state: GraphStartingState,
20-
current: ReconfiguratorSimUuid,
20+
current: ReconfiguratorSimStateUuid,
2121
}
2222

2323
impl GraphRenderOptions {
2424
/// Create new render options with the current state.
25-
pub fn new(current: ReconfiguratorSimUuid) -> Self {
25+
pub fn new(current: ReconfiguratorSimStateUuid) -> Self {
2626
Self {
2727
verbose: false,
2828
starting_state: GraphStartingState::None,
@@ -51,7 +51,7 @@ pub enum GraphStartingState {
5151
None,
5252
State {
5353
/// The starting state.
54-
start: ReconfiguratorSimUuid,
54+
start: ReconfiguratorSimStateUuid,
5555
/// The maximum number of states to render.
5656
///
5757
/// We do not allow a limit to be set without a starting state, because
@@ -74,7 +74,7 @@ impl Simulator {
7474
&self,
7575
options: &GraphRenderOptions,
7676
) -> Vec<&SimState> {
77-
let mut remaining_heads: Vec<ReconfiguratorSimUuid> =
77+
let mut remaining_heads: Vec<ReconfiguratorSimStateUuid> =
7878
if let GraphStartingState::State { start, .. } =
7979
options.starting_state
8080
{
@@ -123,10 +123,10 @@ impl Simulator {
123123
/// Recursively walk a branch, processing merge points along the way.
124124
fn walk_branch_recursive<'a>(
125125
&'a self,
126-
mut current_id: ReconfiguratorSimUuid,
126+
mut current_id: ReconfiguratorSimStateUuid,
127127
node_to_heads: &HashMap<
128-
ReconfiguratorSimUuid,
129-
Vec<ReconfiguratorSimUuid>,
128+
ReconfiguratorSimStateUuid,
129+
Vec<ReconfiguratorSimStateUuid>,
130130
>,
131131
walk_state: &mut WalkState<'a>,
132132
) {
@@ -168,12 +168,12 @@ impl Simulator {
168168
/// State accumulated during graph traversal.
169169
struct WalkState<'a> {
170170
states: Vec<&'a SimState>,
171-
visited: HashSet<ReconfiguratorSimUuid>,
172-
remaining_heads: Vec<ReconfiguratorSimUuid>,
171+
visited: HashSet<ReconfiguratorSimStateUuid>,
172+
remaining_heads: Vec<ReconfiguratorSimStateUuid>,
173173
}
174174

175175
impl<'a> WalkState<'a> {
176-
fn new(heads: Vec<ReconfiguratorSimUuid>) -> Self {
176+
fn new(heads: Vec<ReconfiguratorSimStateUuid>) -> Self {
177177
Self {
178178
states: Vec::new(),
179179
visited: HashSet::new(),

nexus/reconfigurator/simulation/src/sim.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use std::{collections::HashMap, sync::Arc};
99

1010
use indexmap::IndexSet;
11-
use omicron_uuid_kinds::{ReconfiguratorSimKind, ReconfiguratorSimUuid};
11+
use omicron_uuid_kinds::{
12+
ReconfiguratorSimStateKind, ReconfiguratorSimStateUuid,
13+
};
1214
use typed_rng::TypedUuidRng;
1315

1416
use crate::{
@@ -48,8 +50,8 @@ pub struct Simulator {
4850
// In the future, it would be interesting to store a chain of every set of
4951
// heads over time, similar to `jj op log`. That would let us implement undo
5052
// and restore operations.
51-
heads: IndexSet<ReconfiguratorSimUuid>,
52-
states: HashMap<ReconfiguratorSimUuid, Arc<SimState>>,
53+
heads: IndexSet<ReconfiguratorSimStateUuid>,
54+
states: HashMap<ReconfiguratorSimStateUuid, Arc<SimState>>,
5355
// This state corresponds to `ROOT_ID`.
5456
//
5557
// Storing it in the Arc is extremely important! `SimStateBuilder` stores a
@@ -59,15 +61,16 @@ pub struct Simulator {
5961
// points to the same memory address.
6062
root_state: Arc<SimState>,
6163
// Top-level (unversioned) RNG.
62-
sim_uuid_rng: TypedUuidRng<ReconfiguratorSimKind>,
64+
sim_uuid_rng: TypedUuidRng<ReconfiguratorSimStateKind>,
6365
}
6466

6567
impl Simulator {
6668
/// The root ID of the store.
6769
///
6870
/// This is always defined to be the nil UUID, and if queried will always
6971
/// have a state associated with it.
70-
pub const ROOT_ID: ReconfiguratorSimUuid = ReconfiguratorSimUuid::nil();
72+
pub const ROOT_ID: ReconfiguratorSimStateUuid =
73+
ReconfiguratorSimStateUuid::nil();
7174

7275
/// Create a new simulator with the given initial seed.
7376
pub fn new(log: &slog::Logger, seed: Option<String>) -> Self {
@@ -77,6 +80,8 @@ impl Simulator {
7780

7881
fn new_inner(log: &slog::Logger, seed: String) -> Self {
7982
let log = log.new(slog::o!("component" => "SimStore"));
83+
// The ReconfiguratorSimStateUuid type used to be ReconfiguratorSimUuid.
84+
// Retain the old name in the seed for generated ID compatibility.
8085
let sim_uuid_rng =
8186
TypedUuidRng::from_seed(&seed, "ReconfiguratorSimUuid");
8287
let root_state = SimState::new_root(seed);
@@ -99,12 +104,15 @@ impl Simulator {
99104

100105
/// Get the current heads of the store.
101106
#[inline]
102-
pub fn heads(&self) -> &IndexSet<ReconfiguratorSimUuid> {
107+
pub fn heads(&self) -> &IndexSet<ReconfiguratorSimStateUuid> {
103108
&self.heads
104109
}
105110

106111
/// Get the state for the given UUID.
107-
pub fn get_state(&self, id: ReconfiguratorSimUuid) -> Option<&SimState> {
112+
pub fn get_state(
113+
&self,
114+
id: ReconfiguratorSimStateUuid,
115+
) -> Option<&SimState> {
108116
if id == Self::ROOT_ID {
109117
return Some(&self.root_state);
110118
}
@@ -126,7 +134,7 @@ impl Simulator {
126134
fn get_state_by_prefix(
127135
&self,
128136
prefix: &str,
129-
) -> Result<ReconfiguratorSimUuid, StateIdResolveError> {
137+
) -> Result<ReconfiguratorSimStateUuid, StateIdResolveError> {
130138
let mut matching_ids = Vec::new();
131139

132140
if Self::ROOT_ID.to_string().starts_with(prefix) {
@@ -169,11 +177,11 @@ impl Simulator {
169177
}
170178
}
171179

172-
/// Resolve a [`ReconfiguratorSimId`] to a [`ReconfiguratorSimUuid`].
180+
/// Resolve a [`ReconfiguratorSimId`] to a [`ReconfiguratorSimStateUuid`].
173181
pub fn resolve_state_id(
174182
&self,
175183
id: ReconfiguratorSimId,
176-
) -> Result<ReconfiguratorSimUuid, StateIdResolveError> {
184+
) -> Result<ReconfiguratorSimStateUuid, StateIdResolveError> {
177185
match id {
178186
ReconfiguratorSimId::Id(id) => Ok(id),
179187
ReconfiguratorSimId::Prefix(prefix) => {
@@ -192,7 +200,7 @@ impl Simulator {
192200
}
193201

194202
#[inline]
195-
pub(crate) fn next_sim_uuid(&mut self) -> ReconfiguratorSimUuid {
203+
pub(crate) fn next_sim_uuid(&mut self) -> ReconfiguratorSimStateUuid {
196204
self.sim_uuid_rng.next()
197205
}
198206

nexus/reconfigurator/simulation/src/state.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Context, anyhow, bail};
88
use nexus_inventory::CollectionBuilder;
99
use nexus_types::deployment::UnstableReconfiguratorState;
1010
use omicron_common::api::external::Generation;
11-
use omicron_uuid_kinds::{CollectionUuid, ReconfiguratorSimUuid};
11+
use omicron_uuid_kinds::{CollectionUuid, ReconfiguratorSimStateUuid};
1212
use sync_ptr::SyncConstPtr;
1313

1414
use crate::{
@@ -31,9 +31,9 @@ pub struct SimState {
3131
// is stored behind an `Arc`. This means that the address stays stable even
3232
// if the `Simulator` struct is cloned or moved in memory.
3333
root_state: SyncConstPtr<SimState>,
34-
id: ReconfiguratorSimUuid,
34+
id: ReconfiguratorSimStateUuid,
3535
// The parent state that this state was derived from.
36-
parent: Option<ReconfiguratorSimUuid>,
36+
parent: Option<ReconfiguratorSimStateUuid>,
3737
// The state's generation, starting from 0.
3838
//
3939
// TODO: Should this be its own type to avoid confusion with other
@@ -79,13 +79,13 @@ impl SimState {
7979

8080
#[inline]
8181
#[must_use]
82-
pub fn id(&self) -> ReconfiguratorSimUuid {
82+
pub fn id(&self) -> ReconfiguratorSimStateUuid {
8383
self.id
8484
}
8585

8686
#[inline]
8787
#[must_use]
88-
pub fn parent(&self) -> Option<ReconfiguratorSimUuid> {
88+
pub fn parent(&self) -> Option<ReconfiguratorSimStateUuid> {
8989
self.parent
9090
}
9191

@@ -185,7 +185,7 @@ pub struct SimStateBuilder {
185185
// Used to check that the simulator is the same as the one that created
186186
// this state.
187187
root_state: SyncConstPtr<SimState>,
188-
parent: ReconfiguratorSimUuid,
188+
parent: ReconfiguratorSimStateUuid,
189189
parent_gen: Generation,
190190
system: SimSystemBuilder,
191191
config: SimConfigBuilder,
@@ -195,7 +195,7 @@ pub struct SimStateBuilder {
195195
impl SimStateBuilder {
196196
#[inline]
197197
#[must_use]
198-
pub fn parent(&self) -> ReconfiguratorSimUuid {
198+
pub fn parent(&self) -> ReconfiguratorSimStateUuid {
199199
self.parent
200200
}
201201

@@ -271,7 +271,7 @@ impl SimStateBuilder {
271271
self,
272272
description: String,
273273
sim: &mut Simulator,
274-
) -> ReconfiguratorSimUuid {
274+
) -> ReconfiguratorSimStateUuid {
275275
// Check for unrelated histories.
276276
if !std::ptr::eq(sim.root_state(), self.root_state.inner()) {
277277
panic!(

nexus/reconfigurator/simulation/src/system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use nexus_types::{
2424
};
2525
use omicron_common::{api::external::Generation, disk::M2Slot};
2626
use omicron_uuid_kinds::{
27-
BlueprintUuid, CollectionUuid, ReconfiguratorSimUuid, SledUuid,
27+
BlueprintUuid, CollectionUuid, ReconfiguratorSimStateUuid, SledUuid,
2828
};
2929
use strum::IntoEnumIterator as _;
3030

@@ -677,7 +677,7 @@ impl fmt::Display for ResolvedCollectionId {
677677
#[derive(Clone, Debug)]
678678
pub enum ReconfiguratorSimId {
679679
/// The specified state by full UUID.
680-
Id(ReconfiguratorSimUuid),
680+
Id(ReconfiguratorSimStateUuid),
681681

682682
/// The specified state by UUID prefix.
683683
Prefix(String),

uuid-kinds/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl_typed_uuid_kinds! {
7272
Rack = {},
7373
RackInit = {},
7474
RackReset = {},
75-
ReconfiguratorSim = {},
75+
ReconfiguratorSimState = {},
7676
Region = {},
7777
SiloGroup = {},
7878
SiloUser = {},

0 commit comments

Comments
 (0)