Skip to main content

Module identity

Module identity 

Source
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 standby with a new instance_id (the vault.restored marker beside the database, written by unv 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.
  • activate makes a copy active and 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_folder names 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§

Identity

Enums§

Role

Constants§

RESTORED_MARKER
The file unv recover restore leaves 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_id is 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 new instance_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 path is inside, or None. marker_exists answers whether a directory holds a marker file (.stfolder for Syncthing); it is a parameter so the check can be tested without touching the disk.
sync_folder_on_disk
sync_folder against the real file system.