Skip to content

Commit

Permalink
tear up way more of sled-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Jun 19, 2024
1 parent 731a0a1 commit d2ba9ad
Show file tree
Hide file tree
Showing 14 changed files with 683 additions and 722 deletions.
16 changes: 2 additions & 14 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ impl From<omicron_common::api::internal::nexus::SledInstanceState>
Self {
propolis_id: s.propolis_id,
vmm_state: s.vmm_state.into(),
migration_state: s.migration_state.map(Into::into),
migration_in: s.migration_in.map(Into::into),
migration_out: s.migration_out.map(Into::into),
}
}
}
Expand All @@ -146,26 +147,13 @@ impl From<omicron_common::api::internal::nexus::MigrationRuntimeState>
) -> Self {
Self {
migration_id: s.migration_id,
role: s.role.into(),
state: s.state.into(),
gen: s.gen,
time_updated: s.time_updated,
}
}
}

impl From<omicron_common::api::internal::nexus::MigrationRole>
for types::MigrationRole
{
fn from(s: omicron_common::api::internal::nexus::MigrationRole) -> Self {
use omicron_common::api::internal::nexus::MigrationRole as Input;
match s {
Input::Source => Self::Source,
Input::Target => Self::Target,
}
}
}

impl From<omicron_common::api::internal::nexus::MigrationState>
for types::MigrationState
{
Expand Down
16 changes: 2 additions & 14 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ impl From<types::SledInstanceState>
Self {
propolis_id: s.propolis_id,
vmm_state: s.vmm_state.into(),
migration_state: s.migration_state.map(Into::into),
migration_in: s.migration_in.map(Into::into),
migration_out: s.migration_out.map(Into::into),
}
}
}
Expand All @@ -341,25 +342,12 @@ impl From<types::MigrationRuntimeState>
Self {
migration_id: s.migration_id,
state: s.state.into(),
role: s.role.into(),
gen: s.gen,
time_updated: s.time_updated,
}
}
}

impl From<types::MigrationRole>
for omicron_common::api::internal::nexus::MigrationRole
{
fn from(r: types::MigrationRole) -> Self {
use omicron_common::api::internal::nexus::MigrationRole as Output;
match r {
types::MigrationRole::Source => Output::Source,
types::MigrationRole::Target => Output::Target,
}
}
}

impl From<types::MigrationState>
for omicron_common::api::internal::nexus::MigrationState
{
Expand Down
56 changes: 26 additions & 30 deletions common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,32 @@ pub struct SledInstanceState {
/// The most recent state of the sled's VMM process.
pub vmm_state: VmmRuntimeState,

/// The current state of any in-progress migration for this instance, as
/// understood by this sled.
pub migration_state: Option<MigrationRuntimeState>,
/// The current state of any inbound migration to this VMM.
pub migration_in: Option<MigrationRuntimeState>,

/// The state of any outbound migration to this VMM.
pub migration_out: Option<MigrationRuntimeState>,
}

#[derive(Copy, Clone, Debug, Default)]
pub struct Migrations<'state> {
pub migration_in: Option<&'state MigrationRuntimeState>,
pub migration_out: Option<&'state MigrationRuntimeState>,
}

impl Migrations<'_> {
pub fn empty() -> Self {
Self { migration_in: None, migration_out: None }
}
}

impl SledInstanceState {
pub fn migrations(&self) -> Migrations<'_> {
Migrations {
migration_in: self.migration_in.as_ref(),
migration_out: self.migration_out.as_ref(),
}
}
}

/// An update from a sled regarding the state of a migration, indicating the
Expand All @@ -119,7 +142,6 @@ pub struct SledInstanceState {
pub struct MigrationRuntimeState {
pub migration_id: Uuid,
pub state: MigrationState,
pub role: MigrationRole,
pub gen: Generation,

/// Timestamp for the migration state update.
Expand Down Expand Up @@ -174,32 +196,6 @@ impl fmt::Display for MigrationState {
}
}

#[derive(
Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum MigrationRole {
/// This update concerns the source VMM of a migration.
Source,
/// This update concerns the target VMM of a migration.
Target,
}

impl MigrationRole {
pub fn label(&self) -> &'static str {
match self {
Self::Source => "source",
Self::Target => "target",
}
}
}

