Skip to content

Commit

Permalink
WIP: Expunge and Decommission disks in planner
Browse files Browse the repository at this point in the history
This PR is intended to fix #6999 and #7098.

The executor steps are all independent already except those that will be
fixed in this PR. A disk disposition was added to the blueprint and gets
changed from `InService` to `Expunged` when the `PlanningInput` changes.
A disk state was also added that goes from `Active` -> `Decommissioned`.
This disk state changes when the parent sled is expunged or the
sled-agent has been guaranteed to have seen the disk expungement as
reported via inventory.

This code fully implements the planner bits. The exucutor bits are
going to be pulled in from the [fewer-fatal-errors-in-executor-branch](main...fewer-fatal-errors-in-executor).
The executor bits are going to be expanded to implement the expunge and
decommission as dictated by the blueprint. Because the planner changes
are tightly coupled with the executor,  they will all come in this PR.

Further code will also be added to represent the disk disposition and
state in the blueprint and diff tables for omdb output. This PR is primarily
blocked on [revamping the diff system](#7240).
This is particularly necessary because we need to change those tables
and want to do it rigorously after we have a visitor based mechanism
for doing so.

There is some more cleanup to do here as well, in particular around
the `physical_disk_filter` and things that may not be needed when the
executor bits get fully implemented.
  • Loading branch information
andrewjstone committed Dec 19, 2024
1 parent cfd5a89 commit 900319b
Show file tree
Hide file tree
Showing 19 changed files with 629 additions and 131 deletions.
7 changes: 5 additions & 2 deletions nexus/db-model/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::schema::{
};
use crate::typed_uuid::DbTypedUuid;
use crate::{
impl_enum_type, ipv6, ByteCount, Generation, MacAddr, Name, SledState,
SqlU16, SqlU32, SqlU8,
impl_enum_type, ipv6, ByteCount, Generation, MacAddr, Name,
PhysicalDiskState, SledState, SqlU16, SqlU32, SqlU8,
};
use anyhow::{anyhow, bail, Context, Result};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -233,6 +233,7 @@ pub struct BpOmicronPhysicalDisk {
pub pool_id: Uuid,

pub disposition: DbBpPhysicalDiskDisposition,
pub state: PhysicalDiskState,
}

impl BpOmicronPhysicalDisk {
Expand All @@ -252,6 +253,7 @@ impl BpOmicronPhysicalDisk {
disposition: to_db_bp_physical_disk_disposition(
disk_config.disposition,
),
state: disk_config.state.into(),
}
}
}
Expand All @@ -267,6 +269,7 @@ impl From<BpOmicronPhysicalDisk> for BlueprintPhysicalDiskConfig {
},
id: disk.id.into(),
pool_id: ZpoolUuid::from_untyped_uuid(disk.pool_id),
state: disk.state.into(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,7 @@ table! {
pool_id -> Uuid,

disposition -> crate::DbBpPhysicalDiskDispositionEnum,
state -> crate::PhysicalDiskStateEnum,
}
}

Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,6 @@ mod tests {
&planning_input
.sled_lookup(SledFilter::Commissioned, new_sled_id)
.unwrap()
.resources,
)
.unwrap()
.disks
Expand All @@ -2350,6 +2349,7 @@ mod tests {
added: 4,
updated: 0,
expunged: 0,
decommissioned: 0,
removed: 0
}
);
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl DataStore {
let conn = &*self.pool_connection_authorized(&opctx).await?;
diesel::update(dsl::physical_disk)
.filter(dsl::time_deleted.is_null())
.physical_disk_filter(DiskFilter::ExpungedButActive)
.physical_disk_filter(DiskFilter::ExpungedButNotDecommissioned)
.set(dsl::disk_state.eq(PhysicalDiskState::Decommissioned))
.execute_async(conn)
.await
Expand Down
3 changes: 1 addition & 2 deletions nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3124,8 +3124,7 @@ mod tests {
sled_id,
&planning_input
.sled_lookup(SledFilter::InService, sled_id)
.expect("found sled")
.resources,
.expect("found sled"),
)
.expect("ensured disks");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ mod test {
generation: Generation::new().next(),
disks: vec![BlueprintPhysicalDiskConfig {
disposition: BlueprintPhysicalDiskDisposition::InService,
state: nexus_types::external_api::views::PhysicalDiskState::Active,
identity: DiskIdentity {
vendor: "test-vendor".to_string(),
serial: "test-serial".to_string(),
Expand Down
Loading

0 comments on commit 900319b

Please sign in to comment.