aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/local.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 03:23:21 +0000
committertv <tv@krebsco.de>2026-12-01 03:45:00 +0000
commitb6743899468db6304173aca4c7b32d05ea8d92c9 (patch)
tree96036989bc0bba94364cdf1b6a3aba73c3e8ae28 /src/remake/local.rs
parent80a1075951bdf70a4e9fb68e4a4228cfe0d27ba8 (diff)
remake: the switch worker looks when something changed, not every second
It read the remake records and its peers' epochs once a second, whatever happened. It now looks when the records change, within a second of a peer saying another epoch than this node's, and when a vote is due; and by itself, once a second, only while something waits on time: a remake of this epoch open or committed, a rejoin, a catch-up, a member on another epoch. What it keeps for a time, an archived document or a remake's content, it wakes for when that is due.
Diffstat (limited to 'src/remake/local.rs')
-rw-r--r--src/remake/local.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/remake/local.rs b/src/remake/local.rs
index cf6f566..cdea68a 100644
--- a/src/remake/local.rs
+++ b/src/remake/local.rs
@@ -275,6 +275,28 @@ impl RemakeState {
prune(&mut self.lock().archive, current_generation, now);
}
+ /// How long until something kept for a time goes (`prune_archive`,
+ /// `prune_contents`), at `now`: an archived
+ /// document whose age limit is ahead, a remake's content within its grace. None
+ /// where nothing waits on time: what is kept by a count of epochs, or by a remake
+ /// that refers to it, goes when those change.
+ pub(crate) fn next_expiry(&self, now: UnixMillis) -> Option<Duration> {
+ let inner = self.lock();
+ let archives = inner.archive.iter().filter_map(|archived| {
+ archived
+ .retention
+ .age_left(now.ms_since(archived.archived_at))
+ });
+ let contents = inner
+ .contents
+ .values()
+ .filter_map(|(_, stored)| CONTENT_GRACE.checked_sub(stored.elapsed()));
+ archives
+ .chain(contents)
+ .min()
+ .map(|left| left + Duration::from_millis(1))
+ }
+
pub(crate) fn catch_up(&self) -> Option<CatchUp> {
self.lock().catch_up.clone()
}