Skip to content
Merged
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
49 changes: 23 additions & 26 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ struct CrucibleDatasetRow {
// dataset fields
id: DatasetUuid,
time_deleted: String,
pool_id: Uuid,
pool_id: ZpoolUuid,
address: String,
size_used: i64,
no_provision: bool,
Expand Down Expand Up @@ -1679,34 +1679,33 @@ async fn get_crucible_dataset_rows(
bail!("no latest inventory found!");
};

let mut zpool_total_size: HashMap<Uuid, i64> = HashMap::new();
let mut zpool_total_size: HashMap<ZpoolUuid, i64> = HashMap::new();

for sled_agent in latest_collection.sled_agents {
for zpool in sled_agent.zpools {
zpool_total_size
.insert(zpool.id.into_untyped_uuid(), zpool.total_size.into());
zpool_total_size.insert(zpool.id, zpool.total_size.into());
}
}

let zpools: HashMap<Uuid, Zpool> = datastore
let zpools: HashMap<ZpoolUuid, Zpool> = datastore
.zpool_list_all_external_batched(opctx)
.await?
.into_iter()
.map(|(zpool, _)| (zpool.id().into_untyped_uuid(), zpool))
.map(|(zpool, _)| (zpool.id(), zpool))
.collect();

let mut result: Vec<CrucibleDatasetRow> =
Vec::with_capacity(crucible_datasets.len());

for d in crucible_datasets {
let control_plane_storage_buffer: Option<i64> = match zpools
.get(&d.pool_id)
.get(&d.pool_id())
{
Some(zpool) => Some(zpool.control_plane_storage_buffer().into()),
None => None,
};

let pool_total_size = zpool_total_size.get(&d.pool_id);
let pool_total_size = zpool_total_size.get(&d.pool_id());

result.push(CrucibleDatasetRow {
// dataset fields
Expand All @@ -1715,7 +1714,7 @@ async fn get_crucible_dataset_rows(
Some(t) => t.to_string(),
None => String::from(""),
},
pool_id: d.pool_id,
pool_id: d.pool_id(),
address: d.address().to_string(),
size_used: d.size_used,
no_provision: d.no_provision(),
Expand Down Expand Up @@ -2200,7 +2199,7 @@ async fn cmd_db_disk_info(

let mut rows = Vec::with_capacity(3);
for (dataset, region) in regions {
let my_pool_id = dataset.pool_id;
let my_pool_id = dataset.pool_id();
let (_, my_zpool) = LookupPath::new(opctx, datastore)
.zpool_id(my_pool_id)
.fetch()
Expand All @@ -2219,7 +2218,7 @@ async fn cmd_db_disk_info(
host_serial: my_sled.serial_number().to_string(),
region: region.id().to_string(),
dataset: dataset.id().to_string(),
physical_disk: my_zpool.physical_disk_id.to_string(),
physical_disk: my_zpool.physical_disk_id().to_string(),
});
}

Expand Down Expand Up @@ -2311,7 +2310,7 @@ async fn cmd_db_disk_physical(
}

let datasets = query
.filter(dataset_dsl::pool_id.eq(zp.id()))
.filter(dataset_dsl::pool_id.eq(to_db_typed_uuid(zp.id())))
.select(CrucibleDataset::as_select())
.load_async(&*conn)
.await
Expand Down Expand Up @@ -2739,7 +2738,7 @@ async fn cmd_db_snapshot_info(
} else {
let mut rows = Vec::with_capacity(3);
for (dataset, region) in regions {
let my_pool_id = dataset.pool_id;
let my_pool_id = dataset.pool_id();
let (_, my_zpool) = LookupPath::new(opctx, datastore)
.zpool_id(my_pool_id)
.fetch()
Expand All @@ -2758,7 +2757,7 @@ async fn cmd_db_snapshot_info(
host_serial: my_sled.serial_number().to_string(),
region: region.id().to_string(),
dataset: dataset.id().to_string(),
physical_disk: my_zpool.physical_disk_id.to_string(),
physical_disk: my_zpool.physical_disk_id().to_string(),
});
}

Expand All @@ -2779,7 +2778,7 @@ async fn cmd_db_snapshot_info(

let mut rows = Vec::with_capacity(3);
for (dataset, region) in regions {
let my_pool_id = dataset.pool_id;
let my_pool_id = dataset.pool_id();
let (_, my_zpool) = LookupPath::new(opctx, datastore)
.zpool_id(my_pool_id)
.fetch()
Expand All @@ -2798,7 +2797,7 @@ async fn cmd_db_snapshot_info(
host_serial: my_sled.serial_number().to_string(),
region: region.id().to_string(),
dataset: dataset.id().to_string(),
physical_disk: my_zpool.physical_disk_id.to_string(),
physical_disk: my_zpool.physical_disk_id().to_string(),
});
}

Expand Down Expand Up @@ -3832,7 +3831,7 @@ async fn cmd_db_dry_run_region_allocation(
pub dataset_id: DatasetUuid,
pub size_used: i64,

pub pool_id: Uuid,
pub pool_id: ZpoolUuid,

#[tabled(display_with = "option_impl_display")]
pub total_size: Option<i64>,
Expand All @@ -3852,17 +3851,16 @@ async fn cmd_db_dry_run_region_allocation(
);
};

let mut zpool_total_size: HashMap<Uuid, i64> = HashMap::new();
let mut zpool_total_size: HashMap<ZpoolUuid, i64> = HashMap::new();

for sled_agent in latest_collection.sled_agents {
for zpool in sled_agent.zpools {
zpool_total_size
.insert(zpool.id.into_untyped_uuid(), zpool.total_size.into());
zpool_total_size.insert(zpool.id, zpool.total_size.into());
}
}

for (dataset, region) in datasets_and_regions {
let pool_id = dataset.pool_id.into_untyped_uuid();
let pool_id = dataset.pool_id();
let total_size = zpool_total_size.get(&pool_id);
rows.push(Row {
region_id: region.id(),
Expand Down Expand Up @@ -7700,19 +7698,18 @@ async fn cmd_db_zpool_list(
bail!("no latest inventory found!");
};

let mut zpool_total_size: HashMap<Uuid, i64> = HashMap::new();
let mut zpool_total_size: HashMap<ZpoolUuid, i64> = HashMap::new();

for sled_agent in latest_collection.sled_agents {
for zpool in sled_agent.zpools {
zpool_total_size
.insert(zpool.id.into_untyped_uuid(), zpool.total_size.into());
zpool_total_size.insert(zpool.id, zpool.total_size.into());
}
}

#[derive(Tabled)]
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct ZpoolRow {
id: Uuid,
id: ZpoolUuid,
time_deleted: String,
sled_id: SledUuid,
physical_disk_id: PhysicalDiskUuid,
Expand All @@ -7724,7 +7721,7 @@ async fn cmd_db_zpool_list(
let rows: Vec<ZpoolRow> = zpools
.into_iter()
.map(|(p, _)| {
let zpool_id = p.id().into_untyped_uuid();
let zpool_id = p.id();
Ok(ZpoolRow {
id: zpool_id,
time_deleted: match p.time_deleted() {
Expand Down
2 changes: 1 addition & 1 deletion nexus/auth/src/authz/api_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ authz_resource! {
authz_resource! {
name = "Zpool",
parent = "Fleet",
primary_key = Uuid,
primary_key = { uuid_kind = ZpoolKind },
roles_allowed = false,
polar_snippet = FleetChild,
}
Expand Down
4 changes: 2 additions & 2 deletions nexus/db-lookup/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a> LookupPath<'a> {
}

/// Select a resource of type Zpool, identified by its id
pub fn zpool_id(self, id: Uuid) -> Zpool<'a> {
pub fn zpool_id(self, id: ZpoolUuid) -> Zpool<'a> {
Zpool::PrimaryKey(Root { lookup_root: self }, id)
}

Expand Down Expand Up @@ -782,7 +782,7 @@ lookup_resource! {
ancestors = [],
lookup_by_name = false,
soft_deletes = true,
primary_key_columns = [ { column_name = "id", rust_type = Uuid } ]
primary_key_columns = [ { column_name = "id", uuid_kind = ZpoolKind } ]
}

lookup_resource! {
Expand Down
12 changes: 9 additions & 3 deletions nexus/db-model/src/crucible_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use super::{Generation, Region, SqlU16};
use crate::collection::DatastoreCollectionConfig;
use crate::ipv6;
use crate::typed_uuid::DbTypedUuid;
use chrono::{DateTime, Utc};
use db_macros::Asset;
use nexus_db_schema::schema::{crucible_dataset, region};
use omicron_uuid_kinds::*;
use serde::{Deserialize, Serialize};
use std::net::{Ipv6Addr, SocketAddrV6};
use uuid::Uuid;
Expand Down Expand Up @@ -35,7 +37,7 @@ pub struct CrucibleDataset {
time_deleted: Option<DateTime<Utc>>,
rcgen: Generation,

pub pool_id: Uuid,
pub pool_id: DbTypedUuid<ZpoolKind>,

ip: ipv6::Ipv6Addr,
port: SqlU16,
Expand All @@ -50,14 +52,14 @@ pub struct CrucibleDataset {
impl CrucibleDataset {
pub fn new(
id: omicron_uuid_kinds::DatasetUuid,
pool_id: Uuid,
pool_id: ZpoolUuid,
addr: SocketAddrV6,
) -> Self {
Self {
identity: CrucibleDatasetIdentity::new(id),
time_deleted: None,
rcgen: Generation::new(),
pool_id,
pool_id: pool_id.into(),
ip: addr.ip().into(),
port: addr.port().into(),
size_used: 0,
Expand All @@ -80,6 +82,10 @@ impl CrucibleDataset {
pub fn no_provision(&self) -> bool {
self.no_provision
}

pub fn pool_id(&self) -> ZpoolUuid {
self.pool_id.into()
}
}

// Datasets contain regions
Expand Down
8 changes: 3 additions & 5 deletions nexus/db-model/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ use omicron_common::update::OmicronZoneManifestSource;
use omicron_common::zpool_name::ZpoolName;
use omicron_uuid_kinds::DatasetKind;
use omicron_uuid_kinds::DatasetUuid;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::InternalZpoolKind;
use omicron_uuid_kinds::MupdateKind;
use omicron_uuid_kinds::MupdateOverrideKind;
Expand All @@ -91,7 +90,6 @@ use omicron_uuid_kinds::PhysicalDiskUuid;
use omicron_uuid_kinds::SledKind;
use omicron_uuid_kinds::SledUuid;
use omicron_uuid_kinds::ZpoolKind;
use omicron_uuid_kinds::ZpoolUuid;
use omicron_uuid_kinds::{CollectionKind, OmicronZoneKind};
use omicron_uuid_kinds::{CollectionUuid, OmicronZoneUuid};
use std::collections::BTreeSet;
Expand Down Expand Up @@ -2036,7 +2034,7 @@ impl From<InvNvmeDiskFirmware>
pub struct InvZpool {
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub time_collected: DateTime<Utc>,
pub id: Uuid,
pub id: DbTypedUuid<ZpoolKind>,
pub sled_id: DbTypedUuid<SledKind>,
pub total_size: ByteCount,
}
Expand All @@ -2050,7 +2048,7 @@ impl InvZpool {
Self {
inv_collection_id: inv_collection_id.into(),
time_collected: zpool.time_collected,
id: zpool.id.into_untyped_uuid(),
id: zpool.id.into(),
sled_id: sled_id.into(),
total_size: zpool.total_size.into(),
}
Expand All @@ -2061,7 +2059,7 @@ impl From<InvZpool> for nexus_types::inventory::Zpool {
fn from(pool: InvZpool) -> Self {
Self {
time_collected: pool.time_collected,
id: ZpoolUuid::from_untyped_uuid(pool.id),
id: pool.id.into(),
total_size: *pool.total_size,
}
}
Expand Down
8 changes: 5 additions & 3 deletions nexus/db-model/src/zpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ use omicron_uuid_kinds::PhysicalDiskKind;
use omicron_uuid_kinds::PhysicalDiskUuid;
use omicron_uuid_kinds::SledKind;
use omicron_uuid_kinds::SledUuid;
use uuid::Uuid;
use omicron_uuid_kinds::ZpoolKind;
use omicron_uuid_kinds::ZpoolUuid;

/// Database representation of a Pool.
///
/// A zpool represents a ZFS storage pool, allocated on a single
/// physical sled.
#[derive(Queryable, Insertable, Debug, Clone, Selectable, Asset)]
#[diesel(table_name = zpool)]
#[asset(uuid_kind = ZpoolKind)]
pub struct Zpool {
#[diesel(embed)]
identity: ZpoolIdentity,
Expand Down Expand Up @@ -50,7 +52,7 @@ pub struct Zpool {

impl Zpool {
pub fn new(
id: Uuid,
id: ZpoolUuid,
sled_id: SledUuid,
physical_disk_id: PhysicalDiskUuid,
control_plane_storage_buffer: ByteCount,
Expand Down Expand Up @@ -83,7 +85,7 @@ impl Zpool {
}

impl DatastoreCollectionConfig<CrucibleDataset> for Zpool {
type CollectionId = Uuid;
type CollectionId = DbTypedUuid<ZpoolKind>;
type GenerationNumberColumn = zpool::dsl::rcgen;
type CollectionTimeDeletedColumn = zpool::dsl::time_deleted;
type CollectionIdColumn = crucible_dataset::dsl::pool_id;
Expand Down
Loading
Loading