Automatic key migration

This commit is contained in:
mdecimus
2025-01-14 11:44:46 +01:00
parent 76c53af46b
commit a491c6388f
2 changed files with 40 additions and 4 deletions

View File

@@ -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::<bool>("webadmin.auto-update", "false")
.unwrap_or_default()

View File

@@ -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::<u64>(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);