Skip to content

Commit

Permalink
Add disk generation to inventory (oxidecomputer#7162)
Browse files Browse the repository at this point in the history
This is the first PR related to fixing oxidecomputer#7098
  • Loading branch information
andrewjstone authored Nov 26, 2024
1 parent 8674bfc commit 03ede4a
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions nexus-sled-agent-shared/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct Inventory {
pub disks: Vec<InventoryDisk>,
pub zpools: Vec<InventoryZpool>,
pub datasets: Vec<InventoryDataset>,
pub omicron_physical_disks_generation: Generation,
}

/// Describes the role of the sled within the rack.
Expand Down
4 changes: 4 additions & 0 deletions nexus/db-model/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ pub struct InvSledAgent {
pub usable_hardware_threads: SqlU32,
pub usable_physical_ram: ByteCount,
pub reservoir_size: ByteCount,
pub omicron_physical_disks_generation: Generation,
}

impl InvSledAgent {
Expand Down Expand Up @@ -852,6 +853,9 @@ impl InvSledAgent {
sled_agent.usable_physical_ram,
),
reservoir_size: ByteCount::from(sled_agent.reservoir_size),
omicron_physical_disks_generation: Generation::from(
sled_agent.omicron_physical_disks_generation,
),
})
}
}
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 @@ -1486,6 +1486,7 @@ table! {
usable_hardware_threads -> Int8,
usable_physical_ram -> Int8,
reservoir_size -> Int8,
omicron_physical_disks_generation -> Int8,
}
}

Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(114, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(115, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -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(115, "inv-omicron-physical-disks-generation"),
KnownVersion::new(114, "crucible-ref-count-records"),
KnownVersion::new(113, "add-tx-eq"),
KnownVersion::new(112, "blueprint-dataset"),
Expand Down
9 changes: 9 additions & 0 deletions nexus/db-queries/src/db/datastore/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,10 @@ impl DataStore {
sled_agent.reservoir_size,
)
.into_sql::<diesel::sql_types::Int8>(),
nexus_db_model::Generation(
sled_agent.omicron_physical_disks_generation,
)
.into_sql::<diesel::sql_types::Int8>(),
))
.filter(
baseboard_dsl::part_number
Expand All @@ -914,6 +918,7 @@ impl DataStore {
sa_dsl::usable_hardware_threads,
sa_dsl::usable_physical_ram,
sa_dsl::reservoir_size,
sa_dsl::omicron_physical_disks_generation,
))
.execute_async(&conn)
.await?;
Expand All @@ -933,6 +938,7 @@ impl DataStore {
_usable_hardware_threads,
_usable_physical_ram,
_reservoir_size,
_omicron_physical_disks_generation,
) = sa_dsl::inv_sled_agent::all_columns();
}

Expand Down Expand Up @@ -2377,6 +2383,9 @@ impl DataStore {
.get(sled_id.as_untyped_uuid())
.map(|datasets| datasets.to_vec())
.unwrap_or_default(),
omicron_physical_disks_generation: s
.omicron_physical_disks_generation
.into(),
};
sled_agents.insert(sled_id, sled_agent);
}
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-queries/src/db/datastore/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ mod test {
disks,
zpools: vec![],
datasets: vec![],
omicron_physical_disks_generation:
omicron_common::api::external::Generation::new(),
},
)
.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions nexus/inventory/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ impl CollectionBuilder {
.into_iter()
.map(|d| d.into())
.collect(),
omicron_physical_disks_generation: inventory
.omicron_physical_disks_generation,
};

if let Some(previous) = self.sleds.get(&sled_id) {
Expand Down
1 change: 1 addition & 0 deletions nexus/inventory/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,5 +573,6 @@ pub fn sled_agent(
disks,
zpools,
datasets,
omicron_physical_disks_generation: Generation::new(),
}
}
2 changes: 2 additions & 0 deletions nexus/reconfigurator/planning/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ impl Sled {
})
.collect(),
datasets: vec![],
omicron_physical_disks_generation: Generation::new(),
}
};

