Skip to content

Commit 07a3a50

Browse files
authored
[reconfigurator] Executor internal cleanup around iterators (#7722)
Builds on #7713, and is followup from #7713 (comment). In #7652 I changed all the executor substeps to take iterators instead of `&BTreeMap` references that no longer existed, but that introduced a weird split where the top-level caller had to filter the blueprint down to just the items that the inner functions expected. @smklein pointed out one place where the inner code was being extra defensive, which was just more confusing than anything. This PR removes that split: the top-level executor now always passes a full `&Blueprint` down, and the inner modules are responsible for doing their own filtering as appropriate. To easy testing, I kept the versions that take an iterator of already-filtered items as private `*_impl` functions that the new functions-that-take-a-full-`Blueprint` themselves call too.
1 parent 2a2c407 commit 07a3a50

File tree

6 files changed

+140
-81
lines changed

6 files changed

+140
-81
lines changed

nexus/reconfigurator/execution/src/clickhouse.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use futures::future::Either;
2222
use futures::stream::FuturesUnordered;
2323
use futures::stream::StreamExt;
2424
use nexus_db_queries::context::OpContext;
25+
use nexus_types::deployment::Blueprint;
2526
use nexus_types::deployment::BlueprintZoneConfig;
27+
use nexus_types::deployment::BlueprintZoneDisposition;
2628
use nexus_types::deployment::ClickhouseClusterConfig;
2729
use omicron_common::address::CLICKHOUSE_ADMIN_PORT;
2830
use omicron_uuid_kinds::OmicronZoneUuid;
@@ -38,7 +40,20 @@ use std::str::FromStr;
3840

3941
const CLICKHOUSE_DATA_DIR: &str = "/data";
4042

41-
pub(crate) async fn deploy_nodes<'a, I>(
43+
pub(crate) async fn deploy_nodes(
44+
opctx: &OpContext,
45+
blueprint: &Blueprint,
46+
clickhouse_cluster_config: &ClickhouseClusterConfig,
47+
) -> Result<(), Vec<anyhow::Error>> {
48+
deploy_nodes_impl(
49+
opctx,
50+
blueprint.all_omicron_zones(BlueprintZoneDisposition::any),
51+
clickhouse_cluster_config,
52+
)
53+
.await
54+
}
55+
56+
async fn deploy_nodes_impl<'a, I>(
4257
opctx: &OpContext,
4358
zones: I,
4459
clickhouse_cluster_config: &ClickhouseClusterConfig,
@@ -186,7 +201,20 @@ where
186201
Ok(())
187202
}
188203

