Skip to content

Storage schema

Everything a node persists is in its data directory (--data-dir, by default {home}/{node}/data):

<data-dir>/
├── store/ one RocksDB database for every group on this node
├── snapshots/ sealed snapshot files, one current per group
├── components/ compiled components, each with a MAC under a key from K_c
├── cluster-key K_c, AES-256-GCM under HMAC-SHA256(K_r, "calimero.cluster-key.wrap.v1")
└── signing-key the receipt key, under HMAC-SHA256(K_r, "calimero.signing-key.wrap.v1")

Every value the node writes is CBOR (calimero-cbor, the codec apps store their values in): Raft entries and group metadata, an app group’s and the system group’s rows, and the system state’s checkpoint. A row a replica writes as it applies an entry is deterministic CBOR (calimero_node::stored::row: map keys sorted), so replicas that applied the same entries hold the same bytes; a log entry, which the leader writes once and every replica keeps as written, keeps its maps in their own order (stored::entry).

The database is opened with tuned column and table options (calimero-log’s tuning): compression, bloom filters, one bounded block cache (128 MiB). Log appends, votes and blobs are synced writes; RocksDB shares one WAL sync between the groups writing at once, and groups never queue behind one another.

Column Key Value
log group (u64 BE) ‖ index (u64 BE) A Raft entry, CBOR (its command as a byte string)
meta group ‖ name vote, committed, purged, applied (last applied log id and membership), generation, snapshot (the current snapshot’s metadata and file); and, under the node’s own group (u64::MAX, NODE_ROWS), format (the store format) and rollback ({ node, entry: { generation, mark }, epoch }, the rollback counter)
state group ‖ generation (u32 BE) ‖ machine key The state machine’s rows
blobs name Bundles, uploaded releases and app blobs, by hex(SHA-256)

Rows are stored as they are (store formats 2 and 3): the data directory is on the data disk the TD encrypts itself (Encryption). What is sealed with AES-256-GCM under the cluster key K_c, with a random 96-bit nonce stored in front and bound as associated data to its column tag, its group and its key ("cl" ‖ tag ‖ group ‖ key), is the node’s own rows (NODE_ROWS: the store’s format, the rollback counter) and every row of a snapshot file, sealed as the snapshot is built and opened as it is installed. A snapshot row’s associated data names its machine key but not its generation, the shape every release writes, so nodes of either store format exchange snapshots. Format 1 sealed every value this way; format 2 reads no store from before it.

Two further keys are derived from K_c (HMAC-SHA256(K_c, label)):

  • calimero.log.hidden-keys.v1 keys the HMAC that hides row keys;
  • calimero.log.snapshot.v1 seals snapshot frames.

A machine can hide a key (StateTx::put_hidden). The row is then stored at tag ‖ HMAC(group ‖ tag ‖ key) (33 bytes), and the value, before sealing, is u32 BE key length ‖ key ‖ value. The disk then shows neither which keys an app uses nor how they sort; reading a hidden key needs K_c.

An entry’s apply reads rows through its batch (StateTx). A read that fails (a storage fault, a hidden row that is not a hidden row’s shape, a row the machine cannot decode) fails the batch: nothing in it commits, the applied index stays where it was, and the group stops on that entry on this node. Reading the row as absent would apply the entry differently from the replicas that read it, with nothing to show for it. A machine’s restore and a hidden-row scan fail the same way; only answers (views, routes) read a fault as absent, and log it.

An app group’s machine key space (crates/node/src/app.rs, rows). Hidden rows (the key on disk is an HMAC) are those whose names or ids would say something about the app:

Row Hidden Holds
c + the app’s key yes The component’s storage: what its runs write (storage.put, add, delete)
j + caller|key yes Idempotency records: the answer replayed for a repeated key, and its expiry
q ‖ class ‖ n no The idempotency keys in the order they were recorded, per class (client keys, node keys)
h no The Head: bundle, executor, initialized and init error, last applied index, event-ring bounds, and the component’s host records (timers, id terms, compute component, active and finished runs and pipeline runs, the step cache’s keys, lastWriteMs, the time of its last write, left out until the first)
e ‖ n (u64 BE) no Event n of the event ring (the last 10 000), with its audience
b + blob id yes The app’s record of each blob and sealed file (size, mime, idle time, a file’s seal and wrapped key)
o ‖ seq, d ‖ n yes The xcall outbox and its dead letters
a + action id yes Pending actions
u + run id yes Compute run records
p, y, v, x yes Pipeline runs, their step items, step-run proofs, and the step cache

An SDK 0.12 app’s rows (k, i, r) are kept as they were and read by no run: that runtime is gone.

