Skip to content

Commit 8442cee

Browse files
authored
Use ZpoolUuid (#9012)
1 parent 958cde1 commit 8442cee

File tree

32 files changed

+158
-160
lines changed

32 files changed

+158
-160
lines changed

dev-tools/omdb/src/bin/omdb/db.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ struct CrucibleDatasetRow {
16431643
// dataset fields
16441644
id: DatasetUuid,
16451645
time_deleted: String,
1646-
pool_id: Uuid,
1646+
pool_id: ZpoolUuid,
16471647
address: String,
16481648
size_used: i64,
16491649
no_provision: bool,
@@ -1679,34 +1679,33 @@ async fn get_crucible_dataset_rows(
16791679
bail!("no latest inventory found!");
16801680
};
16811681

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

16841684
for sled_agent in latest_collection.sled_agents {
16851685
for zpool in sled_agent.zpools {
1686-
zpool_total_size
1687-
.insert(zpool.id.into_untyped_uuid(), zpool.total_size.into());
1686+
zpool_total_size.insert(zpool.id, zpool.total_size.into());
16881687
}
16891688
}
16901689

1691-
let zpools: HashMap<Uuid, Zpool> = datastore
1690+
let zpools: HashMap<ZpoolUuid, Zpool> = datastore
16921691
.zpool_list_all_external_batched(opctx)
16931692
.await?
16941693
.into_iter()
1695-
.map(|(zpool, _)| (zpool.id().into_untyped_uuid(), zpool))
1694+
.map(|(zpool, _)| (zpool.id(), zpool))
16961695
.collect();
16971696

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

17011700
for d in crucible_datasets {
17021701
let control_plane_storage_buffer: Option<i64> = match zpools
1703-
.get(&d.pool_id)
1702+
.get(&d.pool_id())
17041703
{
17051704
Some(zpool) => Some(zpool.control_plane_storage_buffer().into()),
17061705
None => None,
17071706
};
17081707

1709-
let pool_total_size = zpool_total_size.get(&d.pool_id);
1708+
let pool_total_size = zpool_total_size.get(&d.pool_id());
17101709

17111710
result.push(CrucibleDatasetRow {
17121711
// dataset fields
@@ -1715,7 +1714,7 @@ async fn get_crucible_dataset_rows(
17151714
Some(t) => t.to_string(),
17161715
None => String::from(""),
17171716
},
1718-
pool_id: d.pool_id,
1717+
pool_id: d.pool_id(),
17191718
address: d.address().to_string(),
17201719
size_used: d.size_used,
17211720
no_provision: d.no_provision(),
@@ -2200,7 +2199,7 @@ async fn cmd_db_disk_info(
22002199

22012200
let mut rows = Vec::with_capacity(3);
22022201
for (dataset, region) in regions {
2203-
let my_pool_id = dataset.pool_id;
2202+
let my_pool_id = dataset.pool_id();
22042203
let (_, my_zpool) = LookupPath::new(opctx, datastore)
22052204
.zpool_id(my_pool_id)
22062205
.fetch()
@@ -2219,7 +2218,7 @@ async fn cmd_db_disk_info(
22192218
host_serial: my_sled.serial_number().to_string(),
22202219
region: region.id().to_string(),
22212220
dataset: dataset.id().to_string(),
2222-
physical_disk: my_zpool.physical_disk_id.to_string(),
2221+
physical_disk: my_zpool.physical_disk_id().to_string(),
22232222
});
22242223
}
22252224

@@ -2311,7 +2310,7 @@ async fn cmd_db_disk_physical(
23112310
}
23122311

23132312
let datasets = query
2314-
.filter(dataset_dsl::pool_id.eq(zp.id()))
2313+
.filter(dataset_dsl::pool_id.eq(to_db_typed_uuid(zp.id())))
23152314
.select(CrucibleDataset::as_select())
23162315
.load_async(&*conn)
23172316
.await
@@ -2739,7 +2738,7 @@ async fn cmd_db_snapshot_info(
27392738
} else {
27402739
let mut rows = Vec::with_capacity(3);
27412740
for (dataset, region) in regions {
2742-
let my_pool_id = dataset.pool_id;
2741+
let my_pool_id = dataset.pool_id();
27432742
let (_, my_zpool) = LookupPath::new(opctx, datastore)
27442743
.zpool_id(my_pool_id)
27452744
.fetch()
@@ -2758,7 +2757,7 @@ async fn cmd_db_snapshot_info(
27582757
host_serial: my_sled.serial_number().to_string(),
27592758
region: region.id().to_string(),
27602759
dataset: dataset.id().to_string(),
2761-
physical_disk: my_zpool.physical_disk_id.to_string(),
2760+
physical_disk: my_zpool.physical_disk_id().to_string(),
27622761
});
27632762
}
27642763

@@ -2779,7 +2778,7 @@ async fn cmd_db_snapshot_info(
27792778

27802779
let mut rows = Vec::with_capacity(3);
27812780
for (dataset, region) in regions {
2782-
let my_pool_id = dataset.pool_id;
2781+
let my_pool_id = dataset.pool_id();
27832782
let (_, my_zpool) = LookupPath::new(opctx, datastore)
27842783
.zpool_id(my_pool_id)
27852784
.fetch()
@@ -2798,7 +2797,7 @@ async fn cmd_db_snapshot_info(
27982797
host_serial: my_sled.serial_number().to_string(),
27992798
region: region.id().to_string(),
28002799
dataset: dataset.id().to_string(),
2801-
physical_disk: my_zpool.physical_disk_id.to_string(),
2800+
physical_disk: my_zpool.physical_disk_id().to_string(),
28022801
});
28032802
}
28042803

@@ -3832,7 +3831,7 @@ async fn cmd_db_dry_run_region_allocation(
38323831
pub dataset_id: DatasetUuid,
38333832
pub size_used: i64,
38343833

3835-
pub pool_id: Uuid,
3834+
pub pool_id: ZpoolUuid,
38363835

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

3855-
let mut zpool_total_size: HashMap<Uuid, i64> = HashMap::new();
3854+
let mut zpool_total_size: HashMap<ZpoolUuid, i64> = HashMap::new();
38563855

38573856
for sled_agent in latest_collection.sled_agents {
38583857
for zpool in sled_agent.zpools {
3859-
zpool_total_size
3860-
.insert(zpool.id.into_untyped_uuid(), zpool.total_size.into());
3858+
zpool_total_size.insert(zpool.id, zpool.total_size.into());
38613859
}
38623860
}
38633861

38643862
for (dataset, region) in datasets_and_regions {
3865-
let pool_id = dataset.pool_id.into_untyped_uuid();
3863+
let pool_id = dataset.pool_id();
38663864
let total_size = zpool_total_size.get(&pool_id);
38673865
rows.push(Row {
38683866
region_id: region.id(),
@@ -7700,19 +7698,18 @@ async fn cmd_db_zpool_list(
77007698
bail!("no latest inventory found!");
77017699
};
77027700

7703-
let mut zpool_total_size: HashMap<Uuid, i64> = HashMap::new();
7701+
let mut zpool_total_size: HashMap<ZpoolUuid, i64> = HashMap::new();
77047702

77057703
for sled_agent in latest_collection.sled_agents {
77067704
for zpool in sled_agent.zpools {
7707-
zpool_total_size
7708-
.insert(zpool.id.into_untyped_uuid(), zpool.total_size.into());
7705+
zpool_total_size.insert(zpool.id, zpool.total_size.into());
77097706
}
77107707
}
77117708

77127709
#[derive(Tabled)]
77137710
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
77147711
struct ZpoolRow {
7715-
id: Uuid,
7712+
id: ZpoolUuid,
77167713
time_deleted: String,
77177714
sled_id: SledUuid,
77187715
physical_disk_id: PhysicalDiskUuid,
@@ -7724,7 +7721,7 @@ async fn cmd_db_zpool_list(
77247721
let rows: Vec<ZpoolRow> = zpools
77257722
.into_iter()
77267723
.map(|(p, _)| {
7727-
let zpool_id = p.id().into_untyped_uuid();
7724+
let zpool_id = p.id();
77287725
Ok(ZpoolRow {
77297726
id: zpool_id,
77307727
time_deleted: match p.time_deleted() {

nexus/auth/src/authz/api_resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ authz_resource! {
13211321
authz_resource! {
13221322
name = "Zpool",
13231323
parent = "Fleet",
1324-
primary_key = Uuid,
1324+
primary_key = { uuid_kind = ZpoolKind },
13251325
roles_allowed = false,
13261326
polar_snippet = FleetChild,
13271327
}

nexus/db-lookup/src/lookup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'a> LookupPath<'a> {
289289
}
290290

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

@@ -782,7 +782,7 @@ lookup_resource! {
782782
ancestors = [],
783783
lookup_by_name = false,
784784
soft_deletes = true,
785-
primary_key_columns = [ { column_name = "id", rust_type = Uuid } ]
785+
primary_key_columns = [ { column_name = "id", uuid_kind = ZpoolKind } ]
786786
}
787787

788788
lookup_resource! {

nexus/db-model/src/crucible_dataset.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
use super::{Generation, Region, SqlU16};
66
use crate::collection::DatastoreCollectionConfig;
77
use crate::ipv6;
8+
use crate::typed_uuid::DbTypedUuid;
89
use chrono::{DateTime, Utc};
910
use db_macros::Asset;
1011
use nexus_db_schema::schema::{crucible_dataset, region};
12+
use omicron_uuid_kinds::*;
1113
use serde::{Deserialize, Serialize};
1214
use std::net::{Ipv6Addr, SocketAddrV6};
1315
use uuid::Uuid;
@@ -35,7 +37,7 @@ pub struct CrucibleDataset {
3537
time_deleted: Option<DateTime<Utc>>,
3638
rcgen: Generation,
3739

38-
pub pool_id: Uuid,
40+
pub pool_id: DbTypedUuid<ZpoolKind>,
3941

4042
ip: ipv6::Ipv6Addr,
4143
port: SqlU16,
@@ -50,14 +52,14 @@ pub struct CrucibleDataset {
5052
impl CrucibleDataset {
5153
pub fn new(
5254
id: omicron_uuid_kinds::DatasetUuid,
53-
pool_id: Uuid,
55+
pool_id: ZpoolUuid,
5456
addr: SocketAddrV6,
5557
) -> Self {
5658
Self {
5759
identity: CrucibleDatasetIdentity::new(id),
5860
time_deleted: None,
5961
rcgen: Generation::new(),
60-
pool_id,
62+
pool_id: pool_id.into(),
6163
ip: addr.ip().into(),
6264
port: addr.port().into(),
6365
size_used: 0,
@@ -80,6 +82,10 @@ impl CrucibleDataset {
8082
pub fn no_provision(&self) -> bool {
8183
self.no_provision
8284
}
85+
86+
pub fn pool_id(&self) -> ZpoolUuid {
87+
self.pool_id.into()
88+
}
8389
}
8490

8591
// Datasets contain regions

nexus/db-model/src/inventory.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ use omicron_common::update::OmicronZoneManifestSource;
8080
use omicron_common::zpool_name::ZpoolName;
8181
use omicron_uuid_kinds::DatasetKind;
8282
use omicron_uuid_kinds::DatasetUuid;
83-
use omicron_uuid_kinds::GenericUuid;
8483
use omicron_uuid_kinds::InternalZpoolKind;
8584
use omicron_uuid_kinds::MupdateKind;
8685
use omicron_uuid_kinds::MupdateOverrideKind;
@@ -91,7 +90,6 @@ use omicron_uuid_kinds::PhysicalDiskUuid;
9190
use omicron_uuid_kinds::SledKind;
9291
use omicron_uuid_kinds::SledUuid;
9392
use omicron_uuid_kinds::ZpoolKind;
94-
use omicron_uuid_kinds::ZpoolUuid;
9593
use omicron_uuid_kinds::{CollectionKind, OmicronZoneKind};
9694
use omicron_uuid_kinds::{CollectionUuid, OmicronZoneUuid};
9795
use std::collections::BTreeSet;
@@ -2036,7 +2034,7 @@ impl From<InvNvmeDiskFirmware>
20362034
pub struct InvZpool {
20372035
pub inv_collection_id: DbTypedUuid<CollectionKind>,
20382036
pub time_collected: DateTime<Utc>,
2039-
pub id: Uuid,
2037+
pub id: DbTypedUuid<ZpoolKind>,
20402038
pub sled_id: DbTypedUuid<SledKind>,
20412039
pub total_size: ByteCount,
20422040
}
@@ -2050,7 +2048,7 @@ impl InvZpool {
20502048
Self {
20512049
inv_collection_id: inv_collection_id.into(),
20522050
time_collected: zpool.time_collected,
2053-
id: zpool.id.into_untyped_uuid(),
2051+
id: zpool.id.into(),
20542052
sled_id: sled_id.into(),
20552053
total_size: zpool.total_size.into(),
20562054
}
@@ -2061,7 +2059,7 @@ impl From<InvZpool> for nexus_types::inventory::Zpool {
20612059
fn from(pool: InvZpool) -> Self {
20622060
Self {
20632061
time_collected: pool.time_collected,
2064-
id: ZpoolUuid::from_untyped_uuid(pool.id),
2062+
id: pool.id.into(),
20652063
total_size: *pool.total_size,
20662064
}
20672065
}

nexus/db-model/src/zpool.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ use omicron_uuid_kinds::PhysicalDiskKind;
1313
use omicron_uuid_kinds::PhysicalDiskUuid;
1414
use omicron_uuid_kinds::SledKind;
1515
use omicron_uuid_kinds::SledUuid;
16-
use uuid::Uuid;
16+
use omicron_uuid_kinds::ZpoolKind;
17+
use omicron_uuid_kinds::ZpoolUuid;
1718

1819
/// Database representation of a Pool.
1920
///
2021
/// A zpool represents a ZFS storage pool, allocated on a single
2122
/// physical sled.
2223
#[derive(Queryable, Insertable, Debug, Clone, Selectable, Asset)]
2324
#[diesel(table_name = zpool)]
25+
#[asset(uuid_kind = ZpoolKind)]
2426
pub struct Zpool {
2527
#[diesel(embed)]
2628
identity: ZpoolIdentity,
@@ -50,7 +52,7 @@ pub struct Zpool {
5052

5153
impl Zpool {
5254
pub fn new(
53-
id: Uuid,
55+
id: ZpoolUuid,
5456
sled_id: SledUuid,
5557
physical_disk_id: PhysicalDiskUuid,
5658
control_plane_storage_buffer: ByteCount,
@@ -83,7 +85,7 @@ impl Zpool {
8385
}
8486

8587
impl DatastoreCollectionConfig<CrucibleDataset> for Zpool {
86-
type CollectionId = Uuid;
88+
type CollectionId = DbTypedUuid<ZpoolKind>;
8789
type GenerationNumberColumn = zpool::dsl::rcgen;
8890
type CollectionTimeDeletedColumn = zpool::dsl::time_deleted;
8991
type CollectionIdColumn = crucible_dataset::dsl::pool_id;

0 commit comments

Comments
 (0)