Skip to content

Commit

Permalink
nits from self-review
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed May 24, 2024
1 parent cbe475c commit 7df2d80
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
8 changes: 7 additions & 1 deletion nexus/db-queries/src/db/datastore/cockroachdb_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ impl DataStore {
// below in `test_state_fingerprint`).
.sql(" ELSE NULL END")
.bind::<sql_types::Text, _>(state_fingerprint)
.bind::<sql_types::Text, _>(value)
.bind::<sql_types::Text, _>(value.clone())
.query::<()>()
.execute_async(&*conn)
.await
.map_err(|err| {
public_error_from_diesel(err, ErrorHandler::Server)
})?;
info!(
opctx.log,
"set cockroachdb setting";
"setting" => setting,
"value" => &value,
);
Ok(())
}
}
Expand Down
9 changes: 1 addition & 8 deletions nexus/reconfigurator/execution/src/cockroachdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use anyhow::Context;
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db::DataStore;
use nexus_types::deployment::Blueprint;
use slog::info;

pub(crate) async fn ensure_settings(
opctx: &OpContext,
Expand All @@ -23,16 +22,10 @@ pub(crate) async fn ensure_settings(
opctx,
blueprint.cockroachdb_fingerprint.clone(),
"cluster.preserve_downgrade_option",
value.clone(),
value,
)
.await
.context("failed to set cluster.preserve_downgrade_option")?;
info!(
opctx.log,
"set cockroachdb setting";
"setting" => "cluster.preserve_downgrade_option",
"value" => &value,
);
}
Ok(())
}
Expand Down
12 changes: 10 additions & 2 deletions nexus/reconfigurator/planning/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ impl<'a> Planner<'a> {
}
}
// The current version is unknown to us; we are likely in the middle
// of an upgrade and shouldn't change _any_ settings.
Err(_) => return,
// of an cluster upgrade.
Err(_) => CockroachDbPreserveDowngrade::DoNotModify,
};
self.blueprint.cockroachdb_preserve_downgrade(value);
info!(
Expand All @@ -545,6 +545,14 @@ impl<'a> Planner<'a> {
"setting" => "cluster.preserve_downgrade_option",
"value" => ?value,
);

// Hey! Listen!
//
// If we need to manage more CockroachDB settings, we should ensure
// that no settings will be modified if we don't recognize the current
// cluster version -- we're likely in the middle of an upgrade!
//
// https://www.cockroachlabs.com/docs/stable/cluster-settings#change-a-cluster-setting
}
}

Expand Down
16 changes: 13 additions & 3 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use omicron_common::api::external::BgpPeer;
use omicron_common::api::external::DataPageParams;
use omicron_common::api::external::Error;
use omicron_common::api::external::IdentityMetadataCreateParams;
use omicron_common::api::external::InternalContext;
use omicron_common::api::external::ListResultVec;
use omicron_common::api::external::LookupResult;
use omicron_common::api::external::Name;
Expand Down Expand Up @@ -232,16 +233,25 @@ impl super::Nexus {
// 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?;
let cockroachdb_settings = self
.datastore()
.cockroachdb_settings(opctx)
.await
.internal_context(
"fetching cockroachdb settings for rack initialization",
)?;
self.datastore()
.cockroachdb_setting_set_string(
opctx,
cockroachdb_settings.state_fingerprint.clone(),
"cluster.preserve_downgrade_option",
CockroachDbClusterVersion::NEWLY_INITIALIZED.to_string(),
)
.await?;
.await
.internal_context(
"setting `cluster.preserve_downgrade_option` \
for rack initialization",
)?;
blueprint.cockroachdb_fingerprint =
cockroachdb_settings.state_fingerprint;
blueprint.cockroachdb_setting_preserve_downgrade =
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/rack_setup/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ pub(crate) fn build_initial_blueprint_from_sled_configs(
// generation of 1. Nexus will bump this up when it updates external DNS
// (including creating the recovery silo).
external_dns_version: Generation::new(),
// Avoid making decisions about CockroachDB settings before Nexus is up.
// Nexus will fill in the CockroachDB values during initialization.
cockroachdb_fingerprint: String::new(),
cockroachdb_setting_preserve_downgrade:
CockroachDbPreserveDowngrade::DoNotModify,
Expand Down

0 comments on commit 7df2d80

Please sign in to comment.