Expand description
Which vault this is, and which copy of it is allowed to act.
A vault has one vault_id for its whole life. Each copy that was ever opened has an
instance_id, an instance_epoch that only grows, and a role: active or standby. A restore
from a recovery package, or a copy of the files made by a sync folder, would otherwise be a
second vault that believes it is the only one, with the same hub identity, pushing to the same
nodes. The rules:
- A restored vault is
standbywith a newinstance_id(thevault.restoredmarker beside the database, written byunv recover restore, is read the next time the database is opened). A standby copy reads, verifies and exports; the hub does not push and the operations executor does not run. activatemakes a copyactiveand raises the epoch above anything this copy has seen. The person doing it is saying the old instance is retired.- The hub tells nodes its
(vault_id, epoch); a node remembers the highest epoch and refuses a lower one, so a forgotten second hub cannot push over the live one. sync_foldernames a cloud-sync folder a live vault sits in. Two machines opening one synced file is the way a vault gets corrupted or forked without anybody deciding to.
Structs§
Enums§
Constants§
- RESTORED_
MARKER - The file
unv recover restoreleaves beside a restored vault. Its presence means “the next open is a new instance in standby”.
Functions§
- activate
- Makes this copy the active one and raises its epoch by one.
- become_
standby - Makes this copy a new instance in standby: what a restore does. The
vault_idis kept (it is still that vault); the instance and its epoch are new. - ensure
- Reads the identity, creating it the first time: a new
vault_id, a newinstance_id, epoch 1, active. An existing vault gets one the first time it is opened by a build that knows about this. - on_open
- Called when a database is opened: a restore marker beside it turns this copy into a standby instance, once. The marker is removed only after the change is stored.
- require_
active - Refuses an action that only the active instance may take.
- sync_
folder - The sync client whose folder
pathis inside, orNone.marker_existsanswers whether a directory holds a marker file (.stfolderfor Syncthing); it is a parameter so the check can be tested without touching the disk. - sync_
folder_ on_ disk sync_folderagainst the real file system.