Operations · Engineering
Branching a database for CI and experiments
Copy-on-write clones, snapshot sources, sidecar rebuilds, and the limits of a branch with no merge.
A test suite that runs against a shared database is a source of flaky failures. One test deletes a document another test expects; parallel jobs conflict; a migration rehearsal mutates the only copy.
NonoDB can branch a database into a complete, independent copy: its own data.mdb, writer, lock file, indexes, TTL/history metadata, and search/vector sidecars.
Branch from the live directory
Stop the daemon first when cloning a live directory:
systemctl stop nonodbnonodb-cli --db app1 branch app1-ci --data /var/lib/nonodb --verifysystemctl start nonodbThe result is a new directory:
/var/lib/nonodb/├── app1/│ ├── data.mdb│ ├── lock.mdb│ └── search/└── app1-ci/ ├── data.mdb ├── lock.mdb └── search/lock.mdb is not copied; the daemon creates a new lock for the branch. The source is never modified.
Branch from a snapshot
A snapshot is already consistent, so it is the safest source while the daemon runs or when the live database must not be touched:
nonodb-cli branch app1-ci \ --from-snapshot /var/backups/nonodb/snapshots/app1/data-1767225600000.mdb \ --data /var/lib/nonodb \ --verify--from-snapshot accepts a snapshot file, a data.mdb file, or a directory containing snapshots (the newest is selected). Sidecars are looked up next to the file or inside the directory, so a root with search/ and vector-ann/ preserves them.
Daemon snapshots normally contain only data-<unix-ms>.mdb; sidecars stay with the live database. The branch command rebuilds missing text, fuzzy, and enabled ANN sidecars inside the staging clone before publishing it. That is why a snapshot-based CI branch can answer search and vector queries immediately.
Copy-on-write
On Linux the command tries FICLONE (reflink); on macOS it tries clonefile. On a CoW filesystem the branch is metadata-only and effectively instant even for a large database:
{ "target": "app1-ci", "method": "reflink", "bytes": 734003200, "elapsed_ms": 12, "sidecars": ["search"], "sidecar_rebuilds": 0, "verification": null}If reflinking is unsupported, it falls back to a full copy and reports "method": "copy" with a warning. The result is correct, but not instant.
--verify adds a deep LMDB/index check. It does not change the copy method.
Options and safety
| Option | Meaning |
|---|---|
--data ROOT |
Instance data root; defaults to NONODB_DATA |
--from-snapshot PATH |
Branch from a snapshot |
--force |
Replace an existing target only after the new branch is complete |
--verify |
Deep-verify before publishing |
--no-sidecars |
Skip copying and rebuilding search/vector sidecars |
--json |
Machine-readable result |
--force swaps the old target out only after the temporary branch is created and verified. A failed clone leaves the existing target intact.
Auth, TLS, backup configuration, audit logs, and other instance-wide files are not copied. A branch is a database, not a new instance.
--no-sidecars is an explicit opt-out. A clone made with it has no text, fuzzy, or ANN sidecars, so those queries fail until the daemon is restarted with NONODB_REBUILD_MISSING_SEARCH=1 or the branch is rebuilt without the flag.
CI example
BRANCH="ci-$CI_JOB_ID"nonodb-cli branch "$BRANCH" \ --from-snapshot "$SNAPSHOT" \ --data "$NONODB_DATA" \ --force
export NONODB_DB="$BRANCH"pytestRemove the branch directory after the job to discard all writes. There is no merge or rebase; use a new branch for each isolated run.
Limits
- Offline only. There is no daemon API for branching while the source writer is active; use a snapshot.
- Not a logical dump. Branching a stopped directory is a filesystem copy. Do not branch while another process writes.
- Sidecars are derived. A normal branch copies and rebuilds missing ones. The daemon does not rebuild on first query, only at startup with
NONODB_REBUILD_MISSING_SEARCH=1. - Reflink depends on the filesystem. XFS, Btrfs, and ZFS commonly support it; ext4 and some overlay filesystems fall back to a full copy.
- No merge/diff/rebase. A branch is not registered in a cluster automatically.
- Cluster metadata is not a branch. Do not use a branch as a failover replica.
When branches help
- integration tests that need a known dataset;
- migration rehearsals on a production-shaped copy;
- reproducing a bug without touching production;
- experiments with indexes or query plans;
- CI jobs that need isolated writes.
When they do not
Do not use a branch as a backup. A branch shares the same failure domain and does not give you history. Do not use it as a replica; replication has its own log, TLS identity, and promotion rules.
A branch is a disposable copy with a writer. Treat it that way, and delete it when the job is done.
The branching guide and backup guide cover snapshots, sidecars, and restore.