Operations: Backup, Compaction and Budgets
PARTIAL
ehgraph at git f200516 can ship a backup to a directory or to
Google Cloud Storage, can fold shipped change-log parts into a
snapshot, and bounds the memory an instance will hold. The page is
PARTIAL: there is no release tag, compaction is off unless the config
turns it on, and the 15-minute restore target in the operations page
has not been measured. The embedded graph's backup loop on production
had shipped nothing on the 2026-11-22 reading
(15.1).
GET /healthz returns instance_id, domain, role, and state
(serving once the process holds the lock). GET /metrics is
Prometheus text. Every series carries instance_id and domain
(docs/wiki/Operations.md).
Backup
backup_prefix chooses the target (crates/ehgraph-backup/src/lib.rs:5):
| Prefix | Target |
|---|---|
A filesystem path, such as /var/backups/ehgraph/ehgraph-network | A directory |
gs://<bucket>/<prefix> | A Google Cloud Storage prefix (lib.rs:119) |
Any other scheme:// is refused (lib.rs:132-136). S3 is not a
target at this revision.
Both targets follow one order (docs/wiki/Operations.md, and
ehgraph-backup/src/lib.rs:10-16):
- Immutable objects are put-if-absent: sealed parts, snapshots,
instance.json, and schema files. On GCS that is an upload withifGenerationMatch=0(crates/ehgraph-backup/src/gcs.rs:7). A retry does not rewrite an object that already landed. - Per namespace, the manifest is written after the parts it names, and the head after the manifest.
checkpoint.jsonis written last. A crash mid-ship leaves the previous checkpoint, and every object that checkpoint names exists.
ehgraph never deletes from a backup prefix. A GCS target uses
[backup] auth = "metadata" by default (the GKE metadata server,
Workload Identity), or env:VAR, or none for an emulator. Transient
errors (timeouts, 408, 429, 5xx) are retried 4 times
(gcs.rs:45, ATTEMPTS). A 401 or 403 is UNAUTHORIZED and names the
missing permissions. Inside the server, the graph uses the pod
identity the server's own GCP auth uses, or a token the host passes
through OpenOptions::backup_token (docs/wiki/Embedding.md).
A ship runs from the process that holds the lock: backup_interval_s
(0 means ship only when asked; DEFAULT), POST /v1/admin/backup with
an operator grant (namespace = "*"), or EhGraph::backup_now. The
ehgraph backup CLI takes the data-directory lock, so it fails while
the server or the embedding host is up. That is the single-writer rule
(15.2).
Restore is offline, into an empty data directory. It format-checks
checkpoint.json before it writes anything. A restored instance comes
up at the backed-up version. Later writes continue from there.
Restoring one instance does not touch another instance's directory or
prefix.
RPO is the unshipped tail: versions still in an unsealed part, plus
anything sealed and not yet copied. Age seal bounds how long a record
can sit unsealed (DEFAULT 30 seconds,
15.2). The operations page states the bound as
backup_interval_s + seal_max_age_s, and says that is 60 seconds with
the example config and that 60 seconds is the RPO target. That 60 is
GUIDANCE for the example config, not a measurement of a running
cluster. The reported series are
ehgraph_backup_lag_versions, ehgraph_backup_lag_seconds,
ehgraph_backup_failures_total, and
ehgraph_backup_last_shipped_timestamp_seconds (0 if nothing has ever
shipped).
RTO is the time to copy the prefix plus replay on open.
docs/wiki/Operations.md names a target of 15 minutes for one domain
at the planning size of about 10⁶ elements, and says that target has
not been measured against a real bucket (NOT_YET_MEASURED). The same
page, under "What the lag means", also says there is no numeric RTO in
this release and that restore time is the copy plus the rebuild. Both
sentences are in that file. This chapter does not pick one of them.
docs/wiki/Architecture.md says the backup directory "is a filesystem
prefix. It stands in for an object store until an S3-compatible client
is chosen." docs/wiki/Roadmap.md, under "Not in this release", still
lists "An S3 or GCS client" and "Compaction of log segments covered by
a retained snapshot." At f200516 the code has a GCS client
(gcs.rs, and open_target on a gs:// prefix) and has compaction,
off by default (below). docs/wiki/Operations.md matches the code.
The book follows the code.
Compaction, off by default
Without compaction the change log grows for the life of a namespace, and so does replay on open. With it on, sealed parts are folded into a full snapshot after each successful backup:
[store]
compaction = true # DEFAULT false
compact_min_parts = 8 # DEFAULT: compact only when at least this many parts can go
compaction defaults to false (crates/ehgraph/src/config.rs:145 and
the Default impl at :207). compact_min_parts defaults to 8
(config.rs:151-153).
A prefix of sealed parts is dropped only when every part in it is all
three of these (docs/wiki/Operations.md):
- Shipped: at or below the backup checkpoint's
backed_up_version. A part that was never backed up is never dropped. - Covered by a full snapshot written exactly at the new floor version.
- Outside the idempotency window, or it records no idempotency key. Those keys are already forgotten, so the window does not change.
The order is crash-safe. The floor snapshot is made durable, then the
new manifest (with floor_version and the pinned floor_snapshot) is
written, and only then are the part files deleted. A crash before the
manifest leaves the old log in force. A crash after it leaves part
files that the next open removes rather than re-adopts. A restore from
a backup prefix keeps every part it ever received, and open treats the
pre-compaction parts as already folded.
graph_at and graph.version.info at a version below the floor
return NOT_FOUND. The floor and everything after it stay readable.
snapshot_keep (DEFAULT 16) never removes the floor snapshot.
A compacted manifest is format 2, which older builds refuse
(15.5). Compaction runs under the backup's ship
lock, so it does not delete a part a ship is still copying.
The per-namespace series are ehgraph_log_parts, ehgraph_log_bytes,
ehgraph_log_floor_version, and ehgraph_open_replay_seconds.
Leave compaction off until rolling back past this release is no longer required. Turning it on writes format 2, and a server built before the pin cannot open that manifest.
Memory budgets
An instance holds three kinds of memory (crates/ehgraph/src/budgets.rs):
| Memory | Bound | On overflow |
|---|---|---|
| Materialized graph, every namespace, always resident | resident_graph_bytes | A write that would grow it is refused with MEMORY_BUDGET_EXCEEDED before it is logged. Writes that do not grow it, and opening, are not refused for this cap |
| Sessions (Arrow batches) | global_bytes, per_session_bytes | Ended sessions are evicted first, then the open fails with MEMORY_BUDGET_EXCEEDED. An active session is not dropped |
| Idempotency keys | idempotency_max_keys | The oldest keys are forgotten (15.2) |
Standalone defaults (DEFAULT, budgets.rs:77-82): 256 MiB for all
sessions, 64 MiB for one session, and an unlimited graph (0).
Embedded defaults come from the host limit: [budgets] host_memory_bytes, otherwise the container cgroup limit
(budgets.rs:20-31). For whatever the config leaves unset, the
resident graph gets 10% of the host, sessions get 10% together, and
one session gets a quarter of that session budget. Each derived value
is at least 16 MiB. Open refuses if the graph budget and the
session budget together exceed half the host
(budgets.rs:133-144). With no detectable limit, the fixed session
defaults apply and the graph is capped at 256 MiB
(budgets.rs:106-110). The server sets no [budgets] of its own, so
an armed embedded graph takes these derived numbers
(docs/wiki/Embedding.md). graph.instance.info reports them.
ehgraph_budget_bytes{kind} and ehgraph_resident_graph_bytes are
the series.
docs/wiki/Operations.md summarises
crates/ehgraph-store/tests/resident_bytes.rs as about 1,660 bytes per
element for a noetl-cluster-shaped graph (about six properties,
including a two-entry map on nodes, and one property on edges) and
about 670 bytes for an element with no properties. On that summary,
10⁴ cluster-shaped elements are about 16 MiB and 10⁶ are about 1.6
GiB, and the page says to budget about 20% more for allocator
overhead. The test itself asserts that the estimate stays within 25%
of the measured heap (resident_bytes.rs:133-137). This chapter did
not re-run the test, so those byte figures are the operations page's
summary, not a new measurement. The planning size of about 10⁶
elements is the roadmap's assumption (GUIDANCE), the same one
15.2 cites.
Call start_maintenance on an embedded graph. Without it, idle
sessions never expire and the budget fills
(docs/wiki/Embedding.md). The server does call it
(15.5).