From 152890f321075beede075314d37ff6451604c359 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 9 Nov 2026 20:29:32 +0000 Subject: document file: a clean stop marked, and `--keep-actor` writes on as the same actor A node writes as a fresh Automerge actor at each start, so no change number of an actor comes twice: one sent before a crash but not yet appended to the document file would otherwise be made again, differently. An epoch thus gathers a writer per start, and every transfer of its history carries a signature per writer. The document file now says when it holds everything the node wrote: * at a clean stop, after the last append, an empty `Closed` record, only where the file is up to the document's heads (ready, not rejoining); * as a node starts on the file, before anything is written, an empty `Opened` record, so a crash from then on leaves a file without the mark; * the header names the actor the node writes with (`current`). With `--keep-actor` (off by default; needs `--document-file`), a node starting on a file that ends with `Closed` writes on as that actor. A crash, a drop, a switch or a rejoin still starts a fresh one, so an epoch's writers come to one per node plus one per such event. lifecycle.md says so. --- src/swarm/bootstrap.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/swarm/bootstrap.rs') diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index d2a593b..5c3b5ef 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -266,6 +266,9 @@ pub(crate) struct StartingDocument { pub(crate) earlier_actors: Vec, /// The signatures of its changes (from the document file). pub(crate) signatures: Vec<(crate::document::ChangeHash, [u8; 64])>, + /// The actor this node wrote with, where it stopped cleanly (the document file's + /// `resumable`): it may write on as that one (`--keep-actor`). + pub(crate) resumable: Option, } /// What `--recover-from` and `--document-file` say about where to start. @@ -314,7 +317,7 @@ pub(crate) fn starting_document( Some(path) => Some(load_backup(path, files)?), }; - let (doc, origin, earlier_actors, signatures) = match (backup, from_file) { + let (doc, origin, earlier_actors, signatures, resumable) = match (backup, from_file) { (Some(_), Some(_)) if !force.allows("replaceDocumentFile") => { bail!( "recover-from would replace the document in the document file; add --force replaceDocumentFile to recover the backup anyway" @@ -326,13 +329,14 @@ pub(crate) fn starting_document( "Recovering the backup instead of the document file's document (--force replaceDocumentFile)" ); } - (backup, Origin::Backup, Vec::new(), Vec::new()) + (backup, Origin::Backup, Vec::new(), Vec::new(), None) } (None, Some(loaded)) => ( loaded.doc, Origin::DocumentFile, loaded.actors, loaded.signatures, + loaded.resumable, ), (None, None) => return Ok(None), }; @@ -343,6 +347,7 @@ pub(crate) fn starting_document( } let mut starting = identify(doc, origin, earlier_actors)?; starting.signatures = signatures; + starting.resumable = resumable; if let Some(remembered) = options.remembered.filter(|id| *id != starting.swarm_id) { let what = origin.describe(); @@ -379,6 +384,7 @@ fn identify( origin, earlier_actors, signatures: Vec::new(), + resumable: None, }) } -- cgit v1.3.1