Only the Head is kept in memory; runs read the app’s keys through the group’s state (KvView), so an app’s state is never loaded whole.

The system group keeps its state in memory and writes one checkpoint row (\0calimero.log.checkpoint) with each snapshot.

A snapshot is snapshots/<…>.snap: a first line naming its format (CALIMERO-SNAPSHOT-3, Format versions), then frames of up to about 1 MiB of rows each, each frame sealed with associated data naming the group, the snapshot id, the frame’s position and whether it is the last. A reader refuses a frame over 64 MiB. A row too large for one frame (an in-memory machine’s checkpoint, which holds the whole system state) is written in pieces of about 1 MiB, one frame each: a row entry whose value length has its top bit set is a piece, and the next entry, under the same key, continues it. It is written from a consistent RocksDB view, so a large state is streamed rather than held in memory. A follower receiving one writes it to a file first, then installs it as the next generation in batches of about 4 MiB and switches generations in one batch (Replication).

A backup is a copy of a group’s current snapshot file under {backup-dir}/{app}/{index:020}.{group}.{snapshot}.snap, with its sealed manifest beside it (….snap.manifest, backup format 1; a lone snapshot file is format 0) (The operator). backup::find checks a backup against its manifest; backup::latest opens the newest one with K_c and returns its index and rows. A restore writes a backup’s rows into a new group (Group::replace_state): each row is opened and sealed again for that group, and a hidden key is hidden again under it.

The recovery disk (--recovery-dir, merod) holds a second set of backups, sealed to the public key of whoever upgrades each app rather than to K_c, so they open after every mero-kms is gone (Recover after every key service is gone). Each holder has a directory, named for its key with : made -: operator/ when the operator holds app upgrades, else org-<id>/ for the app’s organization (recovery_disk::holder_dir, SystemState::backup_holder; since 1.0.0-rc.20 every app is in an organization, so no account holds backups). In it, every RECOVERY_EVERY (5 minutes), each node writes:

File Holds
app-<app>.<index>.<writtenAt>.rbak one app’s state at that log index: its directory record and file key, then its rows as calimero_log::PortableRows (a hidden row by the key it hides, so a group under another K_c hides it again)
holder.<index>.<writtenAt>.rbak an organization’s slice of the system state (system::HolderSlice: the org, its people’s accounts and passkeys, its apps, the bundles and releases they run)
system.<index>.<writtenAt>.rbak the operator’s: the whole system state
code-<hash>.rbak one bundle or release .mpk an app runs, written once
seg-<hash> one segment of a sealed file an app lists, copied as stored (already ciphertext under the file’s own key); deleted SEGMENT_KEEP (7 days) after no held app lists it

Index and time are zero-padded to 20 digits, so names sort oldest first; the newest KEEP (3) per subject stay, and a subject unchanged since its last file is not written again.

An .rbak file (calimero_client::recovery, format 1) is:

  1. calimero.recovery-backup.v1\n (MAGIC);
  2. the header’s length (u32, big-endian), then the header, JSON (camelCase, unknown fields refused, at most MAX_HEADER_BYTES, 1 MiB): format, kind (app, holder, system, code), holder, cluster, app, org, hash, group, index, writtenAt, the merod and mero-tee release that wrote it, node, recipient (the holder’s X25519 public key), enc and wrappedKey (the body’s data key, sealed with HPKE, RFC 9180, base mode: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-256-GCM; info calimero.recovery-backup.v1, associated data calimero.recovery-backup.key.v1), size and sha256 of the plaintext, bodyBytes and bodySha256 of the ciphertext, signingKey (the node’s receipt key) and attestation;
  3. 64 bytes: the receipt key’s Ed25519 signature over calimero.recovery-backup.v1\0 followed by the header bytes;
  4. the body: the plaintext sealed under that data key as a sealed file is (64 KiB AES-256-GCM STREAM chunks, Sealing).

The attestation is the writing node’s purpose=receipts quote over the nonce SHA-256("calimero.recovery-backup.attest.v1\0" || u32 length || cluster || u64 node) and the receipt-key binding (receipt-key.v3: the key, the governance, the cluster and the node id). A reader checks the signature, that the attestation names the header’s cluster and node and binds the signing key, and the quote under its own policy, before it opens a key; a node takes no recovery file whose attestation its peer policy refuses (400 UNATTESTED_RECOVERY_FILE). The holder opens the data key on its own device (meroctl ops recovery-keygen and ops recover for the operator, mero-js’s and calimero-client-py’s recovery modules for an organization or account) and sends only that key; no node holds a holder’s private key.

Each container of what a node keeps names the format it was written in, so a node tells “an older format, which needs its reader” from “damaged”, and refuses what a later release wrote instead of misreading it:

