From 7926a9764626878f5cc244286cce9eb502358929 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 04:16:12 +0000 Subject: keep-actor by default: the writer kept across a clean stop, writes held till a sync A node that stopped cleanly writes on as the writer of before, as `--keep-actor` had it, now by default: an epoch gathers a writer per node and per crash, drop or rejoin, not per start. `keep-actor = false`, in a configuration file, has a node write as a fresh writer each start; a node without a document file has nothing to keep, which is no longer an error. Writing on as the writer of before, a node holds its writes (`mutate_doc` and the API's through it) until it synced once with a ready neighbour, level with it, or 10 seconds passed (`AppState::hold_writes`, `KEPT_WRITER_WAIT`): a neighbour holding later changes of that writer, which a copy of the node's files made (a backup restored, a disk rolled back), hands them over first, and the node takes a fresh writer then, as it did. A node that reaches no neighbour within the wait writes on. --- src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index a2e24ba..f88ad30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -262,21 +262,24 @@ pub async fn run() -> Result<()> { let opened = document_file.as_ref().is_none_or(|file| file.open()); // Writing on as the actor of before, where this node stopped cleanly: everything it // wrote as that one is in the document, so no change of it comes twice. - match resumable.filter(|_| args.keep_actor && opened) { + let kept = match resumable.filter(|_| args.keep_actor && opened) { Some(actor) => { info!(actor = %actor, "Writing on as the actor of before (--keep-actor)"); initial_doc.set_actor(actor); + true } None if args.keep_actor && !opened => { warn!( "Writing as a fresh actor: the document file couldn't be marked as opened (--keep-actor)" ); + false } None if args.keep_actor && starting_epoch.is_some() => { info!("Writing as a fresh actor: this node didn't stop cleanly (--keep-actor)"); + false } - None => {} - } + None => false, + }; if let Some(spec) = &args.remake { remake::remake_genesis(spec, &files, &mut initial_doc) .with_context(|| format!("Making the genesis document (--remake {spec})"))?; @@ -386,6 +389,9 @@ pub async fn run() -> Result<()> { clock: Default::default(), }); let state = node.state.clone(); + if kept { + state.hold_writes(); + } // Join the remembered swarm and no other; HELLOs claim it. A document to start on // names its swarm itself (checked against the remembered one above). -- cgit v1.3.1