From 6692efa446bc8f35cc9783bbb783a7ef244842e1 Mon Sep 17 00:00:00 2001 From: Tim Bruijnzeels Date: Fri, 9 Oct 2020 10:59:16 +0200 Subject: [PATCH] Update KeyStoreVersion to have 0.8.0-rc1. --- src/commons/eventsourcing/store.rs | 11 +++++++++-- src/daemon/http/server.rs | 10 +++++++++- src/upgrades/mod.rs | 20 +++++++++++++------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/commons/eventsourcing/store.rs b/src/commons/eventsourcing/store.rs index a28f0014..e9ce4ce3 100644 --- a/src/commons/eventsourcing/store.rs +++ b/src/commons/eventsourcing/store.rs @@ -49,11 +49,18 @@ impl Default for StoredValueInfo { #[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] // Do NOT EVER change the order.. this is used to check whether migrations are needed +#[allow(non_camel_case_types)] pub enum KeyStoreVersion { Pre0_6, V0_6, V0_7, - V0_8, + V0_8_0_RC1, +} + +impl KeyStoreVersion { + pub fn current() -> Self { + KeyStoreVersion::V0_8_0_RC1 + } } //------------ CommandKey ---------------------------------------------------- @@ -164,7 +171,7 @@ where }; if !existed { - store.set_version(&KeyStoreVersion::V0_8)?; + store.set_version(&KeyStoreVersion::current())?; } Ok(store) diff --git a/src/daemon/http/server.rs b/src/daemon/http/server.rs index 49302a8f..68e6b9f2 100644 --- a/src/daemon/http/server.rs +++ b/src/daemon/http/server.rs @@ -35,7 +35,7 @@ use crate::daemon::config::CONFIG; use crate::daemon::http::statics::statics; use crate::daemon::http::{tls, tls_keys, HttpResponse, Request, RequestPath, RoutingResult}; use crate::daemon::krillserver::KrillServer; -use crate::upgrades::{post_start_upgrade, pre_start_upgrade}; +use crate::upgrades::{post_start_upgrade, pre_start_upgrade, update_storage_version}; //------------ State ----------------------------------------------------- @@ -76,14 +76,22 @@ pub async fn start() -> Result<(), Error> { // Create the server, this will create the necessary data sub-directories if needed let krill = KrillServer::build().await?; + // Perform upgrades that need a running krill server (e.g. clean up ROAs) post_start_upgrade(&CONFIG.data_dir, &krill) .map_err(|e| Error::Custom(format!("Could not upgrade Krill: {}", e))) .await?; + // Update the version identifiers for the storage dirs + update_storage_version(&CONFIG.data_dir) + .map_err(|e| Error::Custom(format!("Could not upgrade Krill: {}", e))) + .await?; + + // If archiving is enabled, now would be a good time to clean things up if let Some(days) = CONFIG.archive_threshold_days { krill.archive_old_commands(days).await?; } + // If the operator wanted to do the upgrade only, now is a good time to report success and stop if env::var(KRILL_ENV_UPGRADE_ONLY).is_ok() { println!("Krill upgrade successful"); ::std::process::exit(0); diff --git a/src/upgrades/mod.rs b/src/upgrades/mod.rs index 69bdc48a..458f39ba 100644 --- a/src/upgrades/mod.rs +++ b/src/upgrades/mod.rs @@ -111,22 +111,28 @@ pub fn pre_start_upgrade(work_dir: &PathBuf) -> Result<(), UpgradeError> { upgrade_pre_fix_info_0_8_0(work_dir) } -/// Should be called right after the KrillServer is initiated +/// Should be called right after the KrillServer is initiated. pub async fn post_start_upgrade(work_dir: &PathBuf, server: &KrillServer) -> Result<(), UpgradeError> { - let version_0_8 = KeyStoreVersion::V0_8; + let version_0_8 = KeyStoreVersion::V0_8_0_RC1; let ca_store: AggregateStore = AggregateStore::new(work_dir, "cas")?; - let pubd_store: AggregateStore = AggregateStore::new(work_dir, "pubd")?; - if ca_store.get_version()? != version_0_8 { + if ca_store.get_version()? < version_0_8 { info!("Will clean up redundant ROAs for all CAs and update version of storage dirs"); roa_cleanup_0_8_0::roa_cleanup(server).await?; - ca_store.set_version(&version_0_8)?; - pubd_store.set_version(&version_0_8)?; - info!("Upgraded Krill to version: {}", KRILL_VERSION); } Ok(()) } +pub async fn update_storage_version(work_dir: &PathBuf) -> Result<(), UpgradeError> { + let ca_store: AggregateStore = AggregateStore::new(work_dir, "cas")?; + let pubd_store: AggregateStore = AggregateStore::new(work_dir, "pubd")?; + let current = KeyStoreVersion::current(); + ca_store.set_version(¤t)?; + pubd_store.set_version(¤t)?; + info!("Upgraded Krill to version: {}", KRILL_VERSION); + Ok(()) +} + fn upgrade_pre_0_6_0_cas_commands(work_dir: &PathBuf) -> Result<(), UpgradeError> { let pre_0_6_0_ca_commands = pre_0_6_0::UpgradeCas;