diff options
| author | tv <tv@krebsco.de> | 2026-10-26 05:38:41 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-26 05:38:41 +0100 |
| commit | f12a839d6e6bdd29a86ac52d5de836519a41aaf0 (patch) | |
| tree | b34da34a22292793c991b15a95908f6cd78bb70b /src/remake/local.rs | |
| parent | 504435444c65efc59c0f7c6881991296258538a7 (diff) | |
wrap unix timestamps in newtype
Diffstat (limited to 'src/remake/local.rs')
| -rw-r--r-- | src/remake/local.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/remake/local.rs b/src/remake/local.rs index c6a4c18..a9a88b4 100644 --- a/src/remake/local.rs +++ b/src/remake/local.rs @@ -15,20 +15,21 @@ use tokio::time::Instant; use super::records::Retention; use super::snapshot::Snapshot; +use crate::clock::UnixMillis; use crate::document::replica::Epoch; use crate::locks::MutexExt; pub(crate) struct RemakeState { /// When this node started (Unix milliseconds): votes it cast before may be lost /// (`vote`). - started_at: u64, + started_at: UnixMillis, // A std mutex: every access is short and never spans an await. inner: Mutex<Inner>, } impl RemakeState { /// `started_at`: now, by the node's clock. - pub(crate) fn new(started_at: u64) -> Self { + pub(crate) fn new(started_at: UnixMillis) -> Self { Self { started_at, inner: Mutex::default(), @@ -94,7 +95,7 @@ pub(crate) struct Quarantined { /// The epoch the changes were made in, and the one the node rejoined. pub(crate) epoch: Epoch, pub(crate) target: Epoch, - pub(crate) created_at: u64, + pub(crate) created_at: UnixMillis, pub(crate) reason: String, /// Store paths the changes touched (minimal, prefix-free). pub(crate) paths: Vec<Vec<String>>, @@ -118,7 +119,7 @@ pub(crate) struct CatchUpReport { #[serde(rename_all = "camelCase")] pub(crate) struct LocalStatus { #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) switched_at: Option<u64>, + pub(crate) switched_at: Option<UnixMillis>, #[serde(skip_serializing_if = "Option::is_none")] pub(crate) replayed_paths: Option<usize>, #[serde(skip_serializing_if = "Option::is_none")] @@ -136,7 +137,7 @@ struct Archived { // Kept for auditing and recovery by hand; not read by the protocol. #[allow(dead_code)] doc: AutoCommit, - archived_at: u64, + archived_at: UnixMillis, retention: Retention, } @@ -146,11 +147,11 @@ struct Archived { pub(crate) struct ArchivedEpoch { pub(crate) generation: u64, pub(crate) id: String, - pub(crate) archived_at: u64, + pub(crate) archived_at: UnixMillis, } impl RemakeState { - pub(crate) fn started_at(&self) -> u64 { + pub(crate) fn started_at(&self) -> UnixMillis { self.started_at } @@ -222,7 +223,7 @@ impl RemakeState { doc: AutoCommit, retention: Retention, current_generation: u64, - now: u64, + now: UnixMillis, ) { let mut inner = self.lock(); inner.archive.push(Archived { @@ -234,7 +235,7 @@ impl RemakeState { prune(&mut inner.archive, current_generation, now); } - pub(crate) fn prune_archive(&self, current_generation: u64, now: u64) { + pub(crate) fn prune_archive(&self, current_generation: u64, now: UnixMillis) { prune(&mut self.lock().archive, current_generation, now); } @@ -371,11 +372,11 @@ impl RemakeState { } /// An archive is kept until every limit of its retention has passed. -fn prune(archive: &mut Vec<Archived>, current_generation: u64, now: u64) { +fn prune(archive: &mut Vec<Archived>, current_generation: u64, now: UnixMillis) { archive.retain(|archived| { archived.retention.covers( current_generation.saturating_sub(archived.epoch.generation), - now.saturating_sub(archived.archived_at), + now.ms_since(archived.archived_at), ) }); } @@ -386,8 +387,8 @@ mod tests { #[test] fn archive_retention() { - let remake = RemakeState::new(0); - let now = 1_000_000; + let remake = RemakeState::new(UnixMillis(0)); + let now = UnixMillis(1_000_000); let epoch = |generation| Epoch { generation, id: [generation as u8; 32], |