Expand Down Expand Up @@ -820,6 +821,7 @@ impl Sled {
disks: vec![],
zpools: vec![],
datasets: vec![],
omicron_physical_disks_generation: Generation::new(),
};

Sled {
Expand Down
10 changes: 10 additions & 0 deletions nexus/types/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use nexus_sled_agent_shared::inventory::OmicronZoneConfig;
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
use nexus_sled_agent_shared::inventory::SledRole;
use omicron_common::api::external::ByteCount;
use omicron_common::api::external::Generation;
pub use omicron_common::api::internal::shared::NetworkInterface;
pub use omicron_common::api::internal::shared::NetworkInterfaceKind;
pub use omicron_common::api::internal::shared::SourceNatConfig;
Expand Down Expand Up @@ -520,4 +521,13 @@ pub struct SledAgent {
pub disks: Vec<PhysicalDisk>,
pub zpools: Vec<Zpool>,
pub datasets: Vec<Dataset>,
/// As part of reconfigurator planning we need to know the control plane
/// disks configuration that the sled-agent has seen last. Specifically,
/// this allows the planner to know if a disk expungement has been seen by
/// the sled-agent, so that the planner can decommission the expunged disk.
///
/// This field corresponds to the `generation` field in
/// `OmicronPhysicalDisksConfig` that is stored in the blueprint and sent to
/// the sled-agent via the executor over the internal API.
pub omicron_physical_disks_generation: Generation,
}
4 changes: 4 additions & 0 deletions openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,9 @@
"$ref": "#/components/schemas/InventoryDisk"
}
},
"omicron_physical_disks_generation": {
"$ref": "#/components/schemas/Generation"
},
"omicron_zones": {
"$ref": "#/components/schemas/OmicronZonesConfig"
},
Expand Down Expand Up @@ -3976,6 +3979,7 @@
"baseboard",
"datasets",
"disks",
"omicron_physical_disks_generation",
"omicron_zones",
"reservoir_size",
"sled_agent_address",
Expand Down
5 changes: 4 additions & 1 deletion schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,9 @@ CREATE TABLE IF NOT EXISTS omicron.public.inv_sled_agent (
usable_physical_ram INT8 NOT NULL,
reservoir_size INT8 CHECK (reservoir_size < usable_physical_ram) NOT NULL,

-- The last generation of OmicronPhysicalDisksConfig seen by the sled-agent
omicron_physical_disks_generation INT8 NOT NULL,

PRIMARY KEY (inv_collection_id, sled_id)
);

Expand Down Expand Up @@ -4684,7 +4687,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
(TRUE, NOW(), NOW(), '114.0.0', NULL)
(TRUE, NOW(), NOW(), '115.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;
3 changes: 3 additions & 0 deletions schema/crdb/inv-omicron-physical-disks-generation/up1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE omicron.public.inv_sled_agent
ADD COLUMN IF NOT EXISTS omicron_physical_disks_generation INT8
NOT NULL DEFAULT 1;
2 changes: 2 additions & 0 deletions schema/crdb/inv-omicron-physical-disks-generation/up2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE omicron.public.inv_sled_agent
ALTER COLUMN omicron_physical_disks_generation DROP DEFAULT;
1 change: 1 addition & 0 deletions sled-agent/src/rack_setup/plan/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ mod tests {
disks,
zpools: vec![],
datasets: vec![],
omicron_physical_disks_generation: Generation::new(),
},
is_scrimlet,
)];
Expand Down
1 change: 1 addition & 0 deletions sled-agent/src/rack_setup/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,7 @@ mod test {
.collect(),
zpools: vec![],
datasets: vec![],
omicron_physical_disks_generation: Generation::new(),
},
true,
)
Expand Down
1 change: 1 addition & 0 deletions sled-agent/src/sim/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ impl SledAgent {
.collect::<Vec<_>>()
})
.unwrap_or_else(|_| vec![]),
omicron_physical_disks_generation: Generation::new(),
})
}

Expand Down
1 change: 1 addition & 0 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ impl SledAgent {
disks,
zpools,
datasets,
omicron_physical_disks_generation: *all_disks.generation(),
})
}

Expand Down

0 comments on commit 03ede4a

Please sign in to comment.