Skip to content

Commit be86cec

Browse files
authored
Use IdMaps for BlueprintPhysicalDisksConfig and BlueprintDatasetsConfig (#7352)
1 parent fbe043a commit be86cec

File tree

15 files changed

+154
-132
lines changed

15 files changed

+154
-132
lines changed

nexus/db-queries/src/db/datastore/deployment.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl DataStore {
245245
.blueprint_datasets
246246
.iter()
247247
.flat_map(|(sled_id, datasets_config)| {
248-
datasets_config.datasets.values().map(move |dataset| {
248+
datasets_config.datasets.iter().map(move |dataset| {
249249
BpOmicronDataset::new(blueprint_id, *sled_id, dataset)
250250
})
251251
})
@@ -628,7 +628,7 @@ impl DataStore {
628628
s.sled_id.into(),
629629
BlueprintPhysicalDisksConfig {
630630
generation: *s.generation,
631-
disks: Vec::new(),
631+
disks: IdMap::new(),
632632
},
633633
);
634634
bail_unless!(
@@ -672,7 +672,7 @@ impl DataStore {
672672
s.sled_id.into(),
673673
BlueprintDatasetsConfig {
674674
generation: *s.generation,
675-
datasets: BTreeMap::new(),
675+
datasets: IdMap::new(),
676676
},
677677
);
678678
bail_unless!(
@@ -839,7 +839,7 @@ impl DataStore {
839839
d.id, d.sled_id
840840
))
841841
})?;
842-
sled_disks.disks.push(d.into());
842+
sled_disks.disks.insert(d.into());
843843
}
844844
}
845845
}
@@ -883,24 +883,18 @@ impl DataStore {
883883
})?;
884884

885885
let dataset_id = d.id;
886-
sled_datasets.datasets.insert(
887-
dataset_id.into(),
888-
d.try_into().map_err(|e| {
886+
sled_datasets.datasets.insert(d.try_into().map_err(
887+
|e| {
889888
Error::internal_error(&format!(
890889
"Cannot parse dataset {}: {e}",
891890
dataset_id
892891
))
893-
})?,
894-
);
892+
},
893+
)?);
895894
}
896895
}
897896
}
898897

