Files
database/factory/replication_test.go
zeekayandHanzo Dev fb16ece6a3 feat(zapdb): native ZAP replication — CDC, physical snapshots, PQ, streaming
Replicates a zapdb to S3 via hanzoai/vfs with no keyspace scan in steady state
and post-quantum encryption out of the box.

- CDC incrementals via db.Subscribe (the WAL tail), not Backup(since)'s O(total)
  scan — a 100-key delta out of 200k keys: 2.76us/19KB vs 20ms/1GB (~7000x).
- Physical SST-copy snapshots (sparse, hole-aware): 134ms/25MB vs logical
  158ms/1.25GB/2.2M allocs. Hydrated before Badger opens; incrementals replay on top.
- Streaming codec: Backup -> zstd -> age into a pooled buffer (peak mem = compressed).
- Post-quantum (ML-KEM-768 + X25519 via luxfi/age v1.5.0), client-side before S3.
  Out of the box via REPLICATE_AGE_KEY_FILE (generate+persist, recipient derived).
- Per-DB streams (REPLICATE_AUTO_ON_OPEN) for subprocess VM plugins; backer/restorer
  split (REPLICATE_BACKUP / REPLICATE_SOURCE_ORDINAL) for multi-node.
- Public imports only (hanzoai/vfs v0.4.1, no replace). Verified live on an EVM
  C-chain end-to-end incl. disaster-recovery exact-match. Canonical KV schema
  (zapdb/zapdb.zap) + zero-copy codec (zapkv.go). Renames engine alias badger->zdb.

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-16 02:00:03 +00:00

40 lines
1.3 KiB
Go

// Copyright (C) 2020-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package factory
import (
"os"
"testing"
"github.com/luxfi/database/memdb"
)
// startReplicationIfBase must be a pure pass-through unless this is the base DB
// (meterDBRegName=="all") AND replication is configured. This is the guard that
// keeps VM-plugin subprocesses — which pass "meterdb" and inherit the same
// REPLICATE_* env — from replicating their chain DB onto the base node's S3 path.
func TestStartReplicationGate(t *testing.T) {
t.Setenv("REPLICATE_S3_ENDPOINT", "http://s3.invalid:9000")
// Plugin DB name must never trigger replication, even with env set.
db := memdb.New()
if got := startReplicationIfBase(db, "meterdb"); got != db {
t.Fatal("plugin DB (meterdb) must pass through untouched")
}
// memdb is not Replicatable, so even the base name is a safe no-op (the
// UnwrapTo assertion fails and we return the db unchanged).
if got := startReplicationIfBase(db, "all"); got != db {
t.Fatal("base DB pass-through must return the same db")
}
}
func TestStartReplicationDisabledWithoutEnv(t *testing.T) {
os.Unsetenv("REPLICATE_S3_ENDPOINT")
db := memdb.New()
if got := startReplicationIfBase(db, "all"); got != db {
t.Fatal("no REPLICATE_S3_ENDPOINT must be a pure pass-through")
}
}