impl fmt::Display for MigrationRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}

// Oximeter producer/collector objects.

/// The kind of metric producer this is.
Expand Down
27 changes: 11 additions & 16 deletions nexus/db-queries/src/db/datastore/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use omicron_common::api::external::ListResultVec;
use omicron_common::api::external::LookupResult;
use omicron_common::api::external::LookupType;
use omicron_common::api::external::ResourceType;
use omicron_common::api::internal::nexus::MigrationRuntimeState;
use omicron_common::api::internal::nexus::Migrations;
use omicron_common::bail_unless;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::InstanceUuid;
Expand Down Expand Up @@ -549,13 +549,13 @@ impl DataStore {
new_instance: &InstanceRuntimeState,
vmm_id: &PropolisUuid,
new_vmm: &VmmRuntimeState,
migration: &Option<MigrationRuntimeState>,
migrations: Migrations<'_>,
) -> Result<InstanceUpdateResult, Error> {
let query = crate::db::queries::instance::InstanceAndVmmUpdate::new(
*vmm_id,
new_vmm.clone(),
Some((*instance_id, new_instance.clone())),
migration.clone(),
migrations,
);

// The InstanceAndVmmUpdate query handles and indicates failure to find
Expand All @@ -566,26 +566,21 @@ impl DataStore {
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))?;

let instance_updated = match result.instance_status {
Some(UpdateStatus::Updated) => true,
Some(UpdateStatus::NotUpdatedButExists) => false,
None => false,
};

let instance_updated = result.instance_status.was_updated();
let vmm_updated = match result.vmm_status {
Some(UpdateStatus::Updated) => true,
Some(UpdateStatus::NotUpdatedButExists) => false,
None => false,
};

let migration_updated = if migration.is_some() {
Some(match result.migration_status {
Some(UpdateStatus::Updated) => true,
Some(UpdateStatus::NotUpdatedButExists) => false,
None => false,
})
let migration_updated = if migrations.migration_in.is_some()
|| migrations.migration_out.is_some()
{
Some(
result.migration_in_status.was_updated()
|| result.migration_out_status.was_updated(),
)
} else {
debug_assert_eq!(result.migration_status, None);
None
};

Expand Down
26 changes: 12 additions & 14 deletions nexus/db-queries/src/db/datastore/vmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use omicron_common::api::external::LookupResult;
use omicron_common::api::external::LookupType;
use omicron_common::api::external::ResourceType;
use omicron_common::api::external::UpdateResult;
use omicron_common::api::internal::nexus::MigrationRuntimeState;
use omicron_common::api::internal::nexus::Migrations;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::PropolisUuid;
use std::net::SocketAddr;
Expand Down Expand Up @@ -144,15 +144,15 @@ impl DataStore {

pub async fn vmm_and_migration_update_runtime(
&self,
vmm_id: Uuid,
vmm_id: PropolisUuid,
new_runtime: &VmmRuntimeState,
migration: Option<&MigrationRuntimeState>,
migrations: Migrations<'_>,
) -> Result<(bool, Option<bool>), Error> {
let query = crate::db::queries::instance::InstanceAndVmmUpdate::new(
vmm_id,
new_runtime.clone(),
None,
migration.cloned(),
migrations,
);

// The InstanceAndVmmUpdate query handles and indicates failure to find
Expand All @@ -163,25 +163,23 @@ impl DataStore {
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))?;

debug_assert_eq!(result.instance_status, None);
// debug_assert_eq!(result.instance_status, );

let vmm_updated = match result.vmm_status {
Some(UpdateStatus::Updated) => true,
Some(UpdateStatus::NotUpdatedButExists) => false,
None => false,
};

let migration_updated = if migration.is_some() {
Some(match result.migration_status {
Some(UpdateStatus::Updated) => true,
Some(UpdateStatus::NotUpdatedButExists) => false,
None => false,
})
let migration_updated = if migrations.migration_in.is_some()
|| migrations.migration_out.is_some()
{
Some(
result.migration_in_status.was_updated()
|| result.migration_out_status.was_updated(),
)
} else {
debug_assert_eq!(result.migration_status, None);
None
};

Ok((vmm_updated, migration_updated))
}

Expand Down
Loading

0 comments on commit d2ba9ad

Please sign in to comment.