189-
pub(crate) async fn deploy_single_node<'a, I>(
204+
pub(crate) async fn deploy_single_node(
205+
opctx: &OpContext,
206+
blueprint: &Blueprint,
207+
) -> Result<(), anyhow::Error> {
208+
deploy_single_node_impl(
209+
opctx,
210+
blueprint
211+
.all_omicron_zones(BlueprintZoneDisposition::is_in_service)
212+
.filter(|(_, z)| z.zone_type.is_clickhouse()),
213+
)
214+
.await
215+
}
216+
217+
async fn deploy_single_node_impl<'a, I>(
190218
opctx: &OpContext,
191219
mut zones: I,
192220
) -> Result<(), anyhow::Error>
@@ -330,7 +358,6 @@ mod test {
330358
use clickhouse_admin_types::ServerId;
331359
use nexus_sled_agent_shared::inventory::OmicronZoneDataset;
332360
use nexus_types::deployment::BlueprintZoneConfig;
333-
use nexus_types::deployment::BlueprintZoneDisposition;
334361
use nexus_types::deployment::BlueprintZoneImageSource;
335362
use nexus_types::deployment::BlueprintZoneType;
336363
use nexus_types::deployment::blueprint_zone_type;

nexus/reconfigurator/execution/src/datasets.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use anyhow::anyhow;
1111
use futures::StreamExt;
1212
use futures::stream;
1313
use nexus_db_queries::context::OpContext;
14+
use nexus_types::deployment::Blueprint;
1415
use nexus_types::deployment::BlueprintDatasetsConfig;
1516
use omicron_common::disk::DatasetsConfig;
1617
use omicron_uuid_kinds::GenericUuid;
@@ -22,7 +23,23 @@ use std::collections::BTreeMap;
2223

2324
/// Idempotently ensures that the specified datasets are deployed to the
2425
/// corresponding sleds
25-
pub(crate) async fn deploy_datasets<'a, I>(
26+
pub(crate) async fn deploy_datasets(
27+
opctx: &OpContext,
28+
sleds_by_id: &BTreeMap<SledUuid, Sled>,
29+
blueprint: &Blueprint,
30+
) -> Result<(), Vec<anyhow::Error>> {
31+
deploy_datasets_impl(
32+
opctx,
33+
sleds_by_id,
34+
blueprint
35+
.sleds
36+
.iter()
37+
.map(|(sled_id, sled)| (*sled_id, &sled.datasets_config)),
38+
)
39+
.await
40+
}
41+
42+
async fn deploy_datasets_impl<'a, I>(
2643
opctx: &OpContext,
2744
sleds_by_id: &BTreeMap<SledUuid, Sled>,
2845
sled_configs: I,
@@ -184,7 +201,7 @@ mod tests {
184201
let sled_configs = [(sim_sled_agent.id, &datasets_config)];
185202

186203
// Give the simulated sled agent a configuration to deploy
187-
deploy_datasets(&opctx, &sleds_by_id, sled_configs.into_iter())
204+
deploy_datasets_impl(&opctx, &sleds_by_id, sled_configs.into_iter())
188205
.await
189206
.expect("Deploying datasets should have succeeded");
190207

nexus/reconfigurator/execution/src/lib.rs

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ use internal_dns_resolver::Resolver;
1111
use nexus_db_queries::context::OpContext;
1212
use nexus_db_queries::db::DataStore;
1313
use nexus_types::deployment::Blueprint;
14-
use nexus_types::deployment::BlueprintPhysicalDiskDisposition;
15-
use nexus_types::deployment::BlueprintZoneDisposition;
1614
use nexus_types::deployment::SledFilter;
1715
use nexus_types::deployment::execution::*;
18-
use nexus_types::external_api::views::SledState;
1916
use nexus_types::identity::Asset;
2017
use omicron_uuid_kinds::GenericUuid;
2118
use omicron_uuid_kinds::OmicronZoneUuid;
@@ -246,7 +243,7 @@ fn register_zone_external_networking_step<'a>(
246243
move |_cx| async move {
247244
datastore
248245
.blueprint_ensure_external_networking_resources(
249-
&opctx, blueprint,
246+
opctx, blueprint,
250247
)
251248
.await
252249
.map_err(|err| anyhow!(err))?;
@@ -271,7 +268,7 @@ fn register_support_bundle_failure_step<'a>(
271268
an expunged disk or sled",
272269
move |_cx| async move {
273270
let res = match datastore
274-
.support_bundle_fail_expunged(&opctx, blueprint, nexus_id)
271+
.support_bundle_fail_expunged(opctx, blueprint, nexus_id)
275272
.await
276273
{
277274
Ok(report) => StepSuccess::new(())
@@ -298,7 +295,7 @@ fn register_sled_list_step<'a>(
298295
"Fetch sled list",
299296
move |_cx| async move {
300297
let sleds_by_id: BTreeMap<SledUuid, _> = datastore
301-
.sled_list_all_batched(&opctx, SledFilter::InService)
298+
.sled_list_all_batched(opctx, SledFilter::InService)
302299
.await
303300
.context("listing all sleds")?
304301
.into_iter()
@@ -329,7 +326,7 @@ fn register_deploy_disks_step<'a>(
329326
move |cx| async move {
330327
let sleds_by_id = sleds.into_value(cx.token()).await;
331328
let res = omicron_physical_disks::deploy_disks(
332-
&opctx,
329+
opctx,
333330
&sleds_by_id,
334331
blueprint
335332
.sleds
@@ -356,15 +353,10 @@ fn register_deploy_datasets_step<'a>(
356353
"Deploy datasets",
357354
move |cx| async move {
358355
let sleds_by_id = sleds.into_value(cx.token()).await;
359-
let res = datasets::deploy_datasets(
360-
&opctx,
361-
&sleds_by_id,
362-
blueprint.sleds.iter().map(|(sled_id, sled)| {
363-
(*sled_id, &sled.datasets_config)
364-
}),
365-
)
366-
.await
367-
.map_err(merge_anyhow_list);
356+
let res =
357+
datasets::deploy_datasets(opctx, &sleds_by_id, blueprint)
358+
.await
359+
.map_err(merge_anyhow_list);
368360
Ok(map_err_to_step_warning(res))
369361
},
370362
)
@@ -384,7 +376,7 @@ fn register_deploy_zones_step<'a>(
384376
move |cx| async move {
385377
let sleds_by_id = sleds.into_value(cx.token()).await;
386378
let res = omicron_zones::deploy_zones(
387-
&opctx,
379+
opctx,
388380
&sleds_by_id,
389381
blueprint
390382
.sleds
@@ -418,9 +410,9 @@ fn register_plumb_firewall_rules_step<'a>(
418410
move |_cx| async move {
419411
let res = nexus_networking::plumb_service_firewall_rules(
420412
datastore,
421-
&opctx,
413+
opctx,
422414
&[],
423-
&opctx,
415+
opctx,
424416
&opctx.log,
425417
)
426418
.await
@@ -448,7 +440,7 @@ fn register_dns_records_step<'a>(
448440
let sleds_by_id = sleds.into_value(cx.token()).await;
449441

450442
let res = dns::deploy_dns(
451-
&opctx,
443+
opctx,
452444
datastore,
453445
nexus_id.to_string(),
454446
blueprint,
@@ -476,12 +468,7 @@ fn register_cleanup_expunged_zones_step<'a>(
476468
"Cleanup expunged zones",
477469
move |_cx| async move {
478470
let res = omicron_zones::clean_up_expunged_zones(
479-
&opctx,
480-
datastore,
481-
resolver,
482-
blueprint.all_omicron_zones(
483-
BlueprintZoneDisposition::is_ready_for_cleanup,
484-
),
471+
opctx, datastore, resolver, blueprint,
485472
)
486473
.await
487474
.map_err(merge_anyhow_list);
@@ -502,19 +489,10 @@ fn register_decommission_sleds_step<'a>(
502489
ExecutionStepId::Cleanup,
503490
"Decommission sleds",
504491
move |_cx| async move {
505-
let res = sled_state::decommission_sleds(
506-
&opctx,
507-
datastore,
508-
blueprint
509-
.sleds
510-
.iter()
511-
.filter(|(_, sled)| {
512-
sled.state == SledState::Decommissioned
513-
})
514-
.map(|(&sled_id, _)| sled_id),
515-
)
516-
.await
517-
.map_err(merge_anyhow_list);
492+
let res =
493+
sled_state::decommission_sleds(opctx, datastore, blueprint)
494+
.await
495+
.map_err(merge_anyhow_list);
518496
Ok(map_err_to_step_warning(res))
519497
},
520498
)
@@ -533,11 +511,7 @@ fn register_decommission_disks_step<'a>(
533511
"Decommission expunged disks",
534512
move |_cx| async move {
535513
let res = omicron_physical_disks::decommission_expunged_disks(
536-
&opctx,
537-
datastore,
538-
blueprint
539-
.all_omicron_disks(BlueprintPhysicalDiskDisposition::is_ready_for_cleanup)
540-
.map(|(sled_id, config)| (sled_id, config.id)),
514+
opctx, datastore, blueprint,
541515
)
542516
.await
543517
.map_err(merge_anyhow_list);
@@ -561,9 +535,8 @@ fn register_deploy_clickhouse_cluster_nodes_step<'a>(
561535
&blueprint.clickhouse_cluster_config
562536
{
563537
let res = clickhouse::deploy_nodes(
564-
&opctx,
565-
blueprint
566-
.all_omicron_zones(BlueprintZoneDisposition::any),
538+
opctx,
539+
blueprint,
567540
&clickhouse_cluster_config,
568541
)
569542
.await
@@ -587,15 +560,8 @@ fn register_deploy_clickhouse_single_node_step<'a>(
587560
ExecutionStepId::Ensure,
588561
"Deploy single-node clickhouse cluster",
589562
move |_cx| async move {
590-
let res = clickhouse::deploy_single_node(
591-
&opctx,
592-
blueprint
593-
.all_omicron_zones(
594-
BlueprintZoneDisposition::is_in_service,
595-
)
596-
.filter(|(_, z)| z.zone_type.is_clickhouse()),
597-
)
598-
.await;
563+
let res =
564+
clickhouse::deploy_single_node(opctx, blueprint).await;
599565
Ok(map_err_to_step_warning(res))
600566
},
601567
)
@@ -620,7 +586,7 @@ fn register_reassign_sagas_step<'a>(
620586
// affect anything else.
621587
let sec_id = nexus_db_model::SecId::from(nexus_id);
622588
let reassigned = sagas::reassign_sagas_from_expunged(
623-
&opctx, datastore, blueprint, sec_id,
589+
opctx, datastore, blueprint, sec_id,
624590
)
625591
.await
626592
.context("failed to re-assign sagas");
@@ -649,7 +615,7 @@ fn register_cockroachdb_settings_step<'a>(
649615
"Ensure CockroachDB settings",
650616
move |_cx| async move {
651617
let res =
652-
cockroachdb::ensure_settings(&opctx, datastore, blueprint)
618+
cockroachdb::ensure_settings(opctx, datastore, blueprint)
653619
.await;
654620
Ok(map_err_to_step_warning(res))
655621
},

nexus/reconfigurator/execution/src/omicron_physical_disks.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use futures::StreamExt;
1111
use futures::stream;
1212
use nexus_db_queries::context::OpContext;
1313
use nexus_db_queries::db::DataStore;
14+
use nexus_types::deployment::Blueprint;
15+
use nexus_types::deployment::BlueprintPhysicalDiskDisposition;
1416
use nexus_types::deployment::BlueprintPhysicalDisksConfig;
1517
use omicron_uuid_kinds::GenericUuid;
1618
use omicron_uuid_kinds::PhysicalDiskUuid;
@@ -104,6 +106,23 @@ where
104106

105107
/// Decommissions all disks which are currently expunged.
106108
pub(crate) async fn decommission_expunged_disks(
109+
opctx: &OpContext,
110+
datastore: &DataStore,
111+
blueprint: &Blueprint,
112+
) -> Result<(), Vec<anyhow::Error>> {
113+
decommission_expunged_disks_impl(
114+
opctx,
115+
datastore,
116+
blueprint
117+
.all_omicron_disks(
118+
BlueprintPhysicalDiskDisposition::is_ready_for_cleanup,
119+
)
120+
.map(|(sled_id, config)| (sled_id, config.id)),
121+
)
122+
.await
123+
}
124+
125+
async fn decommission_expunged_disks_impl(
107126
opctx: &OpContext,
108127
datastore: &DataStore,
109128
expunged_disks: impl Iterator<Item = (SledUuid, PhysicalDiskUuid)>,
@@ -642,7 +661,7 @@ mod test {
642661
assert_eq!(d.disk_state, PhysicalDiskState::Active);
643662
assert_eq!(d.disk_policy, PhysicalDiskPolicy::InService);
644663

645-
super::decommission_expunged_disks(
664+
super::decommission_expunged_disks_impl(
646665
&opctx,
647666
&datastore,
648667
[(sled_id, disk_to_decommission)].into_iter(),

0 commit comments

Comments
 (0)