Retire the previous Odin's target-keyed correlations instead of refusing to start
The store the target-keyed Odin left behind holds correlations under bare target keys. The incarnation-keyed reader treated one as a substituted key and the candidate exited at start (tx-0f15abe4 on yggdrasil, 21:13Z). Those records are now skipped by the reader and retired at activation; presence history is kept under any key so the self publisher sequence continues. Verified in rust:1.95-bookworm on yggdrasil: 22 + 13 (+1 ignored) + 4 passed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
d41c744b2e
commit
27ca3b3355
2 changed files with 91 additions and 0 deletions
|
|
@ -371,6 +371,39 @@ impl CultCacheOdinTopologyStore {
|
|||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
|
||||
/// Remove every correlation not keyed by an incarnation. Those were written
|
||||
/// by the previous, target-keyed Odin; nothing reads them under this
|
||||
/// contract, and left in place `stored_snapshot` would serve them to the
|
||||
/// Verse as current. Presence records are kept whatever their key: the
|
||||
/// self publisher sequence is continued from them.
|
||||
pub fn retire_legacy_correlations(&self) -> Result<usize> {
|
||||
for _ in 0..CAS_ATTEMPTS {
|
||||
if !self.path.is_file() {
|
||||
return Ok(0);
|
||||
}
|
||||
let entries =
|
||||
SingleFileMessagePackBackingStore::new(&self.path).pull_all_read_only_snapshot()?;
|
||||
let retained = entries
|
||||
.iter()
|
||||
.filter(|entry| {
|
||||
!(entry.r#type == OdinRuntimeTopologyCorrelationRecord::TYPE
|
||||
&& IncarnationRef::parse_key(&entry.key).is_none())
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let removed = entries.len() - retained.len();
|
||||
if removed == 0 {
|
||||
return Ok(0);
|
||||
}
|
||||
if SingleFileMessagePackBackingStore::new(&self.path)
|
||||
.compare_exchange_snapshot(&entries, &retained)?
|
||||
{
|
||||
return Ok(removed);
|
||||
}
|
||||
}
|
||||
bail!("Odin topology store changed repeatedly while retiring legacy correlations")
|
||||
}
|
||||
}
|
||||
|
||||
impl OdinTopologyStore for CultCacheOdinTopologyStore {
|
||||
|
|
@ -1653,6 +1686,55 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// A store the target-keyed Odin wrote holds correlations under bare
|
||||
/// target keys. They are retired; presence history under any key stays.
|
||||
#[test]
|
||||
fn legacy_target_keyed_correlations_are_retired_and_presence_is_kept() -> Result<()> {
|
||||
let world = TestWorld::new()?;
|
||||
let service = world.service("ghostlight", Vec::new(), false)?;
|
||||
let presence = service.signed_presence(1, |_| {})?;
|
||||
let engine = world.engine(NOW);
|
||||
let correlation = engine.admit_presence("ghostlight", &presence, NOW)?;
|
||||
let store = SingleFileMessagePackBackingStore::new(&world.topology_path);
|
||||
let current = store.pull_all_read_only_snapshot()?;
|
||||
let mut with_legacy = current.clone();
|
||||
with_legacy.push(CultCacheEnvelope {
|
||||
key: "ghostlight".into(),
|
||||
r#type: OdinRuntimeTopologyCorrelationRecord::TYPE.into(),
|
||||
payload: correlation,
|
||||
stored_at: rfc3339_millis(NOW - 1_000)?,
|
||||
schema_id: Some(ODIN_RUNTIME_TOPOLOGY_CORRELATION_SCHEMA.into()),
|
||||
});
|
||||
with_legacy.push(CultCacheEnvelope {
|
||||
key: "ghostlight/legacy-signer".into(),
|
||||
r#type: GameCultRuntimePresenceHealthRecord::TYPE.into(),
|
||||
payload: presence.clone(),
|
||||
stored_at: rfc3339_millis(NOW - 1_000)?,
|
||||
schema_id: Some(GAMECULT_RUNTIME_PRESENCE_HEALTH_SCHEMA.into()),
|
||||
});
|
||||
ensure!(store.compare_exchange_snapshot(¤t, &with_legacy)?);
|
||||
|
||||
let odin_store = CultCacheOdinTopologyStore::new(&world.topology_path);
|
||||
assert_eq!(odin_store.retire_legacy_correlations()?, 1);
|
||||
assert_eq!(odin_store.retire_legacy_correlations()?, 0);
|
||||
let after = store.pull_all_read_only_snapshot()?;
|
||||
assert!(after.iter().all(|entry| {
|
||||
entry.r#type != OdinRuntimeTopologyCorrelationRecord::TYPE
|
||||
|| IncarnationRef::parse_key(&entry.key).is_some()
|
||||
}));
|
||||
assert!(
|
||||
after
|
||||
.iter()
|
||||
.any(|entry| entry.key == "ghostlight/legacy-signer")
|
||||
);
|
||||
assert!(
|
||||
engine
|
||||
.current_signed_correlation(&service.incarnation()?)?
|
||||
.is_some()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn withdrawing_a_correlation_does_not_reset_its_publisher_sequence() -> Result<()> {
|
||||
let temp = TempDir::new()?;
|
||||
|
|
|
|||
|
|
@ -566,6 +566,10 @@ fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
// Correlations the previous, target-keyed Odin left in this store are not
|
||||
// this contract's and would otherwise be served to the Verse as current.
|
||||
// Presence history is kept: the self publisher sequence continues from it.
|
||||
CultCacheOdinTopologyStore::new(&state.borrow().options.store).retire_legacy_correlations()?;
|
||||
publish_self_presence(&state, &mut server, "ready")?;
|
||||
state.borrow_mut().refresh_all_correlations()?;
|
||||
let mut last_heartbeat = Instant::now();
|
||||
|
|
@ -1102,6 +1106,11 @@ fn correlation_incarnations(path: &Path) -> Result<BTreeSet<IncarnationRef>> {
|
|||
.pull_all_read_only_snapshot()?
|
||||
.into_iter()
|
||||
.filter(|entry| entry.r#type == OdinRuntimeTopologyCorrelationRecord::TYPE)
|
||||
// A correlation keyed by anything but an incarnation key was written
|
||||
// by the previous, target-keyed Odin. It is retired at activation
|
||||
// (`retire_legacy_correlations`), never refreshed, and never a reason
|
||||
// to refuse to start.
|
||||
.filter(|entry| IncarnationRef::parse_key(&entry.key).is_some())
|
||||
.map(|entry| {
|
||||
ensure!(
|
||||
entry.schema_id.as_deref() == Some(ODIN_RUNTIME_TOPOLOGY_CORRELATION_SCHEMA),
|
||||
|
|
|
|||
Loading…
Reference in a new issue