From a491c6388f09973003975d766ca8bdf0c2291bb4 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Tue, 14 Jan 2025 11:44:46 +0100 Subject: [PATCH] Automatic key migration --- crates/common/src/manager/boot.rs | 17 +++++++++++++++-- crates/store/src/dispatch/lookup.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/crates/common/src/manager/boot.rs b/crates/common/src/manager/boot.rs index b0fd1b42..dec4e16f 100644 --- a/crates/common/src/manager/boot.rs +++ b/crates/common/src/manager/boot.rs @@ -229,7 +229,8 @@ impl BootManager { } // Download Spam filter rules if missing - let is_pre_0_11 = match config.value("version.spam-filter").and_then(|v| { + // TODO remove this check in 1.0 + let mut update_webadmin = match config.value("version.spam-filter").and_then(|v| { if !v.is_empty() { Some(Semver::try_from(v)) } else { @@ -311,6 +312,18 @@ impl BootManager { } }; + // TODO remove key migration in 1.0 + for (old_key, new_key) in [ + ("lookup.default.hostname", "server.hostname"), + ("lookup.default.domain", "report.domain"), + ] { + if let (Some(old_value), None) = (config.value(old_key), config.value(new_key)) + { + insert_keys.push(ConfigKey::from((new_key, old_value))); + update_webadmin = true; + } + } + // Download webadmin if missing if let Some(blob_store) = config .value("storage.blob") @@ -381,7 +394,7 @@ impl BootManager { ); // Webadmin auto-update - if is_pre_0_11 + if update_webadmin || config .property_or_default::("webadmin.auto-update", "false") .unwrap_or_default() diff --git a/crates/store/src/dispatch/lookup.rs b/crates/store/src/dispatch/lookup.rs index fce63997..798d4933 100644 --- a/crates/store/src/dispatch/lookup.rs +++ b/crates/store/src/dispatch/lookup.rs @@ -278,12 +278,35 @@ impl InMemoryStore { match self { InMemoryStore::Store(store) => { let key = KeyValue::<()>::build_key(prefix, key); - let lock_expiry = store + let lock_expiry = match store .get_value::(ValueKey::from(ValueClass::InMemory(InMemoryClass::Key( key.clone(), )))) .await - .caused_by(trc::location!())?; + { + Ok(lock_expiry) => lock_expiry, + Err(err) + if err.matches(trc::EventType::Store(trc::StoreEvent::DataCorruption)) => + { + // TODO remove in 1.0 + let mut batch = BatchBuilder::new(); + batch.ops.push(Operation::Value { + class: ValueClass::InMemory(InMemoryClass::Key(key.clone())), + op: ValueOp::Clear, + }); + store + .write(batch.build()) + .await + .caused_by(trc::location!())?; + None + } + Err(err) => { + return Err(err + .details("Failed to read lock.") + .caused_by(trc::location!())); + } + }; + let now = now(); if lock_expiry.is_some_and(|expiry| expiry > now) { return Ok(false);