Skip to content

Commit

Permalink
Automatic key migration
Browse files Browse the repository at this point in the history
mdecimus committed Jan 14, 2025
1 parent 76c53af commit a491c63
Showing 2 changed files with 40 additions and 4 deletions.
17 changes: 15 additions & 2 deletions crates/common/src/manager/boot.rs
Original file line number Diff line number Diff line change
@@ -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()
27 changes: 25 additions & 2 deletions crates/store/src/dispatch/lookup.rs
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit a491c63

Please sign in to comment.