From 8a29efed857991417d12b8e21884dbbcb53ff4a0 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 02:48:25 +0000 Subject: document: the writers a node wrote under are the document's, not a remake's The actors a node writes or wrote with in its current document (document::own::OwnWriters, AppState::own_writers) were kept by the remake state, which signing, the document file, sync and a dropped change read them from. They are the engine's: a document of a kind without writers of this sort has none, and needs no remake state for them. --- src/document/own.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/document/own.rs (limited to 'src/document/own.rs') diff --git a/src/document/own.rs b/src/document/own.rs new file mode 100644 index 0000000..2910616 --- /dev/null +++ b/src/document/own.rs @@ -0,0 +1,33 @@ +//! The writers this node writes or wrote under in its current document. + +use std::sync::Mutex; + +use super::ActorId; +use crate::locks::MutexExt; + +/// 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, +/// for signing and for dropping what it took. A switch or rejoin starts the list over +/// with the new document's actor, so it only grows with restarts within one epoch. +#[derive(Debug, Default)] +pub(crate) struct OwnWriters(Mutex>); + +impl OwnWriters { + /// This node writes with `actor` from now on (or did, in an earlier run). + pub(crate) fn add(&self, actor: ActorId) { + let mut own = self.0.lock_or_recover(); + if !own.contains(&actor) { + own.push(actor); + } + } + + /// The current document is a new one, written with `actor` only (a switch or rejoin + /// is done). + pub(crate) fn reset(&self, actor: ActorId) { + *self.0.lock_or_recover() = vec![actor]; + } + + pub(crate) fn all(&self) -> Vec { + self.0.lock_or_recover().clone() + } +} -- cgit v1.3.1