Container Where the version is This release Unmarked (written before markers)
The store (every row of every column) node row format in meta (sealed, calimero_log::STORE_FORMAT) 4 (CBOR rows, the system group sharded; only format 4 is read) refused, as every format before 4
Snapshot and backup files the first line, CALIMERO-SNAPSHOT-<n> (calimero_log::SNAPSHOT_FORMAT) 3 (format 2’s framing, store format 4’s rows; only format 3 is read) none: every file says its format
A component app’s log entries (with the outcomes and file marks they carry) the first byte, a CBOR integer below 24 (component::ENTRY_FORMAT); a JSON entry (format 1) starts { 2 (CBOR; only format 2 is read) format 1, JSON: refused
Sealed files and their segments the domain strings the chunk AAD and the file id are bound to (calimero.file.v1, calimero.file.segments.v1) v1 none
Recovery files (.rbak) the first line, calimero.recovery-backup.v1, and the header’s format (calimero_client::recovery::FORMAT) 1 none

The store’s format is settled when the engine opens it, before any group starts: an empty store takes the current format, and a store in any other format is refused (the store is in format N, and this release reads format 4 only), and the node does not start. No earlier store is read; a rollout never needs one, since a new release’s nodes start on empty data directories and receive their data by snapshot, whose format is unchanged. A snapshot or backup of a later format is refused by its first line, as is one from before a cutover, and an app entry of another format stops the app’s group on the replica that meets it, which logs the format it found (a release that raises the entry format writes it only once every replica of the group reads it, or declares a cutover, so only a replica on another release than its group meets one).

Changing a row, a snapshot’s framing or an entry’s meaning raises the matching number in the same change and keeps a reader (a migration step, or the old shape’s decoder) for what is already written; a change with no reader is a hard cutover, declared by ! in its PR title and in mdma’s release compatibility table before it ships. The format row shows under the node’s own rows (group 18446744073709551615) in merod inspect with the key.

No release reads an earlier store in place: the redb store from before RocksDB, and store format 1, are refused as above. A cluster moves onto a new release by adding nodes with empty data directories, which receive their data by snapshot.

1.0.0-rc.20 is a hard cutover on top of this: a data directory or log that holds an app outside an organization is not read, so clusters are recreated on that release and nothing written before it is replayed (changelog).

1.0.0-rc.40 is another (store format 3): the system group is sharded into root, a tenant group per organization and the session groups, and an earlier release’s single system log is not split. A node does not start on an earlier data directory, and a cluster founded again from its backups (--restore-from) refuses a system backup that holds an organization no tenant group holds (Node::refound): an earlier release’s organizations, which no group of this release would serve. Clusters are recreated on 1.0.0-rc.40.

It is also where every stored value became CBOR (store format 4, snapshot format 3, entry format 2): no JSON row, entry or snapshot of an earlier release is read, backups included, so a cluster of an earlier release is not founded again from its backups on this one.

merod inspect [--storage-key-file F] summarizes the store’s layout and sealed sizes; with the key, it also opens each group’s metadata (vote, applied index, membership). It opens the store for writing, so stop the node first.

Where the node implements this chapter, by the names in its code: paths are under crates/node/src unless another crate is named. The design and its reasons are above; a module’s own detail is in its //! doc, and the node’s mental model is crates/node/AGENTS.md.

Code: app.rs, component.rs.

AppMachine holds no state in memory but its small Head (bundle, executor, the component’s host records). The app’s keys are hidden rows of its group (rows::CKV), idempotency records too (rows::CIDEM), events a ring of EVENT_RING (rows::EVENT). The system group stays in memory (Machine::IN_MEMORY). Backups (Node::backup) copy the group’s sealed snapshot file, without the run keys an app’s state holds (calimero_log::filter_snapshot_file; the system group’s is copied as it is), with a sealed manifest beside it (backup::Manifest: app, group, index, SHA-256, backup::FORMAT, the merod and release that wrote it, bound to the app and file name under HMAC(K_c, "calimero.backup.manifest.v1")); backup::find checks one, backup::latest opens one with K_c. The file and its manifest are synced before the rename that lists the backup, and the directory after it (likewise kept code and the kept cluster key). That file work (keep_cluster_key, keep_code, backup::write) runs off the async workers (node::off_workers): a copy and its fsyncs on a slow disk would stop every group’s heartbeats on the worker.

Code: crates/node/src/rollback.rs, crates/kms-client/src/kms/rollback.rs (rollback protection).

With a key from mero-kms that keeps counters (kms::KmsCounter, Config::rollback), the node keeps an entry (generation, mark) in its store (Engine::put_node_meta, row rollback, bound to its node id) and raises it with mero-kms’s every CHECKPOINT_EVERY (1 s), store first (Checkpoints::run, from lib.rs). Node::start judges the store before any group starts (rollback::judge): behind mero-kms, empty under a used id, mero-kms without the node’s entry, another node’s store, or a protected store answered without counters are refused; a KMS without counters and a store without one start unprotected. Config::accept_rollback (merod run --accept-rollback) resets the node’s entry to the store’s and raises the cluster epoch. Reported in /ops/status (rollback) and /health (rollbackEpoch).

Code: node/restore.rs, api/restore.rs, POST /ops/apps/{app}/restore.

Operator-signed (<app> / __restore_app / { backup, sha256 }, and for a pinned instance bundle and computeBundle too, SystemState::restore_args), judged before the signature (backup::find, Found::check_release, the bundle the backup’s head names still installed, require_current_release). SystemCmd::RestoreApp moves the app to a new group with the receiving node first (AppRecord.restore, so ensure_app_group forms it with that seed alone and reconcile never inits it); the seed Group::replace_states the backup into it (rows opened and sealed again for the new group, hidden keys re-hidden), appends componentRestored (sets ComponentHead::id_term_base past every restored id term: the new group’s terms restart at 1, D52), snapshot_through + purge_log_through that entry so the others can only catch up from that snapshot, adds them as learners, makes them voters and logs FinishRestore. Calls and views answer 409 APP_RESTORING meanwhile (restore::refuse_while_restoring). The old group’s files are kept (reconcile drops a stopped group’s files only for a deleted app).

Code: --restore-from DIR with --bootstrap, Node::refound.

Backups also hold the system group (backup::SYSTEM, written by its leader, or by every node with ops/backup?all=true), the code it names (backup::keep_code, sealed under HMAC(K_c, "calimero.backup.code.v1")) and K_c wrapped under each release’s K_r (backup::keep_cluster_key). cluster_key::resolve takes K_c from the copy this node’s K_r opens (backup::cluster_key_from); Node::start forms the system group with the founder alone; reconcile (empty state) calls refound: governance and operator key must match the backup’s, no old replica node may still answer at an address --peers does not reuse, then Group::replace_machine_data with the state system::refound made (fleet = --peers, every app PendingRestore::AWAITING_BACKUP, hosted nowhere), snapshot_through + purge_log_through; the other peers join as registered learners.

Code: recovery_disk.rs, node/recovery_disk.rs, api/backup_keys.rs; holder side calimero_client::recovery.

With --recovery-dir, every node::recovery_disk::RECOVERY_EVERY (5 min) each node writes, for every app it holds (leader or not; Node::write_recovery), the app’s snapshot as portable rows (calimero_log::read_snapshot_rows: hidden rows by the key they hide), the code it runs, and per holder its system::HolderSlice (the operator’s: the whole SystemState), each a .rbak file sealed to the holder’s X25519 key (HPKE; a fresh data key per file, chunked as files are) and signed by the receipt key, its purpose=receipts attestation in the header (recovery_disk::attestation_nonce). The holder is whoever upgrades the app (SystemState::backup_holder: the operator, else the app’s org or owner account; a publisher-upgraded package’s too). SetBackupKey (Feature::BackupKeys; SystemState::may_set_backup_key, backup_keys): /ops/backup-key (operator-signed operator / __set_backup_key / { publicKey }), /orgs/{org}/backup-key and /auth/backup-key (passkey, org:<org> / account:<a>). A subject unchanged since its last file is not written again; KEEP (3) per subject. Operator recovery: merod --bootstrap --recover-from DIR forms the system group alone and writes no genesis; POST /ops/recover (Node::recover_system: the system and code files’ keys, the same checks as refound) seeds it; POST /ops/apps/{app}/restore { recovery } restores each app (Group::replace_state_rows in Node::seed_with). An org or account: POST /recover/holder from the holder’s device (its keys), admitted by the operator’s signature over cluster / __recover_holder / system::import_holder_args; SystemCmd::ImportHolder adds the org, accounts (and credentials), apps (each in a new group seeded by the receiving node), bundles, releases and the key, refused where any is here. GET /ops/recovery-files lists headers and signatures, never keys. Sealed files: each segment an app’s files list is copied beside its files as stored (seg-<hash>, write_recovery_segment; unlisted ones go after SEGMENT_KEEP), loaded back and checked by hash before a restore (Node::load_recovery_segments, 409 RECOVERY_SEGMENTS_MISSING), and each file’s data key is wrapped again under the new cluster’s file key (node::recovery_disk::rewrap_row, from AppMeta::file_key). Every recovery file used is attested under the peer policy (Node::check_recovery_attestation, 400 UNATTESTED_RECOVERY_FILE).