899-
// Sort all disks to match what blueprint builders do.
900-
for (_, disks_config) in blueprint_disks.iter_mut() {
901-
disks_config.disks.sort_unstable_by_key(|d| d.id);
902-
}
903-
904898
// Load our `ClickhouseClusterConfig` if it exists
905899
let clickhouse_cluster_config: Option<ClickhouseClusterConfig> = {
906900
use db::schema::bp_clickhouse_cluster_config::dsl;

nexus/db-queries/src/db/datastore/support_bundle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ mod test {
532532
for (sled, datasets) in &blueprint.blueprint_datasets {
533533
let pools = datasets
534534
.datasets
535-
.values()
535+
.iter()
536536
.filter_map(|dataset| {
537537
if !matches!(dataset.kind, DebugDatasetKind)
538538
|| !dataset
@@ -947,7 +947,7 @@ mod test {
947947
.values()
948948
.flat_map(|datasets_config| {
949949
let mut debug_datasets = vec![];
950-
for dataset in datasets_config.datasets.values() {
950+
for dataset in datasets_config.datasets.iter() {
951951
if matches!(dataset.kind, DebugDatasetKind)
952952
&& dataset.disposition.matches(filter)
953953
{
@@ -961,7 +961,7 @@ mod test {
961961

962962
fn expunge_dataset_for_bundle(bp: &mut Blueprint, bundle: &SupportBundle) {
963963
for datasets in bp.blueprint_datasets.values_mut() {
964-
for dataset in datasets.datasets.values_mut() {
964+
for mut dataset in datasets.datasets.iter_mut() {
965965
if dataset.id == bundle.dataset_id.into() {
966966
dataset.disposition = BlueprintDatasetDisposition::Expunged;
967967
}

nexus/reconfigurator/blippy/src/checks.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a> DatasetsBySled<'a> {
305305
let by_zpool: &mut BTreeMap<_, _> =
306306
by_sled.entry(sled_id).or_default();
307307

308-
for dataset in config.datasets.values() {
308+
for dataset in config.datasets.iter() {
309309
let by_kind: &mut BTreeMap<_, _> =
310310
by_zpool.entry(dataset.pool.id()).or_default();
311311

@@ -1209,7 +1209,7 @@ mod tests {
12091209
'outer: for (sled_id, datasets_config) in
12101210
blueprint.blueprint_datasets.iter_mut()
12111211
{
1212-
for dataset in datasets_config.datasets.values_mut() {
1212+
for mut dataset in datasets_config.datasets.iter_mut() {
12131213
if let Some(prev) =
12141214
by_kind.insert(dataset.kind.clone(), dataset.clone())
12151215
{
@@ -1269,7 +1269,7 @@ mod tests {
12691269

12701270
let mut debug_dataset = None;
12711271
let mut zoneroot_dataset = None;
1272-
for dataset in &mut datasets_config.datasets.values_mut() {
1272+
for dataset in &mut datasets_config.datasets.iter_mut() {
12731273
match &dataset.kind {
12741274
DatasetKind::Debug if debug_dataset.is_none() => {
12751275
debug_dataset = Some(dataset.clone());
@@ -1295,8 +1295,8 @@ mod tests {
12951295
assert_ne!(debug_dataset.pool, zoneroot_dataset.pool);
12961296

12971297
// Actually strip these from the blueprint.
1298-
datasets_config.datasets.retain(|&dataset_id, _| {
1299-
dataset_id != debug_dataset.id && dataset_id != zoneroot_dataset.id
1298+
datasets_config.datasets.retain(|dataset| {
1299+
dataset.id != debug_dataset.id && dataset.id != zoneroot_dataset.id
13001300
});
13011301

13021302
let expected_notes = [
@@ -1370,7 +1370,7 @@ mod tests {
13701370
assert_ne!(durable_zone.filesystem_pool, root_zone.filesystem_pool);
13711371

13721372
// Actually strip these from the blueprint.
1373-
datasets_config.datasets.retain(|_, dataset| {
1373+
datasets_config.datasets.retain(|dataset| {
13741374
let matches_durable = (dataset.pool
13751375
== *durable_zone.zone_type.durable_zpool().unwrap())
13761376
&& (dataset.kind
@@ -1543,7 +1543,7 @@ mod tests {
15431543
// Find the datasets we expect to have been orphaned.
15441544
let expected_notes = datasets_config
15451545
.datasets
1546-
.values()
1546+
.iter()
15471547
.filter_map(|dataset| {
15481548
if (dataset.pool == durable_dataset.dataset.pool_name
15491549
&& dataset.kind == durable_dataset.kind)
@@ -1591,15 +1591,16 @@ mod tests {
15911591
.iter_mut()
15921592
.next()
15931593
.expect("at least one sled");
1594-
let removed_disk = disks_config.disks.remove(0);
1594+
let first = disks_config.disks.first().unwrap().id;
1595+
let removed_disk = disks_config.disks.remove(&first).unwrap();
15951596
eprintln!("removed disk {removed_disk:?}");
15961597

15971598
let expected_notes = blueprint
15981599
.blueprint_datasets
15991600
.get(sled_id)
16001601
.unwrap()
16011602
.datasets
1602-
.values()
1603+
.iter()
16031604
.filter_map(|dataset| {
16041605
if dataset.pool.id() != removed_disk.pool_id {
16051606
return None;
@@ -1684,7 +1685,7 @@ mod tests {
16841685
for (sled_id, datasets_config) in
16851686
blueprint.blueprint_datasets.iter_mut()
16861687
{
1687-
for dataset in datasets_config.datasets.values_mut() {
1688+
for mut dataset in datasets_config.datasets.iter_mut() {
16881689
match dataset.kind {
16891690
DatasetKind::Crucible => {
16901691
let bad_address = if !cleared_crucible_addr {

nexus/reconfigurator/execution/src/omicron_physical_disks.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ mod test {
250250
fn make_disks() -> BlueprintPhysicalDisksConfig {
251251
BlueprintPhysicalDisksConfig {
252252
generation: Generation::new().next(),
253-
disks: vec![BlueprintPhysicalDiskConfig {
253+
disks: [BlueprintPhysicalDiskConfig {
254254
disposition: BlueprintPhysicalDiskDisposition::InService,
255255
identity: DiskIdentity {
256256
vendor: "test-vendor".to_string(),
@@ -259,7 +259,9 @@ mod test {
259259
},
260260
id: PhysicalDiskUuid::new_v4(),
261261
pool_id: ZpoolUuid::new_v4(),
262-
}],
262+
}]
263+
.into_iter()
264+
.collect(),
263265
}
264266
}
265267

nexus/reconfigurator/planning/src/blueprint_builder/builder.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,7 @@ impl<'a> BlueprintBuilder<'a> {
423423
.keys()
424424
.copied()
425425
.map(|sled_id| {
426-
let config = BlueprintPhysicalDisksConfig {
427-
generation: Generation::new(),
428-
disks: Vec::new(),
429-
};
426+
let config = BlueprintPhysicalDisksConfig::default();
430427
(sled_id, config)
431428
})
432429
.collect();
@@ -436,7 +433,7 @@ impl<'a> BlueprintBuilder<'a> {
436433
.map(|sled_id| {
437434
let config = BlueprintDatasetsConfig {
438435
generation: Generation::new(),
439-
datasets: BTreeMap::new(),
436+
datasets: IdMap::new(),
440437
};
441438
(sled_id, config)
442439
})
@@ -545,17 +542,14 @@ impl<'a> BlueprintBuilder<'a> {
545542
.blueprint_disks
546543
.get(sled_id)
547544
.cloned()
548-
.unwrap_or_else(|| BlueprintPhysicalDisksConfig {
549-
generation: Generation::new(),
550-
disks: Vec::new(),
551-
});
545+
.unwrap_or_else(|| BlueprintPhysicalDisksConfig::default());
552546
let datasets = parent_blueprint
553547
.blueprint_datasets
554548
.get(sled_id)
555549
.cloned()
556550
.unwrap_or_else(|| BlueprintDatasetsConfig {
557551
generation: Generation::new(),
558-
datasets: BTreeMap::new(),
552+
datasets: IdMap::new(),
559553
});
560554
let editor = SledEditor::for_existing(
561555
state,
@@ -2433,7 +2427,7 @@ pub mod test {
24332427
.get(&sled_id)
24342428
.unwrap()
24352429
.datasets
2436-
.values()
2430+
.iter()
24372431
.filter_map(|dataset_config| {
24382432
if dataset_config.disposition
24392433
== BlueprintDatasetDisposition::Expunged
@@ -2840,12 +2834,12 @@ pub mod test {
28402834
let mut output_dataset_ids = BTreeMap::new();
28412835
let mut output_ndatasets = 0;
28422836
for datasets in output.blueprint_datasets.values() {
2843-
for (id, dataset) in &datasets.datasets {
2837+
for dataset in &datasets.datasets {
28442838
let zpool_id = dataset.pool.id();
28452839
let kind = dataset.kind.clone();
28462840
let by_kind: &mut BTreeMap<_, _> =
28472841
output_dataset_ids.entry(zpool_id).or_default();
2848-
let prev = by_kind.insert(kind, *id);
2842+
let prev = by_kind.insert(kind, dataset.id);
28492843
output_ndatasets += 1;
28502844
assert!(prev.is_none());
28512845
}

nexus/reconfigurator/planning/src/blueprint_builder/internal_dns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub mod test {
134134
for (_, dataset_config) in
135135
blueprint1.blueprint_datasets.iter_mut().skip(1)
136136
{
137-
dataset_config.datasets.retain(|_id, dataset| {
137+
dataset_config.datasets.retain(|dataset| {
138138
// This is gross; once zone configs know explicit dataset IDs,
139139
// we should retain by ID instead.
140140
match &dataset.kind {

0 commit comments

Comments
 (0)