summaryrefslogtreecommitdiffstats
path: root/src/remake/local.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 19:10:58 +0100
committertv <tv@krebsco.de>2026-10-26 19:10:58 +0100
commitf819296674debea160f19a61d09ac1eea4462820 (patch)
tree1fd9e49125380d2a48edf39e11b1c62908b32af7 /src/remake/local.rs
parent2a0658a177759a68a0cfff001914323efa91bf41 (diff)
don't cast votes once there's a majority
Diffstat (limited to 'src/remake/local.rs')
-rw-r--r--src/remake/local.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/remake/local.rs b/src/remake/local.rs
index a9a88b4..fd7c567 100644
--- a/src/remake/local.rs
+++ b/src/remake/local.rs
@@ -58,6 +58,8 @@ struct Inner {
content_fetches: HashSet<[u8; 32]>,
/// Remakes this node coordinates now (`coordinator`).
coordinating: HashSet<String>,
+ /// The remake this node is about to vote for, and when (`vote_due`).
+ vote_due: Option<(String, UnixMillis)>,
/// The actors this node writes or wrote with in the current document: this run's,
/// and those of earlier runs it knows of (`--document-file`). Its own writes, for a
/// rejoin. A switch or rejoin starts the list over with the new document's actor, so
@@ -186,6 +188,25 @@ impl RemakeState {
self.lock().coordinating.contains(id)
}
+ /// When this node votes for `remake` (`vote::cast`): asked first, `now` plus
+ /// `delay()`; asked again, the same time.
+ pub(crate) fn vote_due(
+ &self,
+ remake: &str,
+ now: UnixMillis,
+ delay: impl FnOnce() -> Duration,
+ ) -> UnixMillis {
+ let mut inner = self.lock();
+ match &inner.vote_due {
+ Some((id, due)) if id == remake => *due,
+ _ => {
+ let due = now.plus(delay());
+ inner.vote_due = Some((remake.to_owned(), due));
+ due
+ }
+ }
+ }
+
fn lock(&self) -> MutexGuard<'_, Inner> {
self.inner.lock_or_recover()
}