Compact the event log into per-account snapshots

Once the log grows past ~3x the account count it is rewritten to one
AccountRegistered per account (churned cert events dropped), via a temp
file and rename. Cert replay is now idempotent, so a snapshot plus
re-delivered events converge and a peer syncing from a compacted node
still gets every account. Runs on a 30m timer.
This commit is contained in:
Jean Chevronnet 2026-07-12 07:24:44 +00:00
parent df7b413862
commit cc0265548f
No known key found for this signature in database
3 changed files with 127 additions and 1 deletions

View file

@ -51,6 +51,19 @@ async fn main() -> Result<()> {
tokio::spawn(gossip::run(engine.clone(), gossip, cfg.peer.clone(), cfg.server.sid.clone(), gossip_tx));
}
// Periodically fold log churn into a snapshot when it grows past the accounts.
{
let engine = engine.clone();
tokio::spawn(async move {
loop {
tokio::time::sleep(std::time::Duration::from_secs(1800)).await;
if let Err(e) = engine.lock().await.maybe_compact() {
tracing::warn!(%e, "compaction failed");
}
}
});
}
let addr = format!("{}:{}", cfg.uplink.host, cfg.uplink.port);
tracing::info!(server = %cfg.server.name, %addr, "linking to uplink");
link::run(proto, engine, &addr).await