Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions dev-tools/reconfigurator-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use omicron_repl_utils::run_repl_from_file;
use omicron_repl_utils::run_repl_on_stdin;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::OmicronZoneUuid;
use omicron_uuid_kinds::ReconfiguratorSimUuid;
use omicron_uuid_kinds::ReconfiguratorSimStateUuid;
use omicron_uuid_kinds::SledUuid;
use omicron_uuid_kinds::VnicUuid;
use omicron_uuid_kinds::{BlueprintUuid, MupdateOverrideUuid};
Expand Down Expand Up @@ -89,7 +89,7 @@ struct ReconfiguratorSim {
// The simulator currently being used.
sim: Simulator,
// The current state.
current: ReconfiguratorSimUuid,
current: ReconfiguratorSimStateUuid,
// The current system state
log: slog::Logger,
}
Expand Down Expand Up @@ -1456,7 +1456,7 @@ enum StateArgs {
struct StateLogArgs {
/// Starting state ID (defaults to current state)
#[clap(long)]
from: Option<ReconfiguratorSimUuid>,
from: Option<ReconfiguratorSimStateUuid>,

/// Limit number of states to display
#[clap(long, short = 'n')]
Expand Down Expand Up @@ -2829,7 +2829,7 @@ fn cmd_state_switch(
args: StateSwitchArgs,
) -> anyhow::Result<Option<String>> {
// Try parsing as a full UUID first, then fall back to prefix matching.
let target_id = match args.state_id.parse::<ReconfiguratorSimUuid>() {
let target_id = match args.state_id.parse::<ReconfiguratorSimStateUuid>() {
Ok(id) => id,
Err(_) => sim.sim.get_state_by_prefix(&args.state_id)?,
};
Expand Down
4 changes: 2 additions & 2 deletions nexus/reconfigurator/simulation/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::BTreeSet;
use indent_write::indentable::Indentable as _;
use itertools::Itertools;
use omicron_common::api::external::{Generation, Name};
use omicron_uuid_kinds::ReconfiguratorSimUuid;
use omicron_uuid_kinds::ReconfiguratorSimStateUuid;
use swrite::{SWrite, swriteln};
use thiserror::Error;

Expand Down Expand Up @@ -170,7 +170,7 @@ impl UnknownZoneNamesError {
#[derive(Clone, Debug)]
pub struct StateMatch {
/// The state ID.
pub id: ReconfiguratorSimUuid,
pub id: ReconfiguratorSimStateUuid,
/// The state generation.
pub generation: Generation,
/// The state description.
Expand Down
27 changes: 15 additions & 12 deletions nexus/reconfigurator/simulation/src/render_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::collections::{HashMap, HashSet};

use omicron_uuid_kinds::ReconfiguratorSimUuid;
use omicron_uuid_kinds::ReconfiguratorSimStateUuid;
use renderdag::{Ancestor, GraphRowRenderer, Renderer};
use swrite::{SWrite, swrite, swriteln};

Expand All @@ -17,13 +17,13 @@ use crate::{SimState, Simulator, utils::DisplayUuidPrefix};
pub struct GraphRenderOptions {
verbose: bool,
limit: Option<usize>,
from: Option<ReconfiguratorSimUuid>,
current: ReconfiguratorSimUuid,
from: Option<ReconfiguratorSimStateUuid>,
current: ReconfiguratorSimStateUuid,
}

impl GraphRenderOptions {
/// Create new render options with the current state.
pub fn new(current: ReconfiguratorSimUuid) -> Self {
pub fn new(current: ReconfiguratorSimStateUuid) -> Self {
Self { verbose: false, limit: None, from: None, current }
}

Expand All @@ -40,7 +40,10 @@ impl GraphRenderOptions {
}

/// Set the starting state for ancestry filtering.
pub fn with_from(mut self, from: Option<ReconfiguratorSimUuid>) -> Self {
pub fn with_from(
mut self,
from: Option<ReconfiguratorSimStateUuid>,
) -> Self {
self.from = from;
self
}
Expand All @@ -59,7 +62,7 @@ impl Simulator {
&self,
options: &GraphRenderOptions,
) -> Vec<&SimState> {
let mut remaining_heads: Vec<ReconfiguratorSimUuid> =
let mut remaining_heads: Vec<ReconfiguratorSimStateUuid> =
if let Some(from_id) = options.from {
vec![from_id]
} else {
Expand Down Expand Up @@ -106,10 +109,10 @@ impl Simulator {
/// Recursively walk a branch, processing merge points along the way.
fn walk_branch_recursive<'a>(
&'a self,
mut current_id: ReconfiguratorSimUuid,
mut current_id: ReconfiguratorSimStateUuid,
node_to_heads: &HashMap<
ReconfiguratorSimUuid,
Vec<ReconfiguratorSimUuid>,
ReconfiguratorSimStateUuid,
Vec<ReconfiguratorSimStateUuid>,
>,
walk_state: &mut WalkState<'a>,
) {
Expand Down Expand Up @@ -151,12 +154,12 @@ impl Simulator {
/// State accumulated during graph traversal.
struct WalkState<'a> {
states: Vec<&'a SimState>,
visited: HashSet<ReconfiguratorSimUuid>,
remaining_heads: Vec<ReconfiguratorSimUuid>,
visited: HashSet<ReconfiguratorSimStateUuid>,
remaining_heads: Vec<ReconfiguratorSimStateUuid>,
}

impl<'a> WalkState<'a> {
fn new(heads: Vec<ReconfiguratorSimUuid>) -> Self {
fn new(heads: Vec<ReconfiguratorSimStateUuid>) -> Self {
Self {
states: Vec::new(),
visited: HashSet::new(),
Expand Down
26 changes: 17 additions & 9 deletions nexus/reconfigurator/simulation/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use std::{collections::HashMap, sync::Arc};

use indexmap::IndexSet;
use omicron_uuid_kinds::{ReconfiguratorSimKind, ReconfiguratorSimUuid};
use omicron_uuid_kinds::{
ReconfiguratorSimStateKind, ReconfiguratorSimStateUuid,
};
use typed_rng::TypedUuidRng;

use crate::{
Expand Down Expand Up @@ -48,8 +50,8 @@ pub struct Simulator {
// In the future, it would be interesting to store a chain of every set of
// heads over time, similar to `jj op log`. That would let us implement undo
// and restore operations.
heads: IndexSet<ReconfiguratorSimUuid>,
states: HashMap<ReconfiguratorSimUuid, Arc<SimState>>,
heads: IndexSet<ReconfiguratorSimStateUuid>,
states: HashMap<ReconfiguratorSimStateUuid, Arc<SimState>>,
// This state corresponds to `ROOT_ID`.
//
// Storing it in the Arc is extremely important! `SimStateBuilder` stores a
Expand All @@ -59,15 +61,16 @@ pub struct Simulator {
// points to the same memory address.
root_state: Arc<SimState>,
// Top-level (unversioned) RNG.
sim_uuid_rng: TypedUuidRng<ReconfiguratorSimKind>,
sim_uuid_rng: TypedUuidRng<ReconfiguratorSimStateKind>,
}

impl Simulator {
/// The root ID of the store.
///
/// This is always defined to be the nil UUID, and if queried will always
/// have a state associated with it.
pub const ROOT_ID: ReconfiguratorSimUuid = ReconfiguratorSimUuid::nil();
pub const ROOT_ID: ReconfiguratorSimStateUuid =
ReconfiguratorSimStateUuid::nil();

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

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

/// Get the current heads of the store.
#[inline]
pub fn heads(&self) -> &IndexSet<ReconfiguratorSimUuid> {
pub fn heads(&self) -> &IndexSet<ReconfiguratorSimStateUuid> {
&self.heads
}

/// Get the state for the given UUID.
pub fn get_state(&self, id: ReconfiguratorSimUuid) -> Option<&SimState> {
pub fn get_state(
&self,
id: ReconfiguratorSimStateUuid,
) -> Option<&SimState> {
if id == Self::ROOT_ID {
return Some(&self.root_state);
}
Expand All @@ -126,7 +134,7 @@ impl Simulator {
pub fn get_state_by_prefix(
&self,
prefix: &str,
) -> Result<ReconfiguratorSimUuid, StateIdPrefixError> {
) -> Result<ReconfiguratorSimStateUuid, StateIdPrefixError> {
let mut matching_ids = Vec::new();

if Self::ROOT_ID.to_string().starts_with(prefix) {
Expand Down Expand Up @@ -170,7 +178,7 @@ impl Simulator {
}

#[inline]
pub(crate) fn next_sim_uuid(&mut self) -> ReconfiguratorSimUuid {
pub(crate) fn next_sim_uuid(&mut self) -> ReconfiguratorSimStateUuid {
self.sim_uuid_rng.next()
}

Expand Down
16 changes: 8 additions & 8 deletions nexus/reconfigurator/simulation/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{Context, anyhow, bail};
use nexus_inventory::CollectionBuilder;
use nexus_types::deployment::UnstableReconfiguratorState;
use omicron_common::api::external::Generation;
use omicron_uuid_kinds::{CollectionUuid, ReconfiguratorSimUuid};
use omicron_uuid_kinds::{CollectionUuid, ReconfiguratorSimStateUuid};
use sync_ptr::SyncConstPtr;

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

#[inline]
#[must_use]
pub fn id(&self) -> ReconfiguratorSimUuid {
pub fn id(&self) -> ReconfiguratorSimStateUuid {
self.id
}

#[inline]
#[must_use]
pub fn parent(&self) -> Option<ReconfiguratorSimUuid> {
pub fn parent(&self) -> Option<ReconfiguratorSimStateUuid> {
self.parent
}

Expand Down Expand Up @@ -185,7 +185,7 @@ pub struct SimStateBuilder {
// Used to check that the simulator is the same as the one that created
// this state.
root_state: SyncConstPtr<SimState>,
parent: ReconfiguratorSimUuid,
parent: ReconfiguratorSimStateUuid,
parent_gen: Generation,
system: SimSystemBuilder,
config: SimConfigBuilder,
Expand All @@ -195,7 +195,7 @@ pub struct SimStateBuilder {
impl SimStateBuilder {
#[inline]
#[must_use]
pub fn parent(&self) -> ReconfiguratorSimUuid {
pub fn parent(&self) -> ReconfiguratorSimStateUuid {
self.parent
}

Expand Down Expand Up @@ -271,7 +271,7 @@ impl SimStateBuilder {
self,
description: String,
sim: &mut Simulator,
) -> ReconfiguratorSimUuid {
) -> ReconfiguratorSimStateUuid {
// Check for unrelated histories.
if !std::ptr::eq(sim.root_state(), self.root_state.inner()) {
panic!(
Expand Down
2 changes: 1 addition & 1 deletion uuid-kinds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl_typed_uuid_kinds! {
Rack = {},
RackInit = {},
RackReset = {},
ReconfiguratorSim = {},
ReconfiguratorSimState = {},
Region = {},
SiloGroup = {},
SiloUser = {},
Expand Down
Loading