diff options
Diffstat (limited to 'src/document')
| -rw-r--r-- | src/document/file.rs | 2 | ||||
| -rw-r--r-- | src/document/mod.rs | 1 | ||||
| -rw-r--r-- | src/document/own.rs | 33 | ||||
| -rw-r--r-- | src/document/replica.rs | 2 |
4 files changed, 36 insertions, 2 deletions
diff --git a/src/document/file.rs b/src/document/file.rs index a21aa17..80c76e6 100644 --- a/src/document/file.rs +++ b/src/document/file.rs @@ -245,7 +245,7 @@ pub(crate) struct DocumentFile { #[derive(Debug, Clone)] struct Written { epoch: Epoch, - /// This node's actors when the file was last rewritten (`RemakeState::own_actors`). + /// This node's actors when the file was last rewritten (`document::own::OwnWriters`). actors: usize, heads: Vec<ChangeHash>, /// How many of the document's signatures (`Signatures::count`). diff --git a/src/document/mod.rs b/src/document/mod.rs index 530e6b6..fd44331 100644 --- a/src/document/mod.rs +++ b/src/document/mod.rs @@ -63,6 +63,7 @@ pub(crate) mod file; pub(crate) mod inspect; pub(crate) mod lock; pub(crate) mod meta; +pub(crate) mod own; pub(crate) mod replica; pub(crate) mod signatures; pub(crate) mod signed; 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<Vec<ActorId>>); + +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<ActorId> { + self.0.lock_or_recover().clone() + } +} diff --git a/src/document/replica.rs b/src/document/replica.rs index cdf789c..ba94ca9 100644 --- a/src/document/replica.rs +++ b/src/document/replica.rs @@ -493,7 +493,7 @@ fn run<T, E>( /// Makes `node` the author of `doc`'s changes from now on. Setting an author gives the /// document a new actor; this node keeps its own (`with_actor`), which it tracks -/// (`RemakeState::own_actors`, the document file), as only it writes with it. +/// (`document::own::OwnWriters`, the document file), as only it writes with it. pub(crate) fn authored(doc: &mut Document, node: &str) { if doc .get_author() |
