ADR 0016: authority, snapshots and restore
Status: Accepted on 2026-11-29 (knotrel/knotrel#224). Scope decisions Q3 and Q5 approved by the maintainer on 2026-11-29. Issues: #154 (contracts), #157 (snapshots).
Related: ADR 0012 (source-managed mode), ADR 0015 (runtime and registry).
Context
Knotrel stores nothing on disk. A restarted source-managed graph is rebuilt by a full import from the authoritative source, which can take long on large graphs. Snapshots can shorten that recovery, but a local copy can also claim more than it knows: it may be older than the source, from another source epoch, or corrupt. Durable acknowledgment of direct writes needs a log and is planned separately (#158, v1.4.0).
Decision
- Each graph has three properties fixed at creation: authority (
direct,external, laterknotrel), persistence (none,snapshot, laterwal) and residency (resident, laterbounded). Unsupported combinations are rejected with an explicit error, never mapped to the nearest valid one. Mode changes in place are not supported in v1.3.0: an operator creates a new graph and loads it. - Q3: in v1.3.0 snapshots are allowed only with
externalauthority. Valid combinations:direct/none(today’s standalone mode),external/none(today’s source-managed mode) andexternal/snapshot.direct/snapshotis rejected. - A snapshot is an engine-neutral logical image of one graph at one
coherent point: every node with its flags, every canonical edge with its
flags, configuration, generation and revision, and the source identity,
epoch and applied position. It never contains engine internals and can be
restored on any supported engine. It lives in a new synchronous crate,
knotrel-storage, behind a store interface with a local-filesystem implementation; publication is atomic and keeps the last valid snapshot. - What a restore guarantees: the graph equals the graph that existed at the snapshot’s recorded source position, or the restore fails visibly (corrupt, unsupported or incompatible snapshot) and the graph falls back to the normal rebuild. It does not guarantee that the graph matches the source now.
- A restored graph is never ready by itself. It starts a new generation in the catching-up state and exposes its source position. The feeder resumes after that position and declares a barrier (the ADR 0012 path to ready), or detects a gap, an epoch change or expired history and performs a full replace import. Without a valid snapshot the graph starts uninitialized, as today.
- Q5: snapshots are opt-in and on demand. The default graph enables them
with a snapshot directory setting
(configuration, planned);
without it, persistence stays
none. Periodic scheduling may come later.
Alternatives considered
- Allow
direct/snapshotin v1.3.0. A restore would silently lose writes that were already acknowledged after the last snapshot. Rejected (Q3); revisited with the WAL in #158. - Declare a restored graph ready immediately. Faster recovery, but serves answers that may be stale or from another source epoch as if synchronized. Rejected: a local copy is not synchronization proof.
- Persist engine internals (ETT, HDT, cluster-forest trees). Faster restore for one engine, but ties the format to private structures and breaks restoring on another engine. Rejected.
- Append-only log (AOF) together with snapshots. For an external-authority graph the source already holds the log; a local log adds write cost without a demonstrated benefit. Deferred to #158.
- Periodic snapshots from the first version. Adds scheduling, overlap and disk-pressure behavior before the basic path is proven. Deferred (Q5).
Consequences
- Recovery time of an
external/snapshotgraph becomes “restore plus catch-up from the snapshot position” instead of a full rebuild, when the source still holds that history. The gain is measured in the v1.3.0 qualification #187, not promised here. - The integration contract gains the restore path (how the restored position is announced and how the feeder session restarts) before any code.
- Local disk becomes a resource: disk full or permission errors fail the snapshot, keep the previous one and never affect the in-memory graph. Process-kill safety is tested by fault injection; power-loss safety is an assumption about the filesystem, documented as such.
- Snapshots are not encrypted by Knotrel; encryption at rest is a filesystem or volume concern.