Storage Format Specification (store version 4, file version 4)
This page is the normative specification of Graphersal's storage format, store format version 4
with file format version 4 (15; version 5 marks only a layer snapshot, 7.5): the packed snapshot (.gsnap), the write-ahead log
(journal), the Store directory and its files, and the single-file container (.gstore). It is
written so that a third party can read (and write) these files without Graphersal's code: a
backup tool, a converter, a change-data-capture connector that tails the WAL.
The reference implementation is the persist module of the graphersal crate. Where this text
and the implementation disagree, it is a bug in one of them; please report it.
Contents
- Scope, conformance and terms
- Conventions
- Value encoding
- The store: layout and names
- The
GRAPHfile - The snapshot manifest
- Segment files and chunks
- The packed snapshot
- The write-ahead log
- The
marksfile - The
INTENTandATTICfiles - Operations
- Damage handling
- The single-file container
- Versioning
- Extensibility
- Conformance notes
- Time: the instance clock
1. Scope, conformance and terms
The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are to be read as described in RFC 2119. Byte layouts, numeric constants, magic values, names and the rules that tell a valid file from a damaged one are normative. Default sizes (chunk, segment, thresholds) are informative unless a file records them; a reader MUST NOT assume a default where the file states the value.
Terms
| Term | Meaning |
|---|---|
| graph | a property graph: vertices (an id, a set of labels, properties) and edges (an id, at most one label, an out and an in vertex, properties), plus an optional schema and a catalog of definitions |
| definition | a named entry of the graph's catalog, stored beside the schema: a saved query, a property index, a compression rule, a scheduled job or an embedding model today, other kinds later (6.3) |
| commit | one committed unit of change (a transaction); it has a commit sequence number and a time |
commit_seq | the commit sequence number: u64, the first commit of a graph is 1, every later commit is the previous one + 1; 0 is the position before any commit |
| position | a commit_seq: the state after that commit |
graph_id | a UUID (version 7 when created by the reference implementation) naming a lineage: a history of commits. A fork, an in-place rollback and a repair start a new lineage |
| lineage chain | the list of lineages a store descends from, with the commit at which each child branched off |
| snapshot | the whole graph at one position: a manifest (with the catalog of definitions), a schema and segment files |
| chunk | a self-contained, optionally compressed block of elements inside a segment |
| WAL, journal | the write-ahead log: a sequence of records, one per commit and one per mark |
| mark | a name for a position, recorded in the WAL |
| target | a position to recover to: a commit_seq, a time, or a mark name |
| store | the set of files of ONE graph, kept below a root (a directory, a single container file, or memory) |
| backup | a store whose GRAPH file carries a backup marker (12.6) |
| attic | the part of a store that keeps history an in-place rollback moved aside |
| donor | an intact older copy of damaged data (13) |
| torn tail | the incomplete end of a file left by an interrupted write; distinguished from damage by the rules of 9.6 and 14.4 |
2. Conventions
- Fixed-width integers are little-endian:
u8,u16,u32,u64unsigned,i64two's complement. uvaris an unsigned LEB128 varint (7 bits per byte, least significant group first, high bit = more bytes follow). Auvarlonger than 10 bytes, or one whose value overflowsu64, is invalid. Writers MUST write the shortest encoding.svaris a signed integer as zigzag ((n << 1) ^ (n >> 63)) followed byuvar.stringisuvarbyte length followed by that many bytes of UTF-8. Invalid UTF-8 is invalid.opt_stringisuvar 0for "none", elseuvar (length + 1)followed by the UTF-8 bytes.- Time is an
i64of microseconds since the Unix epoch, UTC. Commit times of one lineage are monotonic: a commit's time ismax(now, time of the previous commit). Commit, mark and checkpoint times and system-journal times of one instance share one monotonic clock:max(now, the latest time the instance wrote); after a restart the floor is the latest time in the WAL and the journal (the floor itself is not stored). Section 18 gives the rules. - UUID values and every
graph_idare 16 bytes in RFC 9562 network order (big-endian), so that byte order equals the order of the canonical text. - Element ids are strings. "Sorted by id" means the bytewise order of the UTF-8 encoding.
- Checksums are CRC-32C (Castagnoli, polynomial
0x1EDC6F41, reflected, initial value and final XOR0xFFFFFFFF), stored asu32. "The CRC of bytesa..b" covers exactly those bytes. - Reserved bytes and fields MUST be written as zero. A reader MUST ignore reserved bytes unless a section says otherwise.
- Bounds. Every length or count read from a file MUST be checked against the bytes that
remain before anything is allocated for it; a count that the remaining bytes cannot hold is
invalid. An uncompressed chunk, single-record WAL body or slice of a commit in parts (9.3.1)
is at most 1 GiB; a commit in parts is not bounded by it. A declared uncompressed size of an
LZ4 block above
255 * stored length + 64is invalid.
2.1 Compression codecs
| Codec byte | Codec | Stored bytes |
|---|---|---|
| 0 | none | the raw bytes; the stored length MUST equal the uncompressed length |
| 1 | LZ4 | one LZ4 block (no frame, no size prefix) |
| 2 | zstd | one zstd frame |
Writers compress a block only when it is at least 4096 bytes long and compression makes it smaller; otherwise they store it with codec 0. Other codec bytes are invalid. A reader that does not implement codec 2 MUST report such a block as unsupported, never as damage.
3. Value encoding
One encoding is shared by segment chunks and WAL records. A value starts with a tag byte:
| Tag | Value | Payload |
|---|---|---|
| 0 | null | none |
| 1 | false | none |
| 2 | true | none |
| 3 | int64 | svar |
| 4 | float64 | 8 bytes, IEEE 754 binary64, little-endian; NaN payloads are preserved |
| 5 | string | string |
| 6 | uuid | 16 bytes, big-endian |
| 7 | array | uvar n, then n values |
| 8 | object | uvar n, then n pairs of key and value; a key is a string-table reference (uvar) inside a segment chunk and an inline string inside a WAL record |
| 9 | date | svar days: days since 1970-01-01 (file format version 2) |
| 10 | localdatetime | svar micros: microseconds since 1970-01-01T00:00:00, wall clock, no zone (file format version 2; read only since version 3) |
| 11 | datetime | svar micros since 1970-01-01T00:00:00Z (the instant), then svar offset: the UTC offset in seconds (file format version 2; read only since version 3) |
| 12 | time | uvar micros: microseconds since midnight (file format version 2; read only since version 3) |
| 13 | duration | svar months, svar days, svar micros, each with its own sign (file format version 2; read only since version 3) |
| 14 | vector | u8 element (0 f32, 1 f16, 2 i8, 3 bit), uvar dimension, then for i8 the scale (4 bytes, IEEE 754 binary32, little-endian), then the packed components: f32 4 bytes each (binary32, little-endian), f16 2 bytes each (binary16, little-endian), i8 1 byte each (two's complement), bit ceil(dimension / 8) bytes in all, the first component in the most significant bit of the first byte (file format version 2) |
| 15 | localdatetime | svar seconds since 1970-01-01T00:00:00 rounded down (toward minus infinity), then uvar nanos: the nanoseconds of that second, 0..10^9; wall clock, no zone (file format version 3) |
| 16 | datetime | svar seconds since 1970-01-01T00:00:00Z rounded down and uvar nanos as in tag 15 (the instant), then svar offset: the UTC offset in seconds (file format version 3) |
| 17 | datetime with a zone name | the fields of tag 16, then the IANA zone name (Europe/Berlin) as a key: a string-table reference (uvar) inside a segment chunk, an inline string inside a WAL record (file format version 3) |
| 18 | time | uvar nanos: nanoseconds since midnight (file format version 3) |
| 19 | offsettime | uvar nanos: nanoseconds since midnight (the local time of day), then svar offset: the UTC offset in seconds (file format version 3) |
| 20 | duration | svar months, svar days, then the time part as svar seconds rounded down and uvar nanos of that second (0..10^9); each part with its own sign (the time part's sign is that of seconds * 10^9 + nanos) (file format version 3) |
| 21 | blobref | a reference to a blob of the store (4.6): u8 hash_algo (1 = SHA-256; 0 is invalid; 2..255 a newer writer's algorithm), uvar hash_len (1..=64; exactly 32 for SHA-256), the hash bytes, u64 length of the content (little-endian), u32 CRC-32C of the content (little-endian) (file format version 4) |
| 22..254 | reserved | invalid in versions 1 to 4 |
| 255 | absent | only where a field explicitly allows it (the before value of a SetProperty mutation, 9.3) |
-
The order of object entries (and of property maps, 7.3) is the insertion order and MUST be preserved. A repeated key in one object or property map is invalid.
-
Temporal values use the proleptic Gregorian calendar. Tags 9 to 13 (file format version 2) have a resolution of one microsecond; tags 15 to 20 (version 3) one nanosecond. A writer of version 3 or later writes ONE form per kind: a
dateas tag 9, alocaldatetimeas tag 15, adatetimeas tag 16 (tag 17 when it keeps a zone name), atimeas tag 18, anoffsettimeas tag 19, adurationas tag 20; every engine value has an encoding, so nothing is refused. A reader of version 3 or later reads tags 9 to 13 as well (a version 2 segment's chunks copied into a newer snapshot keep them). Thesvar seconds+uvar nanospairs hold nanoseconds over the years -9999 to 9999 (about ±3.2 * 10^20 ns, more than ani64) and a duration's whole time part. Their ranges are normative; a value outside its range is invalid:Tag Valid payload 9 dayswithin the years -9999 to 9999: -4371587 (-9999-01-01) to 2932896 (9999-12-31)10 microswithin the same days (-9999-01-01T00:00:00to9999-12-31T23:59:59.999999)11 offsetwithin ±64800 (±18:00); both the instant and the local time (micros + offset * 10^6) within the range of tag 1012 microsin0..8640000000013 monthsanddayswithini32,microswithini6415 nanosbelow 10^9;seconds * 10^9 + nanoswithin the days of tag 9 (-9999-01-01T00:00:00to9999-12-31T23:59:59.999999999)16, 17 nanosbelow 10^9;offsetwithin ±64800; both the instant and the local time within the range of tag 1518 nanosin0..8640000000000019 nanosas in tag 18;offsetwithin ±6480020 monthsanddayswithini32;nanosbelow 10^9 (secondsis ansvar, so the time part spans-9223372036854775808s to9223372036854775807.999999999s, the range ofjava.time.Duration)A
datetimekeeps the offset it was written with; equality and order of twodatetimes use the instant only (the offset and the zone name are not compared). The zone name of tag 17 is stored as text, never as an index into a build's own table; the offset is stored as written and is not recomputed from the name. A name the reader's time zone database does not know (a newer database's) is content of a newer writer behind a valid checksum: unsupported content (16 rule 9), never damage; the reference reader refuses the value and the operation, as it does with every unsupported content; ASCII case is ignored when the name is looked up. Anoffsettimeorders by its UTC time of day (the local time minus the offset, not wrapped). Adurationis not normalized:P1M,P30DandPT720Hare three different values. -
Vector values (tag 14):
dimensionis 1 to 65536; a component of anf32orf16vector is finite (no NaN, no infinity;-0.0is valid and equals0.0); thei8scale is finite and>= 0(-0.0is written as0.0); the value of ani8component iscode * scale; abitcomponent is1.0for a set bit and-1.0otherwise, and the padding bits of the last byte are 0. An unknown element byte, a dimension out of range and any other violation are invalid (damage): every element kind of version 2 is defined here. A reader checks the payload length (dimensiontimes the component size) against the remaining bytes before it allocates. -
Blob references (tag 21): a
hash_algoof 0, ahash_lenoutside 1..=64 and a SHA-256 hash that is not 32 bytes are invalid (damage). An algorithm 2..255 is a newer writer's: the value is decoded and kept, and its blob is carried BY NAME (4.6) by every copy (backups, ZIP archives, forks, repairs, packed snapshots), checked by its length and CRC-32C; it is never read and its hash never computed (unsupported content, 16 rule 9). In this version ablobrefappears only in catalog definition payloads (6.3); a writer MUST NOT store one as an element property value. -
Tags 9 to 14 are invalid in a file of format version 1, tags 15 to 20 in a file of format version 1 or 2, tag 21 in a file of a format version before 4 (15): a reader MUST report such a value as damage, never decode it. A reader takes the version from the header of the file the value is in: a segment chunk from its segment's header (7.1, also when the chunk is read through the chunk index without framing the whole segment), a WAL record from its WAL segment's header (9.1), a definition from the manifest (6.1) or WAL segment it is stored in.
-
Readers MUST bound the nesting depth of arrays and objects (the reference reader defaults to 128 levels and is configurable); writers MUST NOT write more than 4096 levels.
A property map is uvar count followed by count pairs of key and value, with keys encoded
as object keys are in the same context.
4. The store: layout and names
4.1 Layout
A store is a set of named files below a root:
GRAPH identity and state (5); written with its copy GRAPH.copy
GRAPH.copy
LOCK an empty file; the writer's operating-system lock (12.10)
BACKUP an empty file; the backup pin (12.10)
INTENT present only while a multi-file operation runs (11.1)
marks the marks, derived from the WAL (10)
WORKLOAD the workload statistics sidecar (4.4); optional, instance data
INSTANCE the instance identity of the system journal (4.7); instance data
journal/ the system journal (4.7); optional
00000000000000000001.jnl a journal segment; the name is the first seq it may hold
tmp-<32 hex digits> never listed, removed on open
ledger the blob ledger, derived from the WAL (10.1); optional
blobs/ the blobs the store keeps (4.6); optional
3f/3fa1...e9 one blob: its whole content; the name is the lowercase hex of its hash
tmp-<32 hex digits> a blob being written (never listed, removed on open)
models/ store format version 3 only (Graphersal 0.4.0): the embedding models as
files (4.5 "Older stores"); migrated away by the upgrade (15.1)
model2vec-0123456789ab/ one model; the name is its content address
graphersal-embed-model.json its manifest, written last
config.json tokenizer.json model.safetensors README.md LICENSE ...
tmp-<32 hex digits>/ a model being added, copied or removed (never listed, removed on open)
snapshots/
00000000000000052817/ one snapshot; the name is its commit_seq, 20 decimal digits
manifest 6
schema.json the schema, canonical compact JSON
v-000000.seg vertex segments (7), six decimal digits per kind, from 0
e-000000.seg edge segments
00000000000000052000/ a holder: the directory of a pruned snapshot without its manifest,
e-000002.seg keeping only files newer snapshots reference (6.2, 12.4)
tmp-<32 hex digits>/ a snapshot being written (never listed, removed on open)
wal/
00000000000000052818.wal a WAL segment; the name is the first commit_seq it may hold (9)
attic/
20261007T182205Z-00000000000000052001/ one rolled-back history (11.6, 12.5)
LOCK and BACKUP exist only for directories on a file system; other backends provide the same
locks without files (4.3). A snapshot directory holds exactly the files its manifest lists. A
directory under snapshots/ named by a commit but without a manifest file is a holder: it
is no snapshot (it is not listed, loaded or counted) and only keeps segment files that newer
snapshots reference (6.2); a prune removes it when no snapshot uses them any more (12.4).
4.2 Names
Every name a store file records (segment paths in a manifest, paths in INTENT, names in
ATTIC) is relative to the store root, /-separated, and contains no empty, . or ..
part, no \, no : and no NUL. No store file holds an absolute path, an operating-system path,
a device, or the target of a symbolic link. A store is therefore relocatable: moved or copied as
a whole, it opens unchanged. A reader MUST refuse a recorded name that breaks these rules.
4.3 Backends
The format does not depend on where the named files live. The reference implementation provides three backends behind one directory abstraction:
- a directory on a file system (names map to files below the root; parts of the tree MAY be symbolic links to other file systems, which are never resolved or recorded);
- a single container file (14);
- memory (no durability; locks are in-process flags).
A backend MUST provide: reading a file or a byte range of it; appending to a file (an append MAY
tear on a crash); replacing a whole file atomically (GRAPH, GRAPH.copy, marks rewrites,
INTENT, ATTIC); an atomic rename; removal of a file or a directory tree; a durability barrier
(fsync of a file and of a directory); an exclusive writer lock; and a shared/exclusive backup
pin. Files are only ever appended to, cut back, or replaced whole; lengths are logical bytes.
On a file system, a move between two parts of the tree that live on different file systems is
done as: copy into tmp-xdev-<name> in the target directory, sync, rename there, sync the
directory, remove the source, sync its directory. Leftover tmp-xdev-* names MUST be ignored by
every listing.
4.4 The workload statistics sidecar
WORKLOAD holds the instance's workload statistics (book page "Workload Statistics"): data of
the running instance, not of the graph. It is never in the WAL, never in a snapshot, and never
copied by a backup, a ZIP backup, a fork, a repair or a conversion; a restored or copied store
starts without it. An upgrade into a copy (15.1) keeps it: the copy is the same store. A writable store replaces it whole (write_atomic) periodically and at close.
magic "GRWLSTAT" | version u32 = 2 | series count u32
per series: byte length u32 | kind u8 (1 job, 2 lock, 3 query, 4 property)
| name (u32 length + UTF-8; a property series: the key, "*" for all)
| channel u8 (0 host, 1 playground, 2 mcp, 3 cli, 4 python, 5 job)
| kind 4 only: element u8 (0 unstated, 1 vertex, 2 edge) | label flag u8
[+ label (u32 length + UTF-8)] | access u8 (0 filter_scan, 1 filter_index,
2 read, 3 order_group, 4 similarity, 5 write, 6 remove)
| tier count u8 | per tier: tier u8 (0 minutes, 1 hours, 2 days) | bucket count u16
| per bucket: index i64 (the bucket's start in minutes/hours/days since the Unix
epoch, UTC) | count u64 | failed u64 | items u64 | total microseconds u64
| max microseconds u64
job count u32 | per job: name | started_at i64 (microseconds) | microseconds u64
| error flag u8 [+ error text]
section count u32 | per section: tag u8 | byte length u32 | bytes (version 2; may be absent)
tag 1, the system jobs' settings: count u32 | per job: name | schedule flag u8
[+ cron text] | enabled u8 (0 unset, 1 off, 2 on)
tag 2, the storage advisor's marks (book page "Optimize"): count u32 | per mark: id
| dismissed flag u8 [+ until i64, microseconds; i64::MAX = for good]
| applied flag u8 [+ at i64 | kind | title | promised bytes i64 | bytes before u64]
CRC-32C u32 of everything before it
All integers little-endian. Version 1 has no sections and is still read; in version 2 the sections may be left out (no settings). A section of a tag the reader does not know is skipped by its byte length. The settings of the system jobs (book page "Scheduled Jobs") and the advisor's marks are data of the instance like the statistics: they are lost with the file. A reader MUST treat the file as optional: a missing file, a wrong magic, length or checksum, or a version it does not know means "no statistics" (it starts anew and replaces the file at its next write), never damage, never a reason to refuse the store. A series of a kind or channel it does not know is skipped by its byte length, a tier it does not know by its bucket count; a reader keeps at most 60 minute, 48 hour and 90 day buckets. The magic is none of a segment's or a WAL segment's, so the version guard (15) ignores the file.
4.5 Embedding models
An embedding model the store keeps (book page "Embedding Models in a Store") is ONE blob (4.6)
holding all its files as a deterministic tar, referenced by a catalog definition of kind 5
(model, 6.3) that follows the history: every position (commit, mark, snapshot, rollback,
view) has exactly the models, and the default model, of that moment. A model enters a store
only by an explicit import (one commit defining it) and leaves its current state only by a
removal (one commit dropping the definition, refused while the current schema needs the
model); its blob goes with the prune that drops the last retained history referencing it
(12.4). The identity stays the link between a schema's vector properties (their embedder)
and the model: model2vec/<repo>@<12 hex>, the first 12 lowercase hex digits of the SHA-256 of
the text model2vec-identity/1\n followed by one line <role> <size> <sha256 hex>\n per
identity file, for the roles config, tokenizer and model in that order (the rule of the
Model2Vec loader; no path is part of it).
The tar. POSIX ustar (magic "ustar\0", version "00"): one regular-file entry
(typeflag '0') per file, entries sorted by name bytewise, mode 0000644, uid/gid 0,
uname/gname empty, mtime 0, devmajor/devminor 0, prefix and linkname empty, the
checksum as ustar defines it (six octal digits, NUL, space), the size as eleven octal digits and
a NUL (so a file is at most 8 GiB - 1), the data padded with zeros to 512 bytes; the end is two
zero blocks and nothing after them (a reader accepts further zero bytes only). No directories,
links, pax or GNU headers. The same files give the same bytes, so the same blob hash.
Files. The model's own files (the three identity files under the names they had, for
example config.json or config_sentence_transformers.json, tokenizer.json,
model.safetensors), its card README.md, the repository's licence and notice files
(LICENSE*, LICENCE*, COPYING*, NOTICE*), and the manifest graphersal-model.json. Every
file name is 1 to 40 bytes of ASCII letters, digits, ., _ and -, not starting with .. A
model has at most 64 files besides its manifest. When the repository has no licence file, the
writer adds the standard text of an MIT or Apache-2.0 license as LICENSE (license_text
template); for every known base-model licence other than license with a bundled text, the
file LICENSE-BASE-<licence> (lowercase SPDX id, role license), since parts of a base model
(such as a tokenizer) may be in the model.
Manifest (format 3; compact UTF-8 JSON, keys in this order, absent optional keys left out, so the bytes are deterministic; at most 1 MiB):
| Key | Content |
|---|---|
format | 3; a reader that sees a higher value does not load the model |
family | model2vec |
identity | model2vec/<repo>@<12 hex>: MUST match the files |
repo | the Hugging Face repository (name or owner/name) |
revision, commit | the revision asked for, the commit it resolved to (optional) |
license | the licence as an SPDX id as the repository states it, else unknown |
license_text | file (a licence file of the repository), template (the standard text the writer added) or none |
base_models | [{repo, license?}]: the models this one was made from |
gated | whether the repository is gated (its terms may restrict passing the model on) |
files | [{name, role, size, sha256}], sorted by name: every file of the tar but the manifest; role is config, tokenizer, model (exactly one each), card, license, notice |
No time stamp is part of the manifest or the definition (when a model was added is instance data, never part of the immutable model).
Reading. A reader reads the tar as a stream, entry by entry (this version's model load and
verify never hold the whole blob in memory): every header's checksum is checked, sizes are
bounded by the remaining bytes, names validated; an unknown type flag, a duplicate or unsorted name, more than 64 files besides the
manifest, a manifest that does not list exactly the tar's files are invalid content of the
model's blob (never damage of the store, 13). The files are used where they are (no extraction
to disk).
Needed models and the open. A model the CURRENT schema needs (a vector property's
embedder naming its identity) is loaded when the store opens, in every mode (also read-only,
a backup, a view of a past position). A needed model that is not in the catalog of that
position, whose blob is missing or damaged, or whose files do not load refuses the open
(model_unavailable), with the commands that bring it back; one whose load would take the
process over its memory ceiling refuses it too (model_does_not_fit): the check uses the blob's
length times 1.6 before anything is read (versions up to 0.5.2: length plus the definition's
load_bytes), and the message names the
smallest ceiling that fits. A writable open records the refusal in the journal (model.load_failed,
4.7) best effort. A model of a family or blob algorithm the reader does not know opens the store
read-only (16 rule 9); a reader that cannot run models at all (no Model2Vec loader, such as the
browser) checks the needed blobs by length and CRC-32C and opens the store read-only without
text queries. A model nothing needs is loaded at the first query that embeds with it; a missing
or damaged one is a journal record (model.unavailable), the store works.
Copies. The models travel as blobs: every copy carries the blobs its history references (4.6, 12.x) and the definitions with the catalog, so the copy has the models of every position it holds.
Older stores. Graphersal 0.4.0 kept models as models/<model2vec-12hex>/ directories with a
manifest graphersal-embed-model.json (format 2, with added_at), outside the history, carried
by every copy as files and by a packed snapshot as segment-table rows of kind 3. A store of
store format version 4 has no models/: the upgrade (15.1) migrates each such model into a blob
(the tar above, its manifest rebuilt from the old one) and one commit defines them all. A
packed snapshot with kind-3 rows imported into a store is migrated the same way (the new store's
first commit after the snapshot defines the models; into an open store each is imported).
4.6 Blobs
A blob is an immutable file of the store, named by the hash of its content and referenced
from values by a blobref (3, tag 21): hash_algo, the hash, the content's length and its
CRC-32C. The hash is the blob's identity (computed when the content is written or arrives from
outside, and by a verification); the CRC-32C checks every read; the length is checked, and used
for memory decisions, before reading.
blobs/
3f/3fa1...e9 a SHA-256 blob: blobs/<first 2 hex digits>/<64 hex digits>
algo-<n>/3f/3fa1... a blob of another algorithm n (2..255): its own directory
tmp-<32 hex digits> a blob being written (never listed, removed on open)
- Names are lowercase hex; a blob file holds exactly the content, uncompressed. Anything else
under
blobs/is invalid (a verification lists it). - Writing. The content is streamed into
blobs/tmp-<random>while its SHA-256, CRC-32C and length are computed (constant memory), the file is synced; when a blob of that hash exists and its length and CRC-32C are intact the new file is dropped (deduplication), otherwise (none, or a damaged one) the file is renamed to its name and both directories are synced. The commit that references the blob comes AFTER. Several writers may write the same blob at once. - Reading. A missing file, a length other than the reference's and a CRC-32C mismatch are failures of that blob only. A reader checks the length before it allocates.
- Referenced set. A blob is kept exactly as long as some retained history references it
(12.4): the blob tables of the snapshots (6.2 item 5), the ledger (10.1) and the attic
entries' WAL. A blob no retained history references is removed by a prune, an attic removal
or a rollback
delete(12.4, 12.5); a blob written and not yet referenced by a durable commit is kept by the writer that wrote it until its commit. - Damage. A missing or damaged blob is NOT damage of the store (13): the damage policy does not apply, the store keeps working, and only what needs the blob's bytes fails. Any copy of a blob with the same hash is the same bytes.
- The version walk (15) does not read
blobs/(a blob may hold any bytes) norledger.
4.7 The system journal
The system journal (book page "System Journal") holds operational events of the instances that
wrote the store: opens and closes, checkpoints, backups, prunes, damage, rollbacks, permission
denials. Nothing reads it to decide anything: a missing, cut or damaged journal changes nothing
of the store, is never damage (13) and never stops an operation; verify lists its problems as
notes (12.9).
INSTANCE (instance data: never copied by any copy path, an upgrade into a copy included;
regenerated when missing or unreadable):
magic "GRSLINST" | version u32 = 1 | instance id 16 bytes (big-endian) | reserved 28 bytes, zero
| CRC-32C u32 of bytes 0..56 | name (LEB128 length + UTF-8) | CRC-32C u32 of the name's bytes
The id is a random version-7 UUID, the name the configured instance name, else the host name.
Segments journal/<20 digits>.jnl: the name is the first seq the segment may hold. A
segment starts with a 64-byte header:
| Offset | Size | Field |
|---|---|---|
| 0 | 8 | magic GRSLJRNL |
| 8 | 4 | file format version (15) |
| 12 | 16 | the instance id that writes the segment (big-endian) |
| 28 | 8 | the first seq it may hold (= the file name) |
| 36 | 8 | created at, µs |
| 44 | 16 | reserved, zero |
| 60 | 4 | CRC-32C of bytes 0..60 |
Then record frames (26 bytes + payload):
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | sync marker u32 0x4A525347 (bytes 47 53 52 4A; not the WAL's) |
| 4 | 4 | payload length (at most 1 MiB; checked before allocating) |
| 8 | 8 | seq |
| 16 | 1 | level: 0 error, 1 warn, 2 notice, 3 info (a larger value is shown as info) |
| 17 | 1 | reserved, 0 |
| 18 | 4 | CRC-32C of bytes 0..18 |
| 22 | 4 | CRC-32C of the payload |
| 26 | n | payload (uncompressed) |
payload = origin 16 (big-endian) | origin_seq u64 | time i64 (µs) | source | kind | message
| presence u8 (bit 0 op, bit 1 parent, bit 2 commit, bit 3 principal; other bits:
newer content, kept)
| [op u64] [parent u64] [commit u64] [principal]
| fields: a property map with inline keys (3)
| origin name (strings: LEB128 length + UTF-8)
- A record's
seqis local and never reused: the next writer continues after the last valid record of the newest segment (after a damaged newest segment, after its name plus the frames it holds).(origin, origin_seq)identifies a record across copies; records of another origin keep theirs. - Torn tail and damage follow 9.6: a frame cut by a crash at the end of the newest segment is a torn tail, cut by the next writer; a frame whose header CRC fails is skipped by resyncing on the next sync marker with a valid header CRC, one whose body CRC fails by its length. Sealed segments (every one but the newest) never change.
- A new segment starts when the current one exceeds its size (default 4 MiB), when the instance of the open differs from the newest segment's header (a restored copy, another machine), when the newest segment has another file format version or damage, and after a failed write.
- An unknown kind, level or presence bit is shown, never damage (16 rule 9); a field value of a
newer value tag makes only that record's fields unreadable (shown as
fields_unreadable). - Writing:
errorrecords are written and synced at once; the others are written in batches (before a checkpoint, by the instance's periodic flush, at close). A read-only open (a backup, maintenance mode, 16 rule 3) and a store in which damage was found while it is open (13.3, either policy) write no journal records; their new records stay in memory. - Copies: 12.6 to 12.8 and 12.11 carry the journal; a fork, an attic fork and a repair do not (a
new store: its first record
store.creatednames the source); a packed snapshot (8) does not.
5. The GRAPH file
5.1 Layout
A fixed part of 256 bytes, followed by the lineage chain:
| Offset | Size | Field |
|---|---|---|
| 0 | 8 | magic GRSLGRPH |
| 8 | 4 | store format version (u32, 3; see 15) |
| 12 | 4 | state: 0 = closed cleanly, 1 = open (a writer has it, or it was not closed cleanly); another value in an intact file (both checksums valid) is a newer writer's: the store is refused as unsupported, never damage (16 rule 9) |
| 16 | 16 | graph_id of the current lineage |
| 32 | 8 | created at (time) |
| 40 | 4 | lineage entry count n (at least 1) |
| 44 | 4 | chunk target size in bytes, fixed when the store is created |
| 48 | 4 | flags (5.2) |
| 52 | 8 | WAL cut: segment (its first commit_seq); zero unless flag bit 1 |
| 60 | 8 | WAL cut: byte offset in that segment; zero unless flag bit 1 |
| 68 | 8 | backup marker: the last commit the backup holds; zero unless flag bit 2 |
| 76 | 8 | backup marker: taken at (time); zero unless flag bit 2 |
| 84 | 8 | wal_head: the first commit_seq (the name) of the newest WAL segment; zero unless flag bit 3 |
| 92 | 8 | closed_at: the last commit at a clean close; zero unless flag bit 4 |
| 100 | 16 | store_id: the store's identity, random, never zero (5.5) |
| 116 | 136 | reserved, zero |
| 252 | 4 | CRC-32C of bytes 0..252 |
| 256 | 32 × n | lineage entries, newest first: graph_id (16), branched at commit_seq (u64), at time (i64) |
| 256 + 32n | 4 | CRC-32C of the lineage entries |
The file's length MUST be exactly 256 + 32n + 4. The first lineage entry's graph_id MUST
equal the one at offset 16. The root entry (the last) has branched at 0. A store_id of zero
is invalid (the file is damaged).
5.2 Flags
| Bit | Meaning |
|---|---|
| 0 | reserved for parity data; MUST be 0 in store format versions 2 and 3 |
| 1 | a WAL cut is recorded (offsets 52, 60; 12.2) |
| 2 | the store is a backup (offsets 68, 76; 12.6) |
| 3 | wal_head is recorded (offset 84; 9.8) |
| 4 | closed_at is recorded (offset 92; 9.8) |
| 5 | the damage policy is continue (13.3); clear: maintenance, the default |
| 6..31 | reserved; a writer MUST preserve unknown bits it read |
Bit 5 is a creation parameter like the chunk target size (offset 44): it is set when the store
is created and never changed; every writer of GRAPH keeps it, and every copy of the store
(fork, repair, conversion, backup, restore, a backup from memory) carries it. A reader that does
not know it treats the store as maintenance, the safe default. A repair that finds both GRAPH
copies unusable cannot read it and writes the default.
A GRAPH file without bits 3 and 4 (written before they existed) means "unknown": the checks
of 9.8 are skipped.
5.3 Two copies
GRAPH is written as two files, GRAPH.copy first and then GRAPH, each through a temporary
name (<name>.tmp), fsync and an atomic rename; then the directory is synced. A reader uses:
both valid and equal, either; both valid and different, the one with the longer lineage chain,
on a tie GRAPH.copy (it was written first, so it is the newer); one valid, that one. A
read-write open that found the copies different or one of them invalid rewrites both (and
reports it). Both invalid is damage (13).
5.4 The lineage chain
The chain records every lineage the store descends from. A fork's chain is
[new id, branched at the target commit, time] followed by the parent's chain; an in-place
rollback adds such an entry in the same store; a repair starts a new lineage whose chain
continues the damaged store's. An ancestor lineage is valid only up to the branched at of its
child entry: a WAL record of an ancestor beyond that commit does not belong to this store's
history. A file (a WAL segment, a snapshot manifest) whose graph_id is not on the chain MUST
NOT be replayed.
5.5 The store identity
store_id (offset 100; new in store format version 2) identifies the STORE, where graph_id
identifies a lineage of its data. It is a creation parameter: a create writes a new random one
(128 bits, like a lineage id), and every writer of GRAPH keeps it. A fork, an attic fork (12.5), a repair (13.4) and a conversion
to another backend are new stores with a new store_id (their lineage chain still names the
parent); an in-place rollback, an attic restore, a compaction, a restored backup (12.6, 12.8)
and an upgrade (15.1) keep it: a restore IS the store, an upgrade is the same store in a new version. Every backup (full, increment, ZIP, from memory) records its
source's store_id, and an increment requires it to be equal (12.7).
6. The snapshot manifest
manifest = fixed part (4096) | variable part | CRC-32C of the variable part (u32) | copy of the fixed part (4096).
6.1 Fixed part
| Offset | Size | Field |
|---|---|---|
| 0 | 8 | magic GRSLMANI |
| 8 | 4 | format version |
| 12 | 4 | flags (bit 0: incremental, the segment table references files of older snapshots; other bits reserved) |
| 16 | 16 | graph_id |
| 32 | 16 | parent graph_id (zero if none) |
| 48 | 8 | parent commit_seq |
| 56 | 8 | commit_seq: every commit up to and including it is contained |
| 64 | 8 | created at (time) |
| 72 | 8 | last commit at: the time of the commit at commit_seq |
| 80 | 8 | node_sequence: the vertex auto-id sequence |
| 88 | 8 | edge_sequence: the edge auto-id sequence |
| 96 | 8 | vertex count |
| 104 | 8 | edge count |
| 112 | 8 | vertex property count |
| 120 | 8 | edge property count |
| 128 | 8 | estimated in-memory bytes of the loaded graph (lets a loader refuse a snapshot that does not fit a memory budget before reading it) |
| 136 | 8 | schema.json length |
| 144 | 4 | schema.json CRC-32C |
| 148 | 4 | segment count |
| 152 | 8 | offset of the variable part: 4096 |
| 160 | 8 | length of the variable part: from offset 4096 up to, not including, its CRC |
| 168 | 2 | name length (bytes, at most 255) |
| 170 | 255 | name: UTF-8, name length bytes followed by zeros (optional, human-readable) |
| 425 | 3 | reserved, zero |
| 428 | 4 | chunk target size in bytes |
| 432 | 3660 | reserved, zero |
| 4092 | 4 | CRC-32C of bytes 0..4092 |
Listing the snapshots of a store reads only the first 4096 bytes of each manifest. A reader uses the head copy and falls back to the tail copy when the head's CRC fails.
6.2 Variable part
In this order:
- meta:
string(empty = none). Free-form text the format never interprets. - Segment table:
segment countrows ofkind u8(1 vertex, 2 edge, other kinds 7.5; 0 is invalid) |path string|first id string|last id string|element count u64|byte length u64|CRC-32C u32of the whole segment file. Vertex rows precede edge rows, rows of other kinds follow the edge rows; vertex and edge rows of one kind are ordered by id range and their ranges never overlap. A path isv-NNNNNN.segore-NNNNNN.segin the snapshot's own directory, or, in an incremental snapshot (flag bit 0), a reference: a name relative tosnapshots/such as00000000000000001000/v-000003.seg, exactly two parts, a 20-digit snapshot name and a file name (see References below). - Definitions: the definitions table (6.3).
- Chunk index:
uvarrow count, then rows ofsegment number u32(its position in the segment table; it MUST name a vertex or edge row) |chunk offset u64|first id string|last id string|chunk CRC u32(the value of 7.2), grouped by segment in table order. With it the id range of a damaged chunk is known even when the segment's own footer is damaged. - Blob table (file format version 4; absent in a manifest of an older version, which
references no blob):
uvarrow count, then rows of ablobrefpayload (3, tag 21, without the tag) |refs uvar(>= 1): every blob the snapshot's state references with the number of references, rows strictly increasing by(hash_algo, hash bytes). In this version only catalog definitions (6.3) reference blobs. A merged checkpoint (12.3) writes the table of its whole catalog, the same table a full encode writes. A packed export keeps it as it is.
schema.json holds the stored schema as canonical compact JSON (an empty schema of mode none
when the graph stores none); its length and CRC MUST match the manifest.
References (incremental snapshots). A reference names a vertex or edge segment file of an OLDER snapshot of the same store, unchanged; its row (kind, ids, count, length, CRC) and its chunk index rows are those of the referenced file. Rules:
- A manifest with a reference MUST have flag bit 0 set; a reference in a manifest without it, a
reference that is not
<20 digits>/<file name>, and a row of another kind than 1 or 2 with a/are invalid. - Every segment a manifest lists, a referenced one too, carries the manifest's
graph_idin its header (7.1): a snapshot of a new lineage (after an in-place rollback) references no file of an older lineage. - A reference is resolved in the directory that holds the snapshot:
snapshots/of the store, or of an attic entry (11.2) for a snapshot moved there; a referenced file not found next to a snapshot of an attic entry is resolved in the store's ownsnapshots/. - The referenced file may lie in a snapshot directory or in a holder (4.1). Reading, verifying and loading an incremental snapshot check the referenced files exactly like its own.
- A writer MUST NOT reference a file that the store's newest snapshot uses (the donor rule of 12.3): a new snapshot references only twins of the newest snapshot's files, held by the snapshot before it.
- A packed snapshot (8) is self-contained and has no references: writing one from an incremental
snapshot names each segment
v-NNNNNN.seg/e-NNNNNN.segby its position per kind and clears flag bit 0 (the manifest is re-encoded; the segment sections are the files' bytes).
6.3 The definitions table
The graph's catalog of definitions: named, typed entries stored in the database beside the schema (saved queries, property indexes, compression rules, scheduled jobs and embedding models today). One self-describing table serves every kind, present and future, so that a new kind needs no new layout and no new version (16).
definitions = uvar count | definition*
definition = kind u8 | flags u8 | name string | length uvar | payload (length bytes)
flags = bit 0: critical (a reader that does not know `kind` MUST NOT write the store, 16);
bits 1-7 reserved: written as zero, preserved as read
payload = property map (3) with inline keys (as in a WAL record)
- The rows are ordered by
kind, then bynamebytewise, strictly increasing: a kind and name appear at most once. A table out of this order is invalid. lengthMUST NOT exceed the bytes that remain; the payload is exactlylengthbytes.- The payload of every kind, known or not, is a property map. Its keys MUST NOT be
kind,nameorflags: these are the envelope keys of the exchange form of a definition, a JSON object that puts the payload keys beside them. A writer never writes such a key; a reader that decodes the payload treats one as invalid. - A reader that knows the kind decodes the payload. A payload that is not a valid property map
(truncated or invalid bytes, trailing bytes, a repeated or reserved key) is damage (13; a
repair takes the catalog from a donor, 13.4). A valid map is NEVER damage (16 rule 9): keys
the reader does not know are ignored and kept (16 rule 1); an unknown VALUE of a known key it
can represent (a compression
codec,elementorpath, an indexelement,typeortransform, a saved query's parameter schema) keeps the definition, not served, its payload written back exactly as read; a map it cannot read as its kind at all (a missing or mistyped known key) keeps the definition as opaque bytes like an unknown kind (16 rules 2 and 3). - A reader that does not know the kind keeps the definition as opaque bytes (kind, flags, name, payload) and writes it back unchanged (16 rules 2 and 3).
- A load does not validate a definition beyond this (as it does not validate data against the schema, 12.1); a saved query whose source no longer compiles is loaded and fails when called.
| Kind | Definition |
|---|---|
| 0 | invalid |
| 1 | saved query |
| 2 | property index |
| 3 | compression rule |
| 4 | scheduled job of a user (since 0.3.0) |
| 5 | embedding model (since 0.5.0, 4.5) |
| 6 | property index of an extended form (since 0.6.0): a label-less index; always critical |
| 7..127 | unassigned (assigned only by this format) |
| 128..255 | host kinds: reserved for applications built on the library, never assigned by this format (16 rule 8) |
An embedding model (kind 5, not critical: a reader that does not know the kind keeps it and
serves no model) is named by the model identity (model2vec/<repo>@<12 hex>, at most 256 bytes;
for a family the reader does not know, any name of 1 to 256 bytes). Its payload keys, in this
order, followed by the keys the writer does not know:
| Key | Value |
|---|---|
blob | blobref (3, tag 21): the model's tar (4.5) |
family | string: model2vec; another family is kept, written back unchanged, not served |
repo | string: the repository, the model's user-visible name (required) |
revision, commit | strings (optional) |
dimension | int64: the vector dimension |
load_bytes | int64: the import's estimate of the memory the loaded model takes (the f32 embedding matrix plus the tokenizer file). Still written; read by the memory check of versions up to 0.5.2 only (later versions check the blob's length times 1.6 and show the size measured at the load) |
license, license_text | strings, as the manifest's (4.5) |
base_models | array of {repo, license?} |
gated | boolean |
default | boolean, absent = false: the default model |
A catalog holds at most one model per repo (the current revision) and at most one default
(a writer refuses a second; a replace drops the old revision and defines the new one in one
commit). A model of an unknown family or blob hash algorithm is kept, listed as unsupported and
written back unchanged, never loaded.
A saved query (kind 1) is one Rhai function (or one GQL query) stored as text and called by
name; its name is
an identifier ([A-Za-z_][A-Za-z0-9_]*, at most 128 bytes). Its payload keys, written in this
order, followed by the keys the writer does not know in the order it read them:
| Key | Value |
|---|---|
folder | string: a /-separated folder path; absent = the root |
description | string; absent = none |
dialect | string: the language and content version of source: "graphersal-rhai/1" (a Rhai function that reads), "graphersal-rhai/2" (a Rhai function that may write), "graphersal-gql/1" (a GQL query that reads), "graphersal-gql/2" (a GQL query that writes); a reader that does not run a dialect keeps the query unchanged and lists it as not runnable |
source | string: the Rhai function text, or the GQL query text |
params | string: canonical compact JSON of an object, parameter name -> {"schema": <schema node>, "default": <value>} (default absent when the parameter has none), in declaration order |
meta | string, free, never interpreted; absent = none |
source is required; every other key is optional. The text is stored, never a compiled plan:
every call plans it anew. A params value the reader cannot read (a schema keyword or a
parameter form of a newer writer) keeps the query: it is listed with the reason, written back
exactly as read and refused when called (since 0.2.1; the exchange form a user imports stays
strict).
A compression rule (kind 3, not critical) keeps the strings of one element kind and label at one property path compressed in memory (book page "Compressed Properties"). Its name is an identifier as for a saved query. The data in snapshots and the WAL is ALWAYS plain: the rule describes only the in-memory representation, so a reader that does not know the kind loses nothing but the compression, and a load compresses the rule paths again. Its payload keys, in this order, followed by the unknown keys:
| Key | Value |
|---|---|
element | string: "vertex" or "edge" |
label | string: the label |
path | string: canonical jpath text of object keys only ($.details.career.cv) |
codec | string: "lz4" (each value compressed) or "dedup" (each distinct value held once in memory; since 0.2.1; on a top-level key every value type since 0.6.0) |
min_bytes | int64: strings shorter than this (UTF-8 bytes) stay plain, 1 to 16777216 (lz4), 0 to 16777216 (dedup; 0 since 0.6.0, which 0.5.2 and older refuse) |
dictionary | boolean: whether the load builds a dictionary from the rule's values (lz4 only; true with "dedup" is invalid) |
label and path are required; element defaults to "vertex", codec to "lz4",
min_bytes to 256 (lz4) or 0 (dedup; 25 before this version, whose rules always stored it), dictionary to true (lz4) or false (dedup);
writers always write min_bytes and dictionary. A codec or an element the reader does not
know, or a path it cannot parse (a newer writer's), is NOT damage and needs no new format
version (16 rules 1 and 9): the reader keeps the definition, writes its payload back exactly as
read (every key, in the order read), does not apply it (the values stay plain in memory as on
disk) and lists it as not applied with the reason; a front end never creates such a rule. The
codec changes no stored data, which stays plain. Two rules with the same element, label and
path (compared as read) are invalid (a writer refuses the second).
0.2.0 decodes an unknown
codecas an invalid payload, that is as damage: it reads a store holding adeduprule (0.2.1) as damaged from that commit on and proposes a repair that would drop commits. Open such a store with 0.2.1 or later only; 0.2.1 and later follow the rule above.
A scheduled job (kind 4, not critical; since 0.3.0) runs an action on a cron schedule (book page "Scheduled Jobs"). Its name is an identifier as for a saved query. A reader that does not know the kind keeps it and never runs it. Its payload keys, in this order, followed by the unknown keys:
| Key | Value |
|---|---|
schedule | string: a 5-field cron schedule, at most 256 bytes |
action | string: "query", "checkpoint" or "backup" |
query | string: the saved query a query job calls (query jobs only) |
args | object: its arguments by parameter name (query jobs only) |
path | string: the directory a backup job writes (backup jobs only) |
enabled | boolean |
timeout_ms | int64: the longest a run may take, in milliseconds; absent = no limit |
memory_limit | int64: the most memory a run may use, in bytes; absent = no limit |
run_on | string: "any", "primary" or "replica" (for replication); absent = "any" |
description | string; absent = none |
effects | list of objects: what the definer was allowed when the job was defined, each {"action", "resource", ..} with action one of "read", "create", "update", "delete", "execute" and resource "data" (+ element, label when stated), "file" (+ path) or "definition" (+ kind as its number, name) |
schedule and action are required; enabled defaults to true, effects to none. A run may
do exactly the stored effects (and read). An action, a run_on value or an effect form the
reader does not know is NOT damage (16 rules 1 and 9): the reader keeps the job, writes its
payload back exactly as read, never runs it and lists it as not served with the reason.
A property index (kind 2, not critical) orders the elements of one element kind and label by the value of one top-level property (book page "Property Indexes"). Its name is an identifier as for a saved query. Only the declaration is stored: snapshots and the WAL hold NO index entries, a load builds them from the data, so a reader that does not know the kind loses nothing but the speed-up. Its payload keys, in this order, followed by the unknown keys:
| Key | Value |
|---|---|
element | string: "vertex" or "edge" |
label | string: the label |
key | string: the top-level property name (not a jpath) |
type | string: the index type, "memory-ordered" (an ordered index in memory whose entries a load builds from the data) |
transform | string, optional: the transform of the index keys, "to_lower" (the lowered text of string values, as the step to_lower() computes it; other values are not in the index); absent for an index of the values themselves |
label and key are required; element defaults to "vertex", type to "memory-ordered"
(a payload written before the key existed has none), transform to none. A writer of this
version always writes type and writes transform only for an index with a transform. Two
indexes with the same element, label, key, type and transform are invalid (a writer
refuses the second); indexes of different types or transforms may cover the same key. A type,
a transform or (since 0.2.1) an element the reader does not know (a newer writer's) is NOT
damage and needs no new format version (16 rules 1 and 9): the reader keeps the definition,
writes its payload back exactly as read (every key, in the order read), builds no entries for it
and serves no query from it. A store written before this kind was decoded never holds it (kind 2
was reserved), so no format version changes.
A property index of an extended form (kind 6, property_index_ext, since 0.6.0) is a
property index whose meaning a reader must know to keep it exact: today a label-less index,
which orders every element of its element kind (unlabeled ones included) by the value of one
top-level property, an index whose transform starts with each (one entry per element
of a list value; also with a label), and a unique index (also with a label: a reader that
does not know it would write past the constraint). It is ALWAYS written with the critical flag (bit 0 of the flags), so a
reader that does not know kind 6 opens the store read-only (16 rule 3) instead of writing data
without maintaining the index; a plain per-label index stays kind 2, not critical. The payload
keys are those of kind 2; label is OPTIONAL (absent: label-less), transform is a string (one
transform: to_lower, each) or an array of strings (a chain applied in order; this version
serves ["each", "to_lower"], any other order or name keeps the definition, not served),
unique is a boolean (absent: false; a writer writes it only when true; a non-boolean is a
malformed payload; with each the definition is kept, not served), and the rest is read as for
kind 2 (an unknown type, transform or element keeps the definition,
not served). Index
names are one namespace across kinds 2 and 6: a writer never stores the same name in both (it
replaces one by the other in one commit). Two indexes of kinds 2 and 6 with the same element,
label, key, type and transform are invalid (unique is not part of that identity). Like
kind 2, only the declaration is stored: a reader rebuilds a unique index from the data, and data
that holds a key twice keeps the definition but neither serves nor enforces it (never damage).
A store written before 0.6.0 never holds kind 6 (it was unassigned), so no format version
changes.
7. Segment files and chunks
segment = header (64) | chunk* | footer. A segment holds elements of one kind, in strictly
increasing id order across its chunks.
7.1 Header
| Offset | Size | Field |
|---|---|---|
| 0 | 8 | magic GRSLSEGM |
| 8 | 4 | format version |
| 12 | 1 | kind: 1 vertex, 2 edge |
| 13 | 1 | default codec (informative) |
| 14 | 2 | zero |
| 16 | 16 | graph_id |
| 32 | 4 | chunk count |
| 36 | 8 | footer offset |
| 44 | 16 | reserved, zero |
| 60 | 4 | CRC-32C of bytes 0..60 |
7.2 Chunks
chunk = uncompressed length u32 | stored length u32 | codec u8 | element count u32 | chunk CRC u32 | stored bytes.
The chunk CRC covers the first 13 header bytes (both lengths, the codec, the element count) followed by the stored bytes, so a damaged length or codec is detected too. Chunks start right after the header and end exactly at the footer offset. The uncompressed payload (2.1) is the chunk payload (7.3), which its elements fill exactly. A chunk's uncompressed size is close to the store's chunk target size (default 1 MiB); the chunk is the unit of repair (13.4).
7.3 Chunk payload
payload = string table | element* (element count elements)
string tbl = uvar n | string*n labels and property keys of this chunk
vertex = id string | uvar label count | uvar label ref * | property map
edge = id string | label uvar (0 = none, else ref + 1) | out id string | in id string | property map
A chunk is self-contained: its own string table holds every label and property key it uses (string values stay inline), so any chunk decodes alone. References are indexes into that table; a reference outside it is invalid. A vertex's labels are a set (a repeated label is invalid); its first label is its primary label. In a property map and in object values inside a chunk, keys are table references. An edge with an empty property map and one without properties are the same (count 0).
7.4 Footer
footer = (chunk offset u64 | first id string) per chunk | CRC-32C u32 of the footer bytes before it.
The footer allows a binary search by id without reading every chunk.
7.5 Files of other segment kinds
Large data of a future feature (an index, statistics) lives in files of its own, not in the
manifest (16 rule 5): a row of the segment table with another kind than 1 and 2 names such a
file. Its path is a plain file name in the snapshot's own directory (4.2), its byte length and
CRC-32C are those of the whole file; first id, last id and element count belong to the
kind (a reader that does not know it ignores them). The file's content belongs to the kind; no
chunk index row names it.
- Kinds 3..127 are ignorable: a reader that does not know the kind checks the file's length and CRC like any segment (a mismatch is damage), copies it wherever the snapshot is copied file by file (backup, import and export of the packed form, 8) and otherwise ignores it. Such a file holds data derived from the snapshot; a writer that does not know the kind does not carry it into a new snapshot (a checkpoint, fork or repair), and a writer that knows it rebuilds it.
- Kinds 128..255 are critical: a store whose base snapshot has such a row opens read-only for a reader that does not know the kind (16 rule 3).
Assigned kinds: 3, an embedding model's file (4.5), written only into packed snapshots (8):
path is <model id>.<file name> (a plain name, at most 64 bytes), first id the model id,
last id the file name, element count 0. A reader that knows the kind puts the file into
models/<model id>/<file name> of the store a packed snapshot is imported into (never into the
snapshot directory) and checks each model against its manifest (4.5); it treats a kind-3 row
of a snapshot directory (one a reader without models imported) as a model file when it exports
the snapshot again.
4, a blob (4.6), written only into packed snapshots (8), after the snapshot's own rows:
path is the blob's hash as lowercase hex (64 digits for SHA-256: a plain name), first id
the algorithm's name (sha256), last id empty, element count 0; the byte length and CRC-32C
are the blob's, and the manifest's blob table (6.2 item 5) names it. A reader that knows the
kind checks the file's SHA-256, length and CRC-32C against the table (foreign input), puts it
into blobs/ of the store a packed snapshot is imported into and does not keep the row in the
stored manifest; a reader without a store skips it like every ignorable file.
128, the layer file of a layer snapshot (critical). A layer is a graph stored as its
changes to a frozen base graph (book page Layered Graphs); its snapshot holds only those
changes and loads only over that base. Such a snapshot is an ordinary snapshot whose vertex and
edge segments hold only the elements the layer added (also edges at base vertices, which
name their endpoints by id like every edge, 7.3), whose manifest holds the layer's own schema,
whole catalog, lineage id, position, commit time and auto-id sequences (6), and whose segment
table has exactly one row of kind 128 after the edge rows: path layer.bin, first id the
base's lineage id as canonical UUID text, last id <commit_seq>@<committed at> of the base
(both decimal, the commit time as in 2), element count the number of entries below. The
manifest's vertex, edge and property counts (6.1) are those of the layer's own elements, its
memory estimate is the layer's own footprint (the base is shared, not counted). The file:
layer file = magic "GRSLLAYR" | format version u32 (5) | base graph_id (16) | base commit_seq u64
| base committed at i64 | entry count u64 | entry*
entry = 1 | id string removed base edge
| 2 | id string removed base vertex (and its base edges)
| 3 | id string | uvar n | label string * n | property map base vertex image
| 4 | id string | label opt_string | 0 | 1 property map base edge image
| 5 | kind u8 | name string removed base definition
- The base reference (
graph_id,commit_seq, committed at) is the identity of the base the layer was built over: its lineage id (5.4, 6.1) and the position and commit time of its state. It is written twice, in the file's header and in the row's ids, and both MUST agree. A reader MUST refuse to load the snapshot over a base of another identity, before it reads any segment (the row is in the manifest). The commit time tells two branches apart that reached the samecommit_seqafter an in-place rollback (12.5); a store id is not part of it, so a packed export of the same base state is the same base. - Entries name base elements by id, never by position: ids are stable across loads of
the same base state, slots are not. An image is the element's whole state in the layer: the
vertex's labels in order (the first is primary) and its property map; the edge's label
(
opt_string, none = unlabeled) and, after a marker byte,0for "no property map" or1and its property map. Property maps are those of 3 with inline keys (as in a WAL record, 9.3), values the tagged values of 3. A removed definition names a definition of the base's catalog (6.3) the layer removed (the layer's catalog starts as a copy of the base's). Other entry types are invalid in this version; the file's own format version guards them like a record type (15). - Entry order: removed base edges, removed base vertices, vertex images, edge images, removed definitions. Removing an element twice (an edge taken by a removed vertex) changes nothing; an image of a missing or removed base element is invalid.
- Load order. A reader builds a fresh layer over the base, applies the schema and the catalog (6), then EVERY entry, then the layer's vertex and edge segments (an added element may reuse the id of a base element the layer removed), then rebuilds what it derives. In a stream the layer file follows the element segments (8), so a reader holds the checked segment bytes until it has read the layer file: memory in proportion to the layer's snapshot, never to the base.
- A reader that knows the kind MUST refuse to load a layer snapshot as a whole graph and a whole-graph snapshot (no kind-128 row) into a layer. A layer writes no embedding model and carries no blob (4.5, 4.6): its catalog's model definitions are copies of the base's, whose blobs stay with the base.
- Version. A layer snapshot's packed header (8), its manifest (both fixed-part copies, 6.1) and its layer file carry file format version 5; its vertex and edge segments keep version 4 (nothing in them differs). A reader of file format version 4 (Graphersal 0.6.x and before) therefore refuses a layer snapshot as written by a newer version (15), as a packed snapshot and as a snapshot directory of a store, and never takes the layer's own elements for a whole graph. Version 5 belongs to layer snapshots only: a packed header or manifest of version 5 without a kind-128 row, and a version 5 in any other file, is of a newer version than this specification (refused, never damage); a layer snapshot under a version word below 5 is invalid. Every other file is written in version 4.
8. The packed snapshot
A packed snapshot (.gsnap) is a whole snapshot in one stream:
packed = magic "GRSLPACK" | format version u32 | section count u32 | section* | trailer
section = kind u8 | length u64 | bytes
trailer = CRC-32C u32 of every byte before it, from the magic on
| Section kind | Content |
|---|---|
| 1 | the manifest (6) |
| 2 | schema.json |
| 3 | a vertex segment (7) |
| 4 | an edge segment |
| 5 | a named extra file: name string followed by the file's bytes; the file of a segment-table row of another kind (7.5), name = the row's path (a blob, a model file, the layer file of a layer snapshot) |
| 0, 6..255 | invalid |
A packed snapshot exported from a store carries the store's embedding models (4.5) unless the
export leaves them out: each model file is a segment-table row of kind 3 (7.5) after the
snapshot's own rows, so a named extra file (section kind 5), each model's manifest after its
other files. The manifest of the packed snapshot is re-encoded with those rows (its checksums
recomputed); the snapshot's own rows and chunk index are unchanged. Importing the packed
snapshot into a store moves the model files into models/ and writes the snapshot's manifest
without their rows.
The sections appear in this order: the manifest, schema.json, the vertex segments, the edge
segments, the named extra files, each in the manifest's table order; the section count is 2 + the
manifest's segment count, and each section's length MUST equal what the manifest records for it
(for kind 5: the length of name as a string plus the row's byte length; the file's bytes MUST
match the row's length and CRC). A new file type therefore needs no new section kind. The manifest and
schema.json sections are at most 256 MiB each. The sections are byte-identical to the files of
a store's snapshot directory, so a store imports and exports packed snapshots by copying, and a
directory snapshot can be read as the packed stream it is equivalent to. A reader of a
non-seekable stream checks each section's CRC as it streams and the trailer at the end; nothing
follows the trailer.
Writing without seeking (informative). The manifest precedes the segments, every section
starts with its length, and a segment file starts with its chunk count and footer offset (7.1),
so a writer must know every segment's length, CRC and chunk index before it writes the first
segment byte. A writer that neither seeks nor holds the encoded snapshot can plan first: encode
every chunk once and keep only its size, CRC and first and last id; write the header, the
manifest and schema.json; then encode each chunk again from the same elements and write it.
Chunks are self-contained (7.3), so with a deterministic compressor the second encoding yields
the planned bytes; the reference writer checks every chunk's CRC against its plan and fails on
a difference (the graph must not change in between). A segment's CRC covers its header, which
is known only after the chunks; it is the CRC-32C combination of the header's CRC and the CRC
of the rest. A store writes a snapshot directory the same way, each segment file as soon as its
plan is complete and the manifest last, holding one chunk at a time.
9. The write-ahead log
The WAL is a sequence of segment files. Over a plain stream (a journal outside a store) the same bytes are one segment that is never rotated.
9.1 Segment header
| Offset | Size | Field |
|---|---|---|
| 0 | 8 | magic GRSLWALS |
| 8 | 4 | format version |
| 12 | 16 | graph_id of the lineage that writes the segment |
| 28 | 8 | first commit_seq the segment may contain |
| 36 | 8 | created at (time) |
| 44 | 16 | reserved, zero |
| 60 | 4 | CRC-32C of bytes 0..60 |
In a store the file name is the first commit_seq as 20 decimal digits; a header whose first
commit_seq differs from its file name is damage (9.8).
9.2 Record frame
A record is a 25-byte frame followed by its payload:
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | sync marker 0x47525357 (bytes 57 53 52 47) |
| 4 | 4 | payload length |
| 8 | 8 | commit_seq: a Commit's own number; for a Mark or Checkpoint, the commit it refers to |
| 16 | 1 | record type |
| 17 | 4 | header CRC-32C of bytes 0..17 |
| 21 | 4 | body CRC-32C of the payload |
| 25 | length | payload |
| Type | Record |
|---|---|
| 1 | Commit (9.3) |
| 2 | Mark (9.4) |
| 3 | Checkpoint (9.5) |
| 4 | Commit part (9.3.1; file format version 4 and later) |
| 0, 5..255 | reserved: an unknown type is invalid, never skipped |
Type 4 is valid only in a WAL segment whose header (9.1) states file format version 4 or later; in an older segment it is an unknown type.
The sync marker and commit_seq lie outside the possibly compressed payload, so a reader can
resynchronise after a damaged record by searching for the next position that holds the sync
marker, a valid header CRC and a valid body CRC. The separate header CRC makes a damaged length
detectable, so it is never taken for an interrupted write (9.6). A record is never split between
segments, and neither is a commit: the parts of a commit in parts (9.3.1) are consecutive
records of one segment.
9.3 Commit payload
commit = commit_seq u64 | time i64 | node_sequence u64 | edge_sequence u64 | codec u8 | body'
body' = body when codec = 0
| uncompressed length u32 | stored body when codec = 1 or 2
body = principal opt_string | attributes property map | uvar mutation count | mutation*
commit_seq MUST equal the frame's. The auto-id sequences are written with every commit so
that an id handed out before a crash, a drop or a rollback is never handed out again after a
recovery. A writer writes a commit whose body is at most the part size (64 MiB) as this one
record, and a larger one in parts (9.3.1); a reader accepts a single-record body up to 1 GiB
(the bound of section 2). A commit with a mutation count of 0 is valid: a sequence-only commit, a unit that
changed nothing but raised an auto-id sequence (applying a change set whose mutations were all
compacted away); replaying it only raises the sequences (and advances the commit position). The
attributes are free metadata of the commit (keys inline). Every string is inline.
| Op | Mutation | Fields |
|---|---|---|
| 1 | AddVertex | id string | uvar label count | label string* | property map |
| 2 | DropVertex | id | before: labels (as in AddVertex) | property map |
| 3 | AddEdge | id | label opt_string | out id | in id | property map |
| 4 | DropEdge | id | before: label opt_string | out id | in id | property map |
| 5 | SetProperty | element kind u8 (1 vertex, 2 edge) | id | key string | before value (tag 255 = absent) | after value |
| 6 | RemoveProperty | element kind | id | key | before value |
| 7 | AddLabel | vertex id | label |
| 8 | RemoveLabel | vertex id | label |
| 9 | SetSchema | before schema string | after schema string (canonical JSON) |
| 10 | SetDefinition | kind u8 | name string | before opt(definition) | after opt(definition) |
| 11 | SetEdgeLabel | edge id | before label opt_string | after label string |
opt(definition) is u8 0 for none, or u8 1 followed by a definition encoded as in the
definitions table (6.3); other presence bytes are invalid. Op 10 serves every definition kind,
so a new kind needs no new op: a define has no before, a removal no after, a change (replace,
move, describe) both; at least one is present, and each present image MUST carry the op's kind
and name. A definition the reader cannot decode follows 6.3: an unknown kind is kept opaque
(and replayed as such), a payload of a known kind that is not a valid property map is damage,
and a valid map is never damage (kept, not served, or kept opaque; 16 rule 9). A writer MUST NOT write an
after image that is a critical definition of a kind it does not know (16 rule 3).
Mutations are in execution order. Before images are always present: a reader can reconstruct the state before each commit, and CDC consumers get before and after values. The edges a vertex drop removes appear as DropEdge mutations before the DropVertex. A write to a nested path inside a property is a SetProperty of the top-level key.
A schema (op 9) may declare vector rules: a vector property with an embedder and a from
property (book page "Vector Rules"). The vectors a rule computes are ordinary SetProperty and
RemoveProperty mutations of the commit that changed their source (or of the commit that added
the rule, which fills every element of the label), written as they were computed. A replay, a
recovery, a merge checkpoint and every other reader apply them as recorded and MUST NOT embed:
replaying a commit never needs the model.
9.3.1 Commit in parts
A commit whose uncompressed body (9.3) is larger than the writer's part size (64 MiB) is
written as parts >= 2 consecutive records of type 4 (file format version 4); a commit up to
the part size stays one Commit record (type 1), unchanged.
frame = 9.2 frame, type 4, commit_seq = the commit's (equal in every part)
part payload = part u32 | parts u32 | part_body
part_body = (part = 0) commit_seq u64 | time i64 | node_sequence u64 | edge_sequence u64
| body_length u64 | slice
| (part > 0) slice
slice = codec u8 | data codec 0: data = the raw bytes
| codec u8 | uncompressed u32 | stored codec 1, 2 (as in 9.3)
- The uncompressed slices of parts
0..partsconcatenated arebodyof 9.3 (principal | attributes | uvar mutation count | mutation*); a mutation may span a part boundary. Each slice is compressed on its own (section 2.1). - A writer writes slices of
1..=part sizeuncompressed bytes (all but the last exactly the part size). A reader accepts any slice of 1 byte to 1 GiB (the bound of section 2) and requires their sum to equalbody_length. It never allocates frombody_lengthup front: the body grows per part, checked against what it may use. partsis2..=1048576(2^20, 64 TiB at 64 MiB per part) and equal in every part;partruns0..partswithout gaps;commit_seqof part 0 MUST equal the frame's. A commit needing more parts is refused by the writer (PersistError::CommitTooLarge, the unit rolls back).- The parts of one commit are consecutive records of ONE segment: no other record lies between them (rotation, 9.7, happens only before part 0).
- A commit in parts is ONE commit for every reader: its position (where a recovery cuts a torn tail, a rollback splits a segment, a backup compares records) is the start of part 0.
9.4 Mark payload
mark = commit_seq u64 | time i64 | name string.
A mark names the position right after commit commit_seq (recovering to it replays up to and
including that commit). Its time comes from the instance clock (section 2, "Time"): never earlier
than the last commit, nor than any other time the instance wrote. Mark names are unique
along a store's whole history (across lineages); a duplicate MUST be refused when it is set.
9.5 Checkpoint payload
checkpoint = commit_seq u64 | time i64: informational, "a snapshot at commit_seq exists".
Readers accept and skip it. Commits newer than commit_seq MAY precede it.
9.6 Torn tail and damage
At the end of the last segment (of a recovery's last journal), the following are a torn tail, the remains of an interrupted write:
- fewer than 25 bytes that are a prefix of the sync marker (the first up to four bytes match) or all zero;
- a frame with a valid header CRC whose payload runs past the end of the file;
- zero bytes only, from a record boundary to the end (space the file system allocated that the interrupted write never filled).
A full frame header with a bad header CRC, a full record with a bad body CRC, and any other bytes at the end are damage, wherever they are, also in the last record. Anything that is not a valid record before the end of a segment that is not the last one is damage. A torn tail is cut off by the next read-write open (12.2), never by a reader; damage is never cut (13).
A commit in parts (9.3.1) at the end of the last segment with fewer than parts complete parts
(the last present one possibly torn by the rules above) is a torn tail too; it starts at part 0,
where it is cut. Damage, wherever it is: a part other than 0 not preceded by its predecessor, a
record of another type or commit_seq between parts, part or parts inconsistent, slices
whose sum differs from body_length, and an incomplete commit in parts before the end of a
segment that is not the last one. A resynchronisation (salvage, 13) that lands on a part other
than 0 skips to the next record that is a part 0 or of type 1, 2 or 3; a commit with a damaged
part is one damaged region covering all its parts.
9.7 WAL segments in a store
- Segments are named by the first
commit_seqthey may contain. Rotation is lazy: before a record (before part 0 of a commit in parts, never between its parts) is written, if the current segment exceeds the segment size (default 16 MiB) or a checkpoint asked for a new segment, the current file is synced, and a new segment named by the next commit sequence number is created with its header, synced, and its directory synced. A Mark or Checkpoint record may therefore be the first record of a segment namedcommit_seq + 1of the commit it refers to. Only the last segment can end in a torn record. - The replay set of a snapshot at position
Sis the last segment whose name is<= S + 1and every later one. Commit records<= Sare skipped; every later commit record MUST be exactly the previous + 1 (else the history has a gap: damage). - After an in-place rollback or a fork, the new lineage writes a new segment (its header carries
the new
graph_id). - A record whose write or sync failed is cut off again (the file truncated to the record's start,
for a commit in parts to the start of part 0, whatever part failed, and synced) before the
writer refuses further commits. When that cut fails, the valid end is
recorded in
GRAPH(flag bit 1); readers MUST read only up to it, and the next read-write open truncates the segment there and removes later segments.
9.8 The newest segment and a clean close
A cut of the last WAL record is indistinguishable from an interrupted write and is treated as a
torn tail. A segment that is missing, emptied or replaced by another segment's bytes must never
be: it would silently open the store at an earlier commit. Without a metadata write per commit,
GRAPH therefore records:
wal_head(flag bit 3, offset 84): the name of the newest WAL segment, written whenever a segment is started, after the segment's header was written and synced and its directory synced (rotation, the first segment of an open, the segmenttarget + 1of a rollback together with its lineage entry), and after an attic restore (the newest restored segment); a recorded WAL cut lowers it to the cut segment. A failed write leaves the older value.closed_at(flag bit 4, offset 92): the last commit at a clean close (state 0). A catalog commit on a closed store (12.12) moves it forward to that commit; it never lowers it.
At every read-write open (before the torn-tail rules), in the damage scan and in verification it
is damage when: a segment's header names another first commit than its file name; the
segment wal_head is missing, or it or an older segment is shorter than its 64-byte header; or
the store was closed cleanly at closed_at and the snapshot plus the WAL end at an earlier
commit. A last segment newer than wal_head and shorter than its header is a crash while it
was being started: it is removed as a torn tail.
9.9 Write ordering and durability
The writer of a journal MUST:
- assign the commit's sequence number (checked against overflow) before writing its record;
- run every other commit check (hooks that may veto) before writing, so that nothing fallible follows a written record and the WAL never holds a commit that did not happen;
- write the record (every part of a commit in parts, 9.3.1), then make it durable according to the configured durability: a sync after every commit (the default), at most once per interval, or left to the operating system; a commit in parts gets one sync, after its last part;
- treat a failed write or sync as a vetoed commit (the unit rolls back) and refuse every later commit and mark until the WAL is reopened, because the state of the file is unknown.
The durable end is the offset after the last record whose sync completed; it moves only after the last part of a commit in parts, so it never lies inside one. Records after it may still be vetoed and MUST NOT be copied by a backup (12.6).
10. The marks file
A derived list of the store's marks: append-only frames
length u32 | CRC-32C u32 of the payload | Mark payload (9.4), appended and synced after the
Mark record is durable in the WAL. The WAL is the source of truth: a missing or damaged marks
file is rebuilt from all WAL segments on open, and marks in the replayed WAL that the file lacks
are appended. Listing marks reads only this file and lists only the marks a target can reach: those
at or after the oldest snapshot of the store (or backup) listed. The file is not rewritten by a
prune (12.4): a backup copies it and may still reach older marks with older snapshots of its own.
A mark that is not listed keeps its name taken; resolving it as a target fails.
10.1 The ledger file
A derived list of blob reference changes (4.6): append-only frames
length u32 | CRC-32C u32 of the payload | payload,
payload = commit_seq u64 | graph_id 16 bytes (big-endian) | blobref (3, tag 21, without the tag) | delta svar: one frame per (commit, blob) whose net delta is not 0, the delta counting
every blobref in the commit's after images (+1) and before images (-1). Frames are appended
and synced after the commit is durable in the WAL. The WAL is the source of truth:
- A frame counts for a position when its
graph_idandcommit_seqlie on that position's lineage chain (5.4): its lineage is on the chain and its commit at or before that lineage's branch point. A rollback does not rewrite the file: frames of an abandoned lineage are ignored by this rule. - A damaged file, and a missing one in a store that holds blobs, is rebuilt from all WAL
segments on open (a warning and a journal record
ledger.rebuilt, never damage). After a crash the frames of the replayed commits the file lacks are appended and frames of the current lineage after the recovered end are dropped. A store that never referenced a blob needs noledger. - A prune rewrites it (atomically) without the frames at or before the oldest kept snapshot and
without the frames off the current chain (their history lives on in attic entries, whose
WAL is read for them); no
INTENTis needed (the file is derived).
11. The INTENT and ATTIC files
11.1 INTENT
A multi-file operation writes INTENT (compact JSON, replaced atomically and synced) before its
first file change and removes it after its last one. Every step is idempotent; a read-write open
that finds INTENT completes (or, for a backup increment, rolls back) the operation before
anything else. An unknown op MUST fail the open, as unsupported content of a newer writer
(16 rule 9), never as damage. Every path in it follows 4.2.
{"op": "<operation>", "files": ["<store-relative names>"], "started_at": <micros>, ...}
Further parameters are string values. Operations of store format version 4 (versions 2 and 3
have all but upgrade_models):
op | Parameters and steps |
|---|---|
prune | files: the snapshot directories and WAL segments to remove. On open: each listed name is removed (missing is fine), the directories synced, INTENT removed |
rollback | files: snapshot directories and WAL segments to move (or delete); target, last_commit, base_snapshot (newest snapshot at or before the target), mode (move | delete), old_graph_id, new_graph_id (32 hex digits), time, attic (attic/<YYYYMMDDTHHMMSSZ>-<target+1, 20 digits>), reason; and either split + split_offset (the segment holding the first commit after the target is cut there; its tail becomes <attic>/wal/<target+1>.wal with the old lineage's header) or kept (hex; when that segment is itself named target+1, it moves whole, and the records before the cut, marks pointing at the target, open the new lineage's segment). The tail of a split segment keeps the header lineage of the segment it is cut from (an ANCESTOR's when the target lies before the current lineage's branch point), not necessarily old_graph_id. files names every directory under snapshots/ after the target, holders (4.1) included. For the existing attic entries (11.2) whose history before their own WAL reaches past the target, three more parameters, each a list of lines separated by \n: copies (<source> <destination>: the store's WAL segments, or the split segment meaning its tail as the attic gets it, that hold the commits from target + 1 up to such an entry's prefix end, copied into <entry>/wal/ under their names), rebase (the ids of those entries) and drop (the snapshot directories of entries one of whose snapshots references a file of a directory this rollback moves). Steps: attic directories; the copies (each written whole under its final name, skipped when present; all of them exist before any source changes); the drop directories removed; each rebase entry's ATTIC rewritten with base_snapshot = this rollback's base_snapshot; tail and cut; move or delete files; ATTIC; marks filtered to <= target; GRAPH with the new lineage entry [new id, branched at target, time]; the new lineage's segment <target+1>.wal (written whole, its header created at time, then the kept records; one found shorter is written again); holders no snapshot of the store or of an attic entry references any more are removed (12.4); INTENT removed |
attic_restore | Allowed only while the store is at the entry's target on the rollback's lineage and its new segment holds nothing beyond the kept records. files: the entry's directories under snapshots/ (holders too) and its WAL segments named after its target (its prefix copies, 11.2, stay behind: the store holds that history again); refused when one of them exists in the store. Steps: remove the new lineage's segment and a snapshot of the new lineage at the target (a checkpoint of the closed store after the rollback writes one without a WAL record), move the entry's files back, drop the lineage entry from GRAPH, rebuild marks from the WAL, remove the entry |
upgrade_models | the migration of a store format version 3 store's models/ (15.1): files the model directories models/<id> checked before it was written, from the old store format version. Written before GRAPH gets the new version (a reader of version 3 then refuses the store as newer; one that reads GRAPH as 3 but finds this op refuses it as unknown). Steps, each idempotent: every model of models/ becomes a blob (a blob of the same content stays); ONE catalog commit (12.12) defines every model whose identity's 12 hex digits no model definition has yet (principal upgrade, attribute upgrade = "<from>-><to>"; a renamed model's embedder in the schema renamed in the same commit), none when all are defined; each model directory renamed to models/tmp-<32 hex> and removed, then models/; INTENT removed |
backup_increment | written in the backup's root (12.7): files (new snapshot directories and WAL segments), graph_before (hex of the backup's GRAPH), taken_at, optionally tail + tail_len (the segment appended to and its length before) and replaced |
Stray *.tmp files in the store root and snapshots/tmp-* directories are removed on open.
11.2 ATTIC and attic entries
An attic entry is a directory attic/<YYYYMMDDTHHMMSSZ>-<first moved commit, 20 digits>/ with
the moved snapshots/ and wal/ and an ATTIC file (the name is unique: when it is taken, by
an entry or an entry being removed, the time part is advanced by one second until it is free;
the ATTIC file records the exact time): compact JSON with the string values
graph_id (the old lineage), new_graph_id, target, last_commit, time, reason,
base_snapshot and kept_bytes. An entry being removed is first renamed
attic/removing-<id> (removed at the next open).
An entry is self-sufficient given the store (it never needs another entry). Its history is
its base snapshot (base_snapshot, a snapshot of the store's own snapshots/), then the store's
WAL from it up to the prefix end, then the entry's own WAL; or, when the entry holds
snapshots, its newest one and its own WAL after it. The prefix end is the commit before the
entry's first WAL segment, at most its target. Segments of the entry named at or before its
target are its prefix: copies of the store's history that a later rollback to an earlier
commit (rebase, 11.1) gave it before moving that history into its own entry; the same rollback
points base_snapshot at its own base and drops the entry's snapshots when they reference files
it moves (they are derived: the entry's WAL rebuilds every state they held). The store's history
up to an entry's prefix end therefore stays in the store: rollbacks keep everything at or before
their target, restores add only history after theirs, and prune keeps every entry's base and the
WAL after it (12.4). The entry's segment and snapshot listings treat a missing snapshots/ or
wal/ as empty.
12. Operations
12.1 Load and recovery
A target is Latest, a commit_seq, a time (the last commit whose time is at or before it), or
a mark name. Loading a target: take the newest snapshot at or before the target (for Latest,
the newest), then replay its replay set (9.7) along the lineage chain (5.4) up to the target.
- A load checks
GRAPHand the lineage, may check the manifest's estimated in-memory bytes against a budget, loads the vertex segments, then the edge segments (an edge's endpoints are resolved by id), rebuilds every index and statistic, and restores thegraph_id, the position, the last commit time and the auto-id sequences. - A snapshot load does not validate the data against the stored schema: the data was valid when it was committed, and integrity comes from the checksums. It restores the catalog of definitions from the manifest (6.3).
- A layer snapshot (7.5, kind 128) loads only into a fresh layer over the base it names, in the order of 7.5: schema, catalog, the layer file's entries, then the layer's own segments.
- WAL replay applies mutations without running commit hooks or schema validation; op 10 stores or removes a definition.
- A read-write open whose loaded state holds a critical definition of a kind the reader does not
know, or whose base snapshot has a file of a critical segment kind it does not know (7.5),
opens the store read-only (16 rule 3): every commit, mark, checkpoint, prune, rollback
and compaction is refused, and nothing is written after the load (no torn-tail cut, no
marksrebuild, no change ofGRAPH). The steps of 12.2 before the load (completing anINTENT, removing leftovers, applying a recorded WAL cut) MAY have run; they do not change the graph. Reading, verification, export, fork and backups work; a fork or backup keeps the definition and is read-only for that reader too. - A read-write open whose snapshot
schema.jsonor a schema image of op 9 the reader cannot parse (a newer writer's keyword or mode; its checksum is valid) loads the data WITHOUT the schema and opens the store read-only in the same way (16 rule 9). As the loaded state lacks the schema, every store operation that would write a state derived from the files (a checkpoint, a fork, a repair) is refused as unsupported; a file-level backup and the export of a stored snapshot copy the bytes as they are. A snapshot written from the loaded graph in memory (g.export_snapshot) has no schema. - Recovery to a target before the end yields a read-only past state. A writable state from it is either a fork (a new store, 12.5) or an in-place rollback.
- Without a snapshot (a journal over a stream), the first journal MUST start at commit 1.
12.2 Open and close
A read-write open: take the writer lock (12.10); complete an INTENT; remove leftovers
(snapshots/tmp-*, *.tmp); apply a recorded WAL cut; run the checks of 9.8; load (12.1, mode
Latest); cut a torn tail of the last segment; rebuild marks if needed; set GRAPH state 1.
A clean close: sync, then write GRAPH with state 0 and closed_at. A store whose state is 1
at open was not closed cleanly; that is not damage (the WAL replay recovers it).
12.3 Checkpoints
A checkpoint writes a snapshot of the current state: encoded consistently at one position
(the reference implementation streams it chunk by chunk, see 8, or merges it, below), into
snapshots/tmp-<32 hex>/, every file synced, the directory synced, verified (manifest CRCs,
schema.json, every segment's length and CRC, every chunk CRC and the chunk index), renamed to
its 20-digit name, snapshots/ synced; then a Checkpoint record is appended and a new WAL
segment is requested. The manifest carries the whole catalog of definitions, every definition
of an unknown kind byte for byte as read (6.3). Only renamed snapshots exist for listing, loading
and retention. A
checkpoint at a position that already has a snapshot returns that snapshot. The chunk target
size is the store's (GRAPH offset 44) for its whole life.
Merge checkpoint. A writer MAY build the new snapshot from the newest snapshot (the base) and the WAL after it instead of from a loaded graph (the reference implementation does, without the graph's lock, unless the WAL after the base exceeds a configured bound). Such a writer:
- reads the WAL only up to its durable end (9.9), from the base's replay set (9.7) along the
lineage chain (5.4), with every header and body CRC, commit continuity and every lineage rule
of a load; the new snapshot's position is the last commit read and its
graph_idthe lineage the replay ends in (an empty segment of a new lineage counts); - applies the commits as a load replays them (12.1) to the base's state of every element they name, and MUST check every mutation's before image against that state: a mismatch (the WAL does not continue the base) is damage;
- reads every base chunk it uses with its CRC and chunk index row, every base segment it rewrites in full (header, chunks, footer, file CRC), and verifies the new snapshot, referenced files included, before the rename;
- carries the schema, the catalog (unknown non-critical definitions byte for byte), the auto-id sequences, the position and the last commit time exactly as a load followed by a checkpoint would; drops files of an ignorable unknown segment kind (7.5); refuses a base or a state with something critical it does not know (16 rule 3);
- rewrites every segment that holds an element a commit names (an element whose id falls between two segments' ranges goes to the later one, beyond the last range to the last one); the rewritten elements are in strictly increasing id order across the new segments;
- keeps every other segment of the base byte for byte under the donor rule: the new snapshot uses no file the base uses, so the base stays an independent copy of every id range, the donor of 13.4. Such a segment is referenced (6.2) when the snapshot before the base (the newest snapshot older than the base, of the same lineage) has a twin: a row with the same kind, first and last id, element count, byte length and file CRC, the same chunk index rows, naming another file than the base's (after resolving both, 6.2); the reference names that file. Otherwise the segment's bytes are copied into a new file of the new snapshot (read with the file CRC checked). So an unchanged range alternates between two files from checkpoint to checkpoint, and only the first checkpoint after the range was rewritten copies it. A writer that encodes a loaded graph (8) writes only new files and meets the rule too;
- on damage, writes nothing visible: the temporary directory is removed, no file of the store changes.
A closed store MAY be checkpointed the same way by a process that takes the writer lock (12.10),
completes an INTENT and removes leftovers (12.2); it ignores a torn tail of the last segment,
honours a recorded WAL cut, applies the checks of 9.8, and appends no Checkpoint record.
12.4 Prune and retention
prune(up_to) keeps every snapshot from min(newest snapshot <= up_to, second-newest snapshot)
on, plus the base snapshot of every attic entry; it verifies each kept snapshot first, then
removes the older snapshots and the WAL segments before the replay set of the oldest kept one,
under an INTENT (prune). The last two verified snapshots and the WAL between them always stay
(the donors of 13.4). Nothing is ever removed implicitly. Prune is refused while the pin is held
shared (12.10). Marks before the oldest kept snapshot become unreachable (10); a prune reports
them, from the marks file only.
Files that a kept snapshot or a snapshot of an attic entry references (6.2) stay: of a removed
snapshot directory that holds one, only the other files are removed, the manifest first (the
directory is a holder from then on, 4.1); a holder older than the oldest kept snapshot that no
such snapshot uses any more is removed whole. The INTENT's files then name single files of
such a directory. Under the donor rule (12.3) the last two snapshots share no file, so each is
the other's donor. A rollback that deleted the history using a holder's files, and the removal
of an attic entry whose snapshots used them, remove the files no snapshot of the store or of an
attic entry references any more (and the holder when it is left empty); a file nobody
references is never referenced again (a checkpoint references only files of a listed snapshot),
so this needs no INTENT.
Blobs (4.6). The referenced set R of a store is the union of the blob tables (6.2 item 5) of
every snapshot of the store and of its attic entries, the blobs of the ledger frames (10.1) on
the current chain, the blobs every attic entry's own WAL references, and the blobs a running
writer holds (written, its commit not yet durable). After its own removals a prune rewrites the
ledger (10.1) and removes every blob file not in R (the orphans of interrupted writes too);
an attic removal and a rollback delete do the same. A removal is idempotent and needs no
INTENT (a blob not in R is never referenced again). When the referenced set cannot be read
nothing is removed.
12.5 Fork, in-place rollback, attic
- Fork: load the target (12.1) and write it as a new store: one snapshot (with the catalog,
6.3), a new
graph_id, the manifest's parent fields set, the chain[new id, branched at target, time]+ the source's chain. Marks are not copied. - In-place rollback (
moveordelete), underINTENTrollback(11.1): everything after the target (later snapshots, the WAL after it; the segment holding the target is split) moves into an attic entry or is deleted; the store continues as a new lineage in the same root. - Attic restore (11.1) undoes a rollback while nothing was committed or marked since; an attic fork writes the entry's history as a new store. Prune never removes an attic entry's base snapshot except together with the entry.
- Every attic entry stays whole after any sequence of rollbacks, restores, removals and
prunes (11.2): a rollback to a commit before an older entry's history copies what that entry
needs into it first (11.1
copies,rebase,drop). Entries never depend on each other: removing, restoring or forking one never breaks another. Restore order (normative): an entry MAY be restored only whileGRAPH's currentgraph_idequals the entry'snew_graph_id(the lineage its rollback started) and nothing was committed or marked since; after several rollbacks the entries therefore restore newest first, each restore bringing back the lineage the next older one needs. A writer MUST refuse an out-of-order restore without changing any file, and SHOULD name the newer entry to restore first. Any entry MAY be forked at any time. - A rollback or restore that fails once its
INTENTis written leaves the files ahead of the graph in memory: the writer refuses every further change and its close writes noGRAPH; the next open completes the operation.
12.6 Backups
A backup is a file-level copy that takes no graph lock: snapshots are immutable once renamed
and the WAL is append-only. A full backup copies GRAPH (rewritten: state 0, no WAL cut, the
backup marker, wal_head and closed_at of the backup's own files) to GRAPH and GRAPH.copy;
the marks file as read before the copy ends were fixed (every mark in it is in the copied WAL);
the latest snapshot (verified before and after the copy) with the files it references (6.2,
copied under their names, in holders when their snapshot is not copied) and its replay set, the
segment of the durable end cut at the durable end, later segments left out. A copy by another process, which has
no durable end, copies the last segment up to its last complete record (a torn tail, 9.6, is left
out; damage before it stops the backup), never past a recorded WAL cut.
LOCK, BACKUP and the attic are not copied. During the copy the source's BACKUP pin is held
shared.
Blobs (4.6). A full backup copies the blobs its copied history references: the blob table of
the copied snapshot (6.2 item 5) and the blobs the commits of the copied WAL reference, each
checked by length and CRC-32C in the source and again in the copy (streamed). A blob missing or
damaged in the source is not carried (a warning; the backup's catalog still references it):
blob damage is never damage of the store. The ledger (10.1) is not copied: it is derived, and
a backup's history is read from its WAL.
Verification. A backup (full, increment, ZIP) reads every checksum of what it copies in the SOURCE before it writes anything, and again in the COPY after writing it:
- in the source: both
GRAPHcopies (one unusable copy is a warning, both are damage; the backup writes two fresh ones); themarksfile (derived, 10: damage is a warning and the backup's is rebuilt from the WAL it copies); every snapshot it copies with everything 12.3 verifies (manifest CRCs,schema.json, every segment and chunk, the chunk index, referenced files) and both copies of the manifest's fixed part (one damaged copy is a warning: the backup gets the file with the intact copy in both places, byte for byte what the writer wrote); every WAL record of every segment it copies, header and body CRC, each segment's header against its name (9.8) and the lineage chain, the segment set of 9.8, and commit continuity (every commit the previous + 1; the first commit after the snapshot, or after the backup's position, its successor); - in the copy:
GRAPH,GRAPH.copyandmarksbyte for byte as written, every snapshot as 12.3 verifies it (both fixed copies strictly), every WAL segment read again with the same end and the same commits as the source's; a ZIP archive is read back entry by entry (12.8).
Damage in the source stops the backup before anything is written; damage of the copy removes a
new backup and rolls an increment back (for an increment, the backup's old GRAPH is written
first, so the rollback never takes a final GRAPH that did not read back for a completed one).
When the copy does not read back, the source's checks run again: a source that fails them now is
the source's damage. The report lists each problem with its file, offset and reason, as
verification does (12.9), and names the side; the remedy for damage in the source is a repair of
the SOURCE (13.4, never of the backup), or, while the source is open in a process whose graph is
intact, a backup from memory (12.11).
Marker. Flag bit 2 marks a backup; offset 68 holds the last commit it holds and offset 76 when
it (its last increment) was taken. graph_id, store_id and the lineage chain are the source's. A marked
store never opens read-write; read-only loads, verification, listing, export, fork, prune of the
backup and backups of it work. Restoring a backup in place takes the writer lock, rolls back an
interrupted increment, clears bit 2 and the marker fields and writes GRAPH clean: the root is
then the live store with the same graph_id and store_id.
12.7 Incremental backups
A backup into a root that holds a marked backup is an increment; into an empty or missing root, a full backup; anything else is refused (a store that is not a backup is never written to).
- Relation. The backup's chain MUST equal the tail of the source's chain that starts at the
entry with the backup's
graph_id. With that entry at position k > 0, the backup may hold commits only up to the smallestbranched atof the entries 0..k-1 (a rollback of a later lineage to before its own start branches from an ancestor at an earlier commit); a backup holding more (the source was rolled back behind the backup's position) is refused; a full backup into a new directory follows the new history, and the old backup stays as the archive of the abandoned one. Unrelated stores are refused. - Identity. The backup's
store_id(5.5) MUST equal the source's. A fork, repair or conversion of the backed-up store shares its lineage chain up to the copy but is a different store: its increment is refused, and a full backup into a new directory is needed. - Position. The backup's position is the larger of its newest snapshot and the last commit of its WAL; its last segment L MUST end with a complete record.
- WAL. If the source has a segment named L with an equal 64-byte header: the source's copy end MUST be at least L's length, and the 25-byte frame of L's last record MUST equal the source's bytes at that offset (prefix check); the bytes from L's length to the copy end are appended. Equal name, different header: allowed only when L holds no commit record and the source branched from the backup's lineage (a rollback to exactly the backup's position); the source's segment then replaces L. The source has no segment L (pruned): its next segment MUST be named at most position + 1, else the gap is refused and a full backup is needed. Every source segment named after L, up to the durable end, is copied whole.
- Snapshots. Every source snapshot newer than the backup's newest is copied, verified before
and after. A referenced file (6.2) the backup lacks (its snapshot was written and pruned since
the last increment) is copied from the source, under its name, before the snapshots that use
it, and listed in the
INTENT'sfiles; one the source lacks too is refused. - Steps, with the backup's writer lock held and the source's pin shared: complete or roll
back an earlier interrupted increment; write
INTENTbackup_increment; when the lineage changed, writeGRAPHwith the source's chain and the OLD marker; copy each snapshot throughsnapshots/tmp-<hex>/(synced, verified, renamed); append the tail and sync, re-reading every record of the segment; copy a replacing segment and each new segment through<name>.wal.tmp(synced, re-read, renamed; a replaced L is first renamed<name>.wal.replaced); check that the copied commits continue the backup's WAL without gap or overlap; writemarks; writeGRAPHwith the source's identity, clean, no WAL cut, the new marker; remove the.replacedfile; removeINTENT. The backup is a valid store after every step. - Interrupted increment (found at the next backup, restore or prune of the backup): when the
marker's time equals the intent's
taken_at, the increment is complete (remove.replacedandINTENT); otherwise it is rolled back: the listed files and everysnapshots/tmp-*andwal/*.tmpremoved, a.replacedsegment renamed back, the tail cut totail_len,GRAPHrewritten fromgraph_before,marksrebuilt from the WAL,INTENTremoved. - Nothing pins the source's WAL for a backup: a prune of the source can make the next increment impossible (a full backup is then needed).
- Blobs (4.6): after the increment, every blob the backup's history references that it lacks is copied from the source (checked by length and CRC-32C on both sides); nothing is removed (a prune of the backup, 12.4, collects).
12.8 ZIP backups
A full backup MAY be written as one ZIP archive: stored entries (method 0), UTF-8 names (the
store's names, 4.2), DOS time 1980-01-01 00:00, the CRC-32 (IEEE, as ZIP requires) in the local
header, zip64 extended fields always (sizes in the local header, sizes and offset in the central
header), then the zip64 end record, its locator and the end record. The archive's GRAPH carries
the backup marker; unpacking it is the explicit restore and clears the marker. A reader MUST
accept only the store's names and MUST refuse compressed, encrypted or streamed (data
descriptor) entries. A well-formed name outside the layout it knows (plain segments, at most
four) is a newer writer's file: the restore is refused as unsupported, never as damage (16
rule 9); any other name is damage. The reference writer reads the archive back after writing it (12.6): every
entry's CRC-32 and every checksum of the store files in it, which arrive in an order a one-pass
reader can check (GRAPH, GRAPH.copy, marks, then each snapshot's manifest before its
other files, then the WAL segments, then the blobs, blobs/<2 hex>/<hash> (4.6: each read back
with its length, CRC-32C and SHA-256), then the segments of the system journal,
journal/<20 digits>.jnl, 4.7: checked frame by frame, a problem is a warning). Unpacking an
archive checks every blob as foreign input: the SHA-256 of its content against its name, its
length and CRC-32C against every reference its history holds; a mismatch refuses the restore
as damage of the archive. A writer MAY leave the models and blobs out of an archive meant to be
shared (the reference implementation's BlobCopy::Exclude): its catalog still references them,
so the receiver has them missing.
12.9 Verification (scrub)
Verification reads every checksum: both GRAPH copies, every manifest (both fixed copies), every
schema.json, every segment and chunk (and the chunk index), every WAL record; it checks id order
and non-overlapping ranges, WAL continuity (commit_seq + 1 per Commit, no gaps) along the
lineage chain, the checks of 9.8, every attic entry (its history is rebuilt as 11.2 describes,
and each of its snapshots verified), and the marks file. A holder (4.1) with files that no
snapshot of the store or of an attic entry references is a problem (a lost manifest, or files a
prune left). A segment file the newest snapshot shares with the previous one (a break of the
donor rule, 12.3) is a warning, not damage: the range has no independent donor; the next
checkpoint finds no twin for it and copies it. It is meant to be run regularly: it finds damage while donors
still exist. Verification also checks every embedding model (4.5): its manifest, the
set of files, every file's size and SHA-256; a model of a newer manifest format is a note. It reads
every segment of the system journal (4.7): a damaged record or segment is a note, never a
problem. It reads every blob of the referenced set (12.4) whole: SHA-256, CRC-32C and length; a
missing or damaged blob, and an entry under blobs/ that is not a blob's name or tmp-*, is a
problem with its path under blobs/ (never damage of the store, 13); a blob file outside the
referenced set is a note (an orphan the next prune removes); a blob of an unknown algorithm is
checked by length and CRC-32C only, with a note that its hash was not checked.
12.10 Locks and pins
- Writer lock: at most one writer per store. On a directory it is an exclusive operating
system advisory lock (
flock/LockFileEx) onLOCK, held while the store is open read-write; in a container file it is the lock on the file itself (14.5). Read-only loads, verification, listing, export, fork and out-of-process backups take none. - Backup pin: a backup holds the
BACKUPlock shared while it copies, and so do a verification, a fork and a packed export of a writable open store while they read (the forms on a closed directory,fork_dirandexport_packed_dir, take no lock); each waits while the lock is held exclusively, and takes it before it reads the durable end of the WAL. A prune, a rollback, and an attic restore or removal take it exclusively and without blocking, and are refused while it is held shared.
12.11 Backups from memory
A writer that holds a store open and has found damage in its files (13.3) MAY write a backup of its graph in memory instead of copying files: the graph was verified when it was loaded and changed only by commits since. It reads and writes NOTHING in the store's directory. The backup is an ordinary marked backup (12.6):
snapshots/<seq>/: one snapshot of the graph at its last commitseq, written throughsnapshots/tmp-<hex>/, synced, verified (12.3) and renamed;wal/<seq + 1>.wal: an empty WAL segment of the graph's lineage (its header only), synced;GRAPHandGRAPH.copy: the store's identity, lineage chain and creation parameters (5.2) with state 0, no WAL cut, the backup marker (seq, the time),wal_headseq + 1,closed_atseq; read back. Nomarksfile: like a fork, the backup holds no WAL before its snapshot, so the marks would not be targets.
Into a missing or empty root it is a full backup. Into a marked backup of the same store (the
relation of 12.7, and its position at most seq) it is an increment under an INTENT
backup_increment whose files are the new snapshot directory and segment: the snapshot is newer
than everything the backup holds, the commits between the backup's position and seq are not in
it (no target between them). A later file-level increment of such a backup finds no segment of
the source it continues and is refused: a full backup is needed.
The blobs the graph's state references (the new snapshot's blob table) are copied from the
store's blobs/ leniently: the one exception to "reads nothing in the store's directory", since
blobs live only there; one that is missing or damaged is listed as not carried.
12.12 Catalog commits on a closed store
A writer holding the writer lock of a CLOSED store MAY append one commit that changes only the schema (op 9) and the catalog (op 10), computed WITHOUT loading the elements (book page "Embedding Models in a Store"). No byte changes: the record is an ordinary Commit (9.3, a single record: such a commit is small) and the next open replays it like any commit.
- The catalog view: the newest snapshot's definitions table (6.3, with the forward-compatibility
rules of 16: opaque definitions kept) and
schema.json, then every record of the WAL after it in the replay set (12.1) up to the last complete record: a Commit's ops 9 and 10 applied with their before images VERIFIED against the view (a mismatch is damage), its data ops read (frames and checksums checked) and skipped; continuity, lineage (5.4) and 9.8 as for a recovery. The last commit's position, time and id sequences are the new commit's base (the manifest's without WAL commits). Damage refuses the commit with nothing written. - A store this version may only read (a critical opaque definition or segment kind, 16 rule 3; a schema it cannot parse) is refused.
- Before appending, the writer MUST do what an open does to the WAL: apply a recorded
wal_cut(9.7) and writeGRAPHwithout it, remove an unstarted last segment and cut a torn tail (9.6), complete themarksfile (10) and the blob ledger (10.1). - The commit continues the last segment unless it is of an older file format version (never
continued; one that starts at this commit is rewritten in the current version with its
records, 15.1) or past the segment size: then a new segment (9.7,
wal_head). Its time is at least every time the files hold (commits, marks, checkpoint records, the system journal's tail). It is synced before anything follows; a failed write is cut off again or its cut recorded (9.7). Then its ledger frames. GRAPH: a store closed cleanly records the new commit asclosed_at(it MUST NOT be lowered); a crashed store (state 1) stays as it is. A crash between the commit and this write leaves a WAL ending later thanclosed_at, which is valid (9.8).
A reader without the lock (--read-only) sees at most an unfinished last record, which it
ignores (9.6). No snapshot is written.
13. Damage handling
13.1 Redundancy
GRAPHandGRAPH.copy(5.3); the manifest's fixed part at its head and its tail (6).- The manifest's chunk index (6.2) carries the id range and CRC of every chunk.
- WAL frames carry a sync marker and
commit_seqoutside the payload (9.2). - Retention keeps the last two verified snapshots and the WAL between them (12.4), and the donor rule (12.3) makes them independent: the newest snapshot shares no segment file with the previous one, so every id range of the newest has a donor in a distinct file (the previous snapshot's chunks plus the WAL between the two), and every range of the previous one has a later snapshot covering it. A file the newest snapshot references is a twin in the directory (or holder) of an older snapshot; its damage is repaired from the previous snapshot like damage of the newest's own files.
- Flag bit 0 of
GRAPHis reserved for parity data (not in store format version 4).
13.2 The damage scan
Chunks are checked one by one against the manifest's chunk index (a damaged segment header or
footer with intact chunks is framing damage; the data is intact). WAL records are read with
resynchronisation (9.2). Torn tails follow 9.6, the segment set follows 9.8. The commits a
damaged WAL region lost are those between the valid commits around it; if none are missing, the
region held a Mark or Checkpoint record. Damage to one copy of redundant metadata (one GRAPH
copy, one manifest fixed part of the latest snapshot) is a warning, not damage.
13.3 Maintenance mode
A read-write open whose load fails with damage (a checksum, a gap, a lineage mismatch, a missing
file, both GRAPH copies invalid, container damage, 14.4) does not fail and does not repair: the
store opens read-only with a damage report that lists the damaged files, chunks and records,
the id ranges and commits affected, and for each its donor: an older snapshot whose chunks
cover the id range plus the WAL up to the damaged one; a later snapshot that covers a damaged
WAL record; or the other copy. The readable state is built from donors. Nothing is written in
maintenance mode (no state change in GRAPH, no torn-tail cut).
Damage found while a store is open. Damage a writer finds in its files while it holds the store open (a backup, 12.6; a checkpoint's merge, 12.3; a verification, 12.9) follows the store's damage policy (5.2 bit 5), fixed when the store was created:
maintenance(the default): the store turns read-only for the rest of the time it is open, with the damage as the reason: every commit, mark, checkpoint, prune, rollback and compaction is refused, and nothing more is written (a close syncs the WAL and does not rewriteGRAPH, so the next open sees an unclean close, which is no damage). Reading and a backup from memory (12.11) go on.continue: the store keeps accepting commits; the damage stays reported for as long as it is open.
The policy does not apply to damage found when the store is OPENED: that is always maintenance mode, as above. Problems of attic entries alone (history moved aside, 11.2) are reported by verification but do not count as damage of the store's own history.
13.4 Repair
Repair is explicit and never in place; it writes a new, verified store elsewhere:
- The base is the newest snapshot with a readable manifest; its schema comes from
schema.json, else an older snapshot's plus the WAL's schema changes. Its catalog of definitions comes from its manifest (covered by the variable part's CRC); when a definition there does not decode, from an older snapshot's catalog plus the WAL's op 10 changes up to the base, else it is lost (reported). The repaired snapshot carries the catalog, unknown definitions byte for byte. - A damaged chunk is rebuilt from the newest older snapshot whose chunks overlapping its id range are all intact, provided the WAL between the two is complete: that range's elements are decoded and every WAL mutation naming an element of the range is replayed. Edges of intact chunks whose endpoint is lost are lost elements.
- The WAL after the base is replayed mutation by mutation: a damaged record is skipped when a later snapshot covers it; otherwise replay continues after the gap, and every element whose current state does not match a later mutation's before image (or whose mutation fails) is reported as diverged (the later value is kept), never guessed.
- The result is a new lineage whose chain continues the damaged store's, with one snapshot named
repaired. The report lists what was repaired, the lost commits, id ranges and elements, and the diverged elements. The damaged files are never changed. - The blobs the repaired state references are copied, each checked by length, CRC-32C and SHA-256 (the source is damaged); a missing or damaged one is reported as not carried and does not fail the repair. A fork and an attic fork (12.5) copy the blobs of their new snapshot's table the same way (length and CRC-32C).
Blobs are not store damage. A missing or damaged blob (4.6) never opens a store in
maintenance mode, never freezes it under the damage policy and never makes a repair necessary:
what needs its bytes fails (reading it, exporting it), everything else goes on. The writer
reports it once per blob and failure in its operational journal (the reference implementation's
blob.damaged record names the blob, the failure and a recommendation: any copy with the same
hash, from a backup or another copy of the store, is the same bytes).
Bringing blobs back. Two operations of a CLOSED store (the writer lock) deal with missing or damaged blobs; neither changes the history:
- A blob restore checks every blob of the referenced set (12.4: length, CRC-32C and hash)
and copies each faulty one from another copy (a backup directory with its increments, a ZIP
backup, a packed snapshot, another store) by its algorithm and hash, a blob of an unknown
algorithm by its name (4.6): streamed into
blobs/tmp-<random>, checked the same way, synced and renamed into place as a blob write (4.6). A healthy blob is never touched; a source blob that fails the check is not used. - A repair that drops faulty blobs (13.4 above, opt-in) leaves out of the repaired store's
catalog every definition that references a missing or damaged blob, and the blob. It MUST be
refused before anything is written while the current schema needs such a definition (a model
a vector property's
embeddernames, 4.5).
14. The single-file container
A whole store in ONE file (extension .gstore by convention; the content decides): a
log-structured container behind the backend abstraction of 4.3. The store's own files, names and
byte formats are exactly those of a directory; the container only records which bytes a name
holds. Nothing inside the file is ever overwritten, except the two header slots.
14.1 Layout
0 preamble (16): magic "GRSLFILE" | container version u32 = 1 | flags u32 = 0;
zeros up to 4096; written once at creation
4096 header slot 0 (64), zeros up to 8192
8192 header slot 1 (64), zeros up to 12288
12288 records, appended one after the other to the end of the file
Header slot (64 bytes): 0 magic "GRSLHEAD" | 8 generation u64 | 16 table offset u64 (the table record's frame) | 24 table record length u64 (the whole frame) | 32 table record sequence number u64 | 40 zero (20) | 60 CRC-32C of bytes 0..60. An all-zero slot is unused. Generation
g lives in slot g mod 2; a new table is published by writing the OLDER slot with g + 1.
Record frame:
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | sync marker GSFR |
| 4 | 1 | record type |
| 5 | 3 | zero |
| 8 | 8 | sequence number: +1 per record within one file, the first record is 1 |
| 16 | 8 | durable end: the file offset up to which every byte was synced when this record was written (at most the record's own offset) |
| 24 | 4 | fields length F (at most 16 KiB) |
| 28 | 8 | payload length P |
| 36 | F | fields |
| 36 + F | 4 | header CRC-32C of bytes 0..36+F |
| 40 + F | 4 | payload CRC-32C |
| 44 + F | P | payload |
Record types (fields: strings are string, numbers uvar; names follow 4.2 and are never
empty):
| Type | Record | Fields | Payload |
|---|---|---|---|
| 1 | append | name, logical offset | the bytes to append there (a missing file is created; a longer file is first cut to the offset) |
| 2 | create | name | none: an empty file, replacing one |
| 3 | put | name | the file's whole new content (an atomic replacement) |
| 4 | truncate | name, length | none |
| 5 | mkdir | name | none (parents are implied) |
| 6 | rename | from, to | none: a file replaces a file; a directory moves with its subtree; onto an existing directory it is the completed cross-device move of 4.3 (only the source goes) |
| 7 | remove | name | none: a file or a whole subtree |
| 8 | table | none | every name (14.1, below) |
Table payload: uvar directory count, the directory names (string); uvar file count,
per file name string | length uvar | extent count uvar | extents (container offset uvar, length uvar). An extent at
offset 0 is a hole (zeros: bytes a damaged record lost); every other extent lies in
12288..table offset; the extents of a file add up to its length.
14.2 Writing
- Every backend operation appends records: an atomic replace is one put record + sync; an append is one append record + sync; a truncate one truncate record + sync; name changes (mkdir, create, rename, remove) one record each, durable at the next sync. Bytes written through an open file handle are buffered (at most 1 MiB) and become one append record when the handle is flushed, synced, cut, full or dropped.
- A new table is appended when the records since the last one reach
max(16 MiB, 16 × the last table record's length), when the writer lock is released (a close), and after a damaged or missing table was found: table record, sync, the older header slot withgeneration + 1, sync. A torn table write leaves the previous header and table valid. - A new file is written under
<name>.create-<hex>.tmp(preamble, an empty table as record 1, header slot 1 with generation 1), synced, hard-linked to the name only when nothing is there (a rename on file systems without links), and the directory synced.
14.3 Opening
The header slots are read; the valid ones are tried newest generation first: the table record a slot points at MUST be a type-8 frame with that sequence number and length, an intact payload CRC and a valid table. The first one that works is the base; the records after it are replayed. A damaged slot or table is a warning: the older generation and the records after it give the same names, because every change is a record. Without any usable table every record from offset 12288 is replayed (a warning).
14.4 Torn tail and damage
Replaying from the base, at a position p:
- fewer than 44 bytes, or a header whose CRC is valid but whose payload runs past the end: the torn tail of an interrupted write;
- an invalid frame header (marker, type, non-zero padding, fields length, header CRC, a durable
end above
p, or a sequence number below the expected one): the next position with a valid frame header is searched. None: if every byte frompon is zero, a torn tail; otherwise damage. Found atq: if the last valid frame of the file names a durable end abovep, the bytesp..qhad been made durable and are damage (replay continues atq; a sequence gap is reported as lost records); otherwise nothing afterpwas ever made durable: a torn tail atp; - an intact header with a payload CRC mismatch: an append whose bytes were made durable (a later
frame names a durable end above
p) is applied as it is and reported as damage; the last append of the file is applied as it is without a report (the store's own checksums judge it, as on a directory: zeros at the end of a WAL segment are a WAL torn tail, other bytes WAL damage); a put or another record made durable is skipped and reported as damage (a put keeps the old content); a table made durable is skipped with a warning (redundant); anything not made durable is a torn tail atp; - a valid record whose sequence number is above the expected one: damage (lost records);
- an append beyond a file's end (a lost earlier append) leaves a hole and is damage.
A torn tail is cut (truncate + sync) at the next write, never by a reader. Container damage opens the store in maintenance mode (13.3); the container then refuses every write. Damage of both header slots or both tables alone loses nothing.
14.5 Locks, processes, relocation
- The writer lock is the operating system's lock on the container file itself, held on its own handle; after taking it, the path MUST still name the locked file (a compaction may have replaced it), else it is taken again. A process without the writer lock changes the file only under that lock, taken for the one change.
- A process that does not hold the writer lock compares the file's identity and length before each operation and replays what another process appended (or reloads a replaced file). A backup pin freezes the pinning process's view: every byte it references stays where it is until a compaction, and a replaced file stays readable through the open handle.
- The file holds no path; it may be moved or copied while no process has it open. Temporary files
of an interrupted create or compaction (
<name>.create-*.tmp,<name>.compact-*.tmp) are removed when the writer lock is taken.
14.6 Compaction
A removal frees space only inside the file. Compaction copies the live state into
<name>.compact-<hex>.tmp next to the file: the preamble, one mkdir record per directory, per
file one create record (empty) or append records of at most 64 MiB, the table, header slot 1
with generation 1; synced; the writer lock is moved to the new file; the new file is renamed over
the old one and the directory synced. It needs free disk space for the live data meanwhile and
is refused on a damaged container.
Space accounting: total = the file's size; live = what a compaction would write, from the in-memory table; garbage = total - live (old tables, replaced and removed files, the framing of many small appends).
15. Versioning
- Every file starts with a magic and a format version. There are three version axes: the
store format version in
GRAPH(offset 8, 5.1), the file format version in the manifests, segments, WAL segments and packed snapshots, and the single-file container version (14.1). This specification is store format version 4, file format version 4 and container version 1. - Version history of the store format: 1, the first version; 2 (Graphersal 0.1.0) added the
store identity
store_idatGRAPHoffset 100 (5.5), which version 1 left zero; 3 (Graphersal 0.2.0) has the layout of version 2 and marks a store written with file format version 2. The bump exists for older readers: a reader of store format version 2 knows only file format version 1 and would take the manifests and WAL segments of file format version 2 for damage (an unknown version word is damage there, 13), open the store in maintenance mode and offer a repair that loses data; with version 3 inGRAPHit refuses the store as newer before it reads any other file. 4 (Graphersal 0.5.0) has the layout of version 3 and marks a store whose embedding models are blobs referenced by catalog definitions (4.5, 4.6), with the blob ledger (10.1) and the system journal (4.7); a version 3 store of Graphersal 0.4.0 may keep models as files undermodels/, which the upgrade migrates (15.1). With version 4 inGRAPH, Graphersal 0.4.x refuses the store as newer. - Version history of the file format: 1 (Graphersal 0.1.x); 2 (Graphersal 0.2.0) added the
temporal value tags 9 to 13 and the vector value tag 14 (3); 3 (Graphersal 0.3.0) added the
nanosecond temporal value tags 15 to 20 (with
offsettimeand the zone name of adatetime) and writes every temporal kind butdatewith them; 4 (Graphersal 0.5.0) adds the blob reference value tag 21 (3), the manifest's blob table (6.2 item 5), the segments of the system journal (4.7) and the Commit part record type 4 of the WAL (9.2, 9.3.1), written for commits larger than one part; 5 (Graphersal 0.7.0) adds the layer snapshot (7.5, segment kind 128) and is written ONLY in the packed header, manifest and layer file of a layer snapshot, every other file staying at version 4. Nothing else differs between these versions, so a reader of version 4 reads files of versions 1 to 3 as they are: a packed snapshot written by an older release loads, and a store created from it keeps its older manifest and segment files byte for byte (8, 12.1). Every file carries its own version: a snapshot MAY reference (6.2) or a packed snapshot MAY contain segment files of older versions, and a manifest of an older version MAY be rewritten in the current version (its content is valid in both). A file of a newer version is not readable by an older reader: since 0.1.1 every reader checks every file header first and refuses a store, backup or packed snapshot holding one as written by a newer version (unsupported version, below), never as damage. That is why file format versions 3 and 4 need no new store format version of their own, unlike version 2 (whose readers, 0.1.0, took an unknown file version for damage); store format version 4 marks the model migration (above). The container is still at version 1. - A writer writes only the current version: 4 for every file, 5 for the packed header, manifest and layer file of a layer snapshot (7.5).
- A file with a newer version than the reader knows MUST be refused (unsupported version), never guessed at. A reader of file format version 4 MUST accept versions 1 to 4 in every file header (manifest 6.1, segment 7.1, packed snapshot 8, WAL segment 9.1), and version 5 in the packed header, manifest and layer file of a layer snapshot (7.5). A store whose snapshots are layer snapshots is a layer store (nothing else marks it: its manifests tell): it is opened only as a layer over the base its layer rows name. A version-5 manifest is read as a layer manifest only with its kind-128 row (else it is newer); a layer store opened as a whole graph, a whole-graph store opened as a layer, and a layer manifest over another base are refusals before anything is written, never damage. A reader without layer stores refuses the version-5 manifest as newer.
- A version from the future is not damage, and a store holding one MUST NOT be worked on.
A file whose magic matches and whose header checksum is valid (the
GRAPHfixed part, 5.1; a manifest fixed-part copy, 6.1; a segment or WAL segment header, 7.1, 9.1) but whose version word is above the reader's is "written by a newer version". The reader MUST refuse the whole operation with an unsupported-version error and MUST NOT classify it as damage (13). A store, backup or single-file store holding even one such file MUST NOT be worked on in any way: no write, no lock, no maintenance mode, no salvage or repair, no upgrade (15.1), no checkpoint, no backup into or out of it, so a reader can never corrupt what a newer writer wrote. A single-file container (14.1, whose preamble has no checksum) is newer when its magic matches and its container version is above the reader's. A header whose checksum fails stays damage. Every operation on an existing store, backup or attic checks, before it takes a lock, reads data or writes: the container version, then bothGRAPHcopies (either one newer refuses the store, whatever the other holds), then the headers of every manifest, snapshot segment and WAL segment of the tree (snapshots, holders,tmp-*directories and attic entries); a header it cannot read is left to the operation's own checks. A restored ZIP backup that is refused this way is removed again. (The reference implementation does so since 0.1.1.) - Format versions move only with a release that needs them. A patch release (x.y.Z) MUST NOT change any format version (store, file or container). A format version changes only with a release whose new features need it; a release that changes no format reads and writes the stores of the release before it as they are, with no upgrade.
- A
GRAPHof an OLDER store format version (its magic and fixed-part checksum valid, the version word below the current one) MUST be classified by its version word before any field that version did not have is checked: it is neither damage (13) nor "not a store". Every operation refuses it with "older format" (open, read-only open, info, verify, backup, restore of a backup directory, fork, conversion), except the upgrade (15.1), the repair (which reads a store of a released older version as upgraded and writes the repaired store in the current version) and the restore of a ZIP backup (which upgrades what it unpacks). - Every release reads every released version. A reader of store format version 4 MUST read the files of store format versions 2 (Graphersal 0.1.0) and 3 (0.2.0 to 0.4.x) and of file format versions 1 to 3, and a later version MUST keep reading them; a store of a released older version is upgraded without the build that wrote it (15.1). Store format version 1 was never released: a store of it is migrated through a packed snapshot exported by the build that wrote it, from which the current build creates a new store (only the graph state, schema and catalog move; marks, the attic and backups do not).
- New value tags, record types, mutation ops,
INTENToperations and flag bits require a new version, except flag bits that a reader may ignore without misreading the store (a writer preserves unknown bits it read).
15.1 Upgrading a store
Which store format versions an implementation upgrades, and how, is an explicit table; an upgrade not in it is refused before anything is written. The reference implementation's table (generated from its code):
| From store format version | Written by | To | Upgrade |
|---|---|---|---|
| 1 | never released (no store id) | 4 | unsupported (packed snapshot) |
| 2 | Graphersal 0.1.x (no models: the version word only) | 4 | in place or into a copy (migration) |
| 3 | Graphersal 0.2.x - 0.4.x | 4 | in place or into a copy (migration) |
| 4 | Graphersal 0.5.x and later | 4 | nothing to do |
"Version word" means only the version word of GRAPH and GRAPH.copy (and their checksums)
changes, which is safe in place; "migration" means the version word plus the migration of the
embedding models a version 3 store keeps under models/ (below; a store without models/
changes only its version word), in place or into a copy; "into a copy only" means the upgrade
writes a new store and an in-place upgrade is refused; "unsupported" means the migration through
a packed snapshot (below). A store holding a file of a newer version is never upgraded (15).
An upgrade converts a store of store format version 2 or 3 (a store, a backup directory, either backend) to version 4. Version 4 has the layout of versions 2 and 3 and every file of them is a valid file of version 4 (its own header names its file format version, which a version 4 reader reads), so an upgrade:
- Takes the writer lock of the store and refuses it while held (an older writer has it open).
- Checks every model of
models/against its manifest (4.5 "Older stores": every file's size and SHA-256, the three identity files, the weights' safetensors header) WITHOUT writing; a damaged, incomplete or unconvertible model refuses the upgrade. - Verifies the store as version 4 would read it (12.6's checks: both
GRAPHcopies, every snapshot, every WAL record and the segment set of 9.8, the attic) WITHOUT writing: theGRAPHcopies are read with the version word replaced by 4. Any problem refuses the upgrade (repair it instead, 13). - With
models/: writesINTENTupgrade_models(11.1). - Rewrites
GRAPH.copy, thenGRAPH(each atomically, 5.3) with version 4 and every other field unchanged (lineage, identity, flags, the backup marker,wal_head,closed_at,wal_cut). Withoutmodels/no other file changes, so noINTENTis needed: after a crash between the two writes the copies differ by the version word only and a version 4 reader uses the valid copy (5.3); repeating the upgrade rewrites both. An older reader refuses either state as newer. - With
models/: completes theINTENT(11.1): each model becomes ONE blob, the model tar of 4.5 holding its files and a manifest of format 3 built from the old one (identity, repository, revision, commit, licence, licence text, base models, gated, the files); ONE catalog commit (12.12, in a new WAL segment) defines the models (kind 5, no default);models/is removed. The repository of a definition is the old manifest's; a model without one, or a second revision of a repository another model of the store takes, getslocal/<12 hex>(its identity changes; the schema'sembeddernaming the old identity is renamed in the same commit). The positions before the migration commit have no models. A reader of version 4 that finds theINTENTcompletes it at its next read-write open or upgrade.
An upgrade into a NEW location copies every file of the store (as a conversion does: name by name, without the
locks and temporary files) after step 2, writes a marker upgrade-in-progress.tmp into the
target first, verifies the copy with its new GRAPH held in memory, then writes GRAPH.copy,
GRAPH and removes the marker: until GRAPH is written the target is not a store, and a target
holding the marker is an interrupted upgrade that the next upgrade into it clears. Unlike a
conversion, the copy keeps the store id: it is the same store in the new version.
After an upgrade the files of file format version 1 stay where they are: snapshots, WAL segments
and the attic keep their bytes, so the history is exactly what was written. A writer MUST NOT
append to a WAL segment of an older file format version: when the newest segment of the
lineage is older, the next record goes into a new segment of the current version (9.8:
wal_head names it); a segment of an older version that holds no commit (it starts at the next
commit) is replaced whole, atomically, by one of the current version under the same name that
holds the same records. Such a segment is no rarity: a checkpoint taken while the store is open
starts a segment named by the next commit and writes its Checkpoint record there (9.7), and a
mark set afterwards adds its Mark record. Those records keep their bytes (their frames do not
depend on the file format version), a torn tail after them is cut (9.6), and a commit record in
the segment is damage (it holds a commit the store's state does not).
A new FILE format version alone needs no upgrade and no table row: a store of store format version 3 written by 0.2.x (files of version 2) was opened and continued as it is by a reader of file format version 3 (Graphersal 0.3.x); its version 2 files stay, the files written from then on are of version 3 (a new WAL segment, new snapshots), and from then on 0.2.x refuses the store as newer (15).
- New definition kinds (6.3), new payload keys of a known kind, new segment kinds (7.5) and named extra files (8) do not change the version: the rules of 16 tell every reader how to treat what it does not know. The layer file (7.5, kind 128) is the exception: its kind alone would let an older reader load a layer's own elements as a whole graph, so a layer snapshot is of file format version 5 (below).
16. Extensibility
The format is meant to grow without migrations. These rules bind every reader and writer of store format version 4 and file format version 4:
- Length before payload, payload as a map. Every definition carries its length before its
payload (6.3), so a reader skips an unknown kind by its length; a payload is a property map,
so a reader ignores unknown keys of a known kind. A new field is a new key, never a new
layout. Payload keys are never
kind,nameorflags(6.3). - Unknown, not critical: kept. A definition of an unknown kind without the critical flag is kept as opaque bytes (kind, flags, name, payload) and written back unchanged at the next checkpoint and in every copy (fork, backup, ZIP, repair), so an older reader never drops a newer definition. Unknown keys of a known kind are kept the same way (their values, written after the known keys in the order read).
- Unknown and critical: read-only. A critical definition of an unknown kind, or a file of a critical unknown segment kind (7.5), must stay consistent with the data (an index, for example); a writer that does not maintain it would corrupt it. A store holding one opens read-only for that reader (12.1), and a writer never stores such a definition itself (9.3).
- One WAL op for every kind. Op 10 (9.3) carries every definition change; a new kind needs no new op and no new version. Its replay follows rules 2 and 3.
- Large data in files of its own. The manifest is read whole and bounded at 256 MiB: a feature with large data stores a definition in the catalog plus files in the snapshot directory, referenced from the segment table by a new segment kind (7.5) with the same critical/ignorable rule; packed snapshots carry such a file as a named extra file (section kind 5, 8).
- Two version axes. The format version (the byte structure; with rules 1-5 it rarely
moves) and content versions such as a saved query's
dialect: a DSL evolves by compiling the stored text, never by re-encoding files. - Upgrades without the older build. Every release reads every released store and file format version (15), so a store of a released older version is upgraded by the current build itself (15.1); a store format change keeps that possible. A packed snapshot of an older file format version loads as it is.
- Host kinds. Definition kinds 128-255 (6.3) belong to hosts, the applications built on a library that implements this format; the format never assigns them, so a host entity never collides with a future library kind. To the library a host kind is an unknown kind: kept as opaque bytes under rules 2 and 3 (a critical one opens the store read-only), never damage. A host SHOULD encode its payload as the property map of 6.3 (the reference implementation offers that codec publicly), so the payload stays inspectable and extensible by key.
- An unknown value of a known key is not damage. Damage is what a checksum, a length or
the byte structure (value tags, record types, mutation ops, guarded by the format version,
15) says is wrong. Content behind a valid checksum that the reader cannot interpret was
written by a newer writer, and a reader MUST NOT report it as damage or offer a repair that
would drop it (a repair by a reader that cannot read it loses it):
- in a definition payload (6.3): kept and not served (an unknown value it can represent), or kept opaque (a payload it cannot read as its kind at all); a critical one opens the store read-only (rule 3);
- in the graph schema (
schema.json, 6.1; a schema image of op 9, 9.3): the schema changes what writes are allowed, so it is never ignored. A reader opens the store READ-ONLY (the data without the schema; nothing is written, not even a torn-tail cut) and refuses every operation that would write a state derived from it (a checkpoint, a fork, a repair) as unsupported; a backup copies its bytes as they are; verify reports it as a note, not a problem; - an
INTENToperation (11.1) or aGRAPHstate value (5.1) the reader does not know, and a well-formed entry outside its layout in a backup archive (12.8): refused as unsupported, never damage.
- Side areas of the store. A directory at the store root that a reader does not know (as
models/is for a reader older than 4.5) is left alone: never listed as damage, never removed by a prune or a compaction, not copied by that reader's copies. A new side area therefore needs no new version when an older reader ignoring it cannot misread the store; the copies it misses are listed with the area (4.5).journal/andINSTANCE(4.7) are such areas for a reader older than 4.7 (it refuses a store whose journal segment has a newer file format version through the header walk of 15, like any newer file).blobs/andledger(4.6, 10.1) are side areas too; a store referencing a blob holds files of file format version 4, which an older reader refuses as newer.
17. Conformance notes
Readers
- Check every CRC before using the bytes it covers; check every count and length against the remaining input before allocating (2).
- Never treat damage as a torn tail: apply 9.6 and 14.4 exactly. Never skip an unknown record type, value tag or mutation op.
- Keep what you do not know (16): an unknown definition byte for byte, unknown payload keys of a known kind, an unknown value of a known key (not served, written back as read), an ignorable file of an unknown segment kind in every file-level copy; open a store with something critical you do not know, or a graph schema you cannot parse, read-only. Content behind a valid checksum that you cannot interpret is never damage (16 rule 9).
- Replay only files whose
graph_idis on the lineage chain, each ancestor only up to its branch point (5.4), and require commit continuity (9.7). - A read-only reader of a store MUST NOT write anything into it, take the writer lock, or cut a torn tail. It SHOULD take the shared backup pin while it copies files, so that a prune cannot remove them meanwhile.
- A reader tailing a live WAL (CDC) reads only complete records with valid CRCs and treats an incomplete record at the end as "not yet written". Records before the writer's durable end are final; a record after it may still be cut off (9.7).
- Read every file with the version in its own header (15): accept files of format versions 1 to 4 in one store or packed snapshot, reject a temporal value tag in a version 1 file, a nanosecond temporal value tag (15 to 20) in a version 1 or 2 file and a blob reference (tag 21) or a Commit part record (type 4) in a file of version 1 to 3, and reject a temporal value outside its range (3) as damage; a zone name you do not know is unsupported content (3).
- Assemble a commit in parts (9.3.1) as ONE commit at the position of part 0; grow its body part
by part, never from
body_lengthup front; an incomplete commit in parts at the end of the last segment is a torn tail starting at part 0 (9.6). - Check a blob's length before reading it and its CRC-32C on every read; a missing or damaged blob fails only what needs its bytes and is never damage of the store (4.6, 13.4). Treat the content of a blob (a model tar, 4.5) as untrusted input.
- Treat
marksandledgeras derived from the WAL (10, 10.1) and the system journal as information only (4.7): a damaged or missing one is rebuilt or shown as a note, never damage, and nothing is decided from the system journal. - A store whose current schema needs a model (4.5) is opened only with that model loaded, or read-only by a reader that cannot run models; a needed model that is missing, damaged or does not fit refuses the open.
Writers
- Write every new file with the current file format version (4) and
GRAPHwith store format version 4; never append a record to a WAL segment of an older file format version (start a new segment, 15.1), and never write a nanosecond temporal tag into a file of version 1 or 2. - Write a commit whose body is larger than the part size in parts (9.3.1): consecutive records of one segment, rotation only before part 0, one sync after the last part, and a failed part cuts the WAL back to part 0 (9.7, 9.9).
- Write a blob completely (temporary name, sync, rename, directory sync) BEFORE the commit that references it, and remove a blob only when no retained history references it (4.6, 12.4).
- Never copy instance data (
WORKLOADexcept into an upgraded copy,INSTANCE, the locks) as part of another store (4.4, 4.7); never write the system journal of a read-only store or of a store in which damage was found (4.7). - Take every commit, mark and checkpoint time and every system-journal time from the instance clock (18).
- Follow the write ordering of 9.9: a WAL never holds a commit that did not happen, and a caller never gets "ok" for a commit that is not durable under the configured durability.
- Make files visible only when complete: a temporary name, sync, an atomic rename, a sync of the directory. Verify a snapshot before it is renamed (12.3).
- Write
GRAPHas specified in 5.3,wal_headas in 9.8, and every multi-file change under anINTENTwith idempotent steps (11.1). - Never remove WAL or snapshots implicitly: only an explicit prune (12.4), a rollback (12.5) or removal of an attic entry removes history.
- Record only store-relative names (4.2).
18. Time: the instance clock
Every time a store's history holds (commits, 9.3; marks, 9.4; checkpoint records, 9.5) and every time of the system journal (4.7) is read from ONE clock per instance (a process that has the store open, or a closed-store operation, 12.12):
- Reading. A reading is
max(system clock, floor)in microseconds (section 2) and raises the floor to itself, so readings never decrease (two readings may be equal). A commit's time is at least the time of the commit before it, and a record about commit N (a mark, a checkpoint, a journal record) is never earlier than commit N. - The floor is not stored. When an instance opens a store, or a closed-store operation starts, the floor is raised to the latest time the store's files hold: the loaded snapshot's times (6.1: created at, last commit at), every commit, mark and checkpoint record of the replayed WAL, and the newest record of the system journal. A recovery to a target (12.1) raises it from what it read; a read-only view of a past position uses the store's full floor.
- A system clock that steps back (a resumed virtual machine, a manual change) leaves every
time at the floor until the system clock passes it again; a step of more than one second is
reported (the reference implementation writes a
clock.step_backjournal record). Times therefore stay monotonic, and the target "the last commit at or before time T" (12.1) stays well defined. - Times that are not part of the history (the "created at" of a snapshot manifest, a WAL
segment header, the times of
GRAPH, backups and attic entries) are informative and read from the system clock.