Skip to content

Commit

Permalink
set preserve downgrade option during rack init
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed May 23, 2024
1 parent 04afc26 commit aa252b2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 55 deletions.
72 changes: 18 additions & 54 deletions nexus/reconfigurator/execution/src/cockroachdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand All @@ -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
}
}
5 changes: 4 additions & 1 deletion nexus/reconfigurator/execution/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([(
Expand Down

0 comments on commit aa252b2

Please sign in to comment.