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:
parent
df7b413862
commit
cc0265548f
3 changed files with 127 additions and 1 deletions
|
|
@ -104,6 +104,16 @@ impl Engine {
|
|||
self.db.ingest(entry)
|
||||
}
|
||||
|
||||
// Compact the log if it has grown past the live account count. Returns
|
||||
// whether it rewrote anything.
|
||||
pub fn maybe_compact(&mut self) -> std::io::Result<bool> {
|
||||
if self.db.should_compact() {
|
||||
self.db.compact()?;
|
||||
return Ok(true);
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn test_register(&mut self, name: &str) {
|
||||
self.db.register(name, "pw", None).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue