From aa252b26b1c2faf10a121c44f0b8956c688821e0 Mon Sep 17 00:00:00 2001 From: iliana etaoin Date: Thu, 23 May 2024 01:36:48 +0000 Subject: [PATCH] set preserve downgrade option during rack init --- .../execution/src/cockroachdb.rs | 72 +++++-------------- nexus/reconfigurator/execution/src/dns.rs | 5 +- nexus/src/app/rack.rs | 19 +++++ 3 files changed, 41 insertions(+), 55 deletions(-) diff --git a/nexus/reconfigurator/execution/src/cockroachdb.rs b/nexus/reconfigurator/execution/src/cockroachdb.rs index 87b2f5ccbb..98aae65648 100644 --- a/nexus/reconfigurator/execution/src/cockroachdb.rs +++ b/nexus/reconfigurator/execution/src/cockroachdb.rs @@ -44,9 +44,7 @@ mod test { use nexus_db_queries::authn; use nexus_db_queries::authz; use nexus_test_utils_macros::nexus_test; - use nexus_types::deployment::BlueprintTarget; use nexus_types::deployment::CockroachDbClusterVersion; - use nexus_types::deployment::CockroachDbPreserveDowngrade; use std::sync::Arc; type ControlPlaneTestContext = @@ -77,10 +75,24 @@ mod test { .await .expect("failed to get blueprint from datastore"); eprintln!("blueprint: {}", blueprint.display()); - assert!(blueprint.cockroachdb_fingerprint.is_empty()); + // The initial blueprint should already have these filled in. + assert_eq!( + blueprint.cockroachdb_fingerprint, + settings.state_fingerprint + ); assert_eq!( blueprint.cockroachdb_setting_preserve_downgrade, - CockroachDbPreserveDowngrade::DoNotModify + CockroachDbClusterVersion::NEWLY_INITIALIZED.into() + ); + // The cluster version, preserve downgrade setting, and + // `NEWLY_INITIALIZED` should all match. + assert_eq!( + settings.version, + CockroachDbClusterVersion::NEWLY_INITIALIZED.to_string() + ); + assert_eq!( + settings.preserve_downgrade, + CockroachDbClusterVersion::NEWLY_INITIALIZED.to_string() ); // Execute the initial blueprint. let overrides = Overridables::for_test(cptestctx); @@ -102,55 +114,7 @@ mod test { .expect("failed to get cockroachdb settings") ); - // Create and add a new blueprint (this will pull the current - // CockroachDB settings and run the planner based on it). - let blueprint2 = nexus - .blueprint_create_regenerate(&opctx) - .await - .expect("failed to regenerate blueprint"); - eprintln!("blueprint: {}", blueprint2.display()); - // The new blueprint should have a matching fingerprint, and a correct - // non-empty value for the preserve downgrade option. - assert_eq!( - blueprint2.cockroachdb_fingerprint, - settings.state_fingerprint - ); - assert_eq!( - blueprint2.cockroachdb_setting_preserve_downgrade, - CockroachDbClusterVersion::NEWLY_INITIALIZED.into(), - ); - // Set the new blueprint as the target and execute it. - datastore - .blueprint_target_set_current( - &opctx, - BlueprintTarget { - target_id: blueprint2.id, - enabled: false, - time_made_target: chrono::Utc::now(), - }, - ) - .await - .expect("failed to set blueprint as target"); - crate::realize_blueprint_with_overrides( - &opctx, - datastore, - &blueprint2, - "test-suite", - &overrides, - ) - .await - .expect("failed to execute new blueprint"); - // Fetch the new CockroachDB settings. - let settings2 = datastore - .cockroachdb_settings(&opctx) - .await - .expect("failed to get cockroachdb settings"); - // The cluster version should not have changed. - assert_eq!(settings.version, settings2.version); - // The current "preserve downgrade option" setting should be set. - assert_eq!( - settings2.preserve_downgrade, - CockroachDbClusterVersion::NEWLY_INITIALIZED.to_string() - ); + // TODO(iliana): when we upgrade to v22.2, test an actual cluster + // upgrade when crdb-seed is run with the old CockroachDB } } diff --git a/nexus/reconfigurator/execution/src/dns.rs b/nexus/reconfigurator/execution/src/dns.rs index bc2c059f52..ec48a35cbe 100644 --- a/nexus/reconfigurator/execution/src/dns.rs +++ b/nexus/reconfigurator/execution/src/dns.rs @@ -1153,11 +1153,14 @@ mod test { .expect("fetching initial external DNS"); // Fetch the initial blueprint installed during rack initialization. - let (_blueprint_target, blueprint) = datastore + let (_blueprint_target, mut blueprint) = datastore .blueprint_target_get_current_full(&opctx) .await .expect("failed to read current target blueprint"); eprintln!("blueprint: {}", blueprint.display()); + // Override the CockroachDB settings so that we don't try to set them. + blueprint.cockroachdb_setting_preserve_downgrade = + CockroachDbPreserveDowngrade::DoNotModify; // Now, execute the initial blueprint. let overrides = Overridables::for_test(cptestctx); diff --git a/nexus/src/app/rack.rs b/nexus/src/app/rack.rs index c766446f38..441f9f4d8d 100644 --- a/nexus/src/app/rack.rs +++ b/nexus/src/app/rack.rs @@ -24,6 +24,7 @@ use nexus_reconfigurator_execution::silo_dns_name; use nexus_types::deployment::blueprint_zone_type; use nexus_types::deployment::BlueprintZoneFilter; use nexus_types::deployment::BlueprintZoneType; +use nexus_types::deployment::CockroachDbClusterVersion; use nexus_types::deployment::SledFilter; use nexus_types::external_api::params::Address; use nexus_types::external_api::params::AddressConfig; @@ -228,6 +229,24 @@ impl super::Nexus { let mut blueprint = request.blueprint; blueprint.external_dns_version = blueprint.external_dns_version.next(); + // Fill in the CockroachDB metadata for the initial blueprint, and set + // the `cluster.preserve_downgrade_option` setting ahead of blueprint + // execution. + let cockroachdb_settings = + self.datastore().cockroachdb_settings(opctx).await?; + self.datastore() + .cockroachdb_setting_set_string( + opctx, + cockroachdb_settings.state_fingerprint.clone(), + "cluster.preserve_downgrade_option", + CockroachDbClusterVersion::NEWLY_INITIALIZED.to_string(), + ) + .await?; + blueprint.cockroachdb_fingerprint = + cockroachdb_settings.state_fingerprint; + blueprint.cockroachdb_setting_preserve_downgrade = + CockroachDbClusterVersion::NEWLY_INITIALIZED.into(); + // Administrators of the Recovery Silo are automatically made // administrators of the Fleet. let mapped_fleet_roles = BTreeMap::from([(