Skip to main content

Module replicated_engine

Module replicated_engine 

Source
Expand description

ReplicatedEngine — convenience wrapper for the common primary + replica pattern.

Eliminates the three-step boilerplate of wiring an Engine with HttpReplicationServer and AntiEntropyLoop.

§Primary

use edgestore::EdgestoreConfig;
use edgestore_repl::ReplicatedEngine;

let primary = ReplicatedEngine::open_primary(
    EdgestoreConfig::new("/var/db/primary"),
    "0.0.0.0:8900",
).unwrap();

primary.engine().lock().unwrap().put(b"products", b"p1", b"data").unwrap();

§Replica

use edgestore::EdgestoreConfig;
use edgestore_repl::ReplicatedEngine;

let replica = ReplicatedEngine::open_replica(
    EdgestoreConfig::new("/var/db/replica"),
    "http://primary-host:8900",
).unwrap();

// Engine is read-only — write attempts return Err(EdgestoreError::ReadOnly).
let val = replica.engine().lock().unwrap().get(b"products", b"p1").unwrap();

§Wake-on-flush (reduced replication lag)

Primary registers an on_segment_flushed callback via Engine::with_on_segment_flushed before passing the engine to this wrapper. The callback wakes the anti-entropy loop via a channel instead of waiting for the poll interval.

Structs§

ReplicatedEngine
Wraps Engine + HttpReplicationServer (primary) or Engine + AntiEntropyLoop (replica).