pub struct ReplicationEngine<S: SyncEngineRef = NoOpSyncEngine> { /* private fields */ }Expand description
The main replication engine.
Manages bidirectional data sync between this node and its mesh peers.
§Sync Engine Integration
The replication engine is passed a reference to the local sync-engine by the daemon. We use this to:
- Write replicated data from peers (
submit) - Check for duplicates before applying (
is_current) - Query Merkle tree for cold path repair
We never write to any CDC stream — that’s sync-engine’s responsibility. We only read from peer CDC streams and write to local sync-engine.
Implementations§
Source§impl ReplicationEngine<NoOpSyncEngine>
impl ReplicationEngine<NoOpSyncEngine>
Sourcepub fn new(
config: ReplicationEngineConfig,
config_rx: Receiver<ReplicationEngineConfig>,
) -> Self
pub fn new( config: ReplicationEngineConfig, config_rx: Receiver<ReplicationEngineConfig>, ) -> Self
Create a new replication engine with no-op sync engine (for testing/standalone).
The engine starts in Created state. Call start()
to connect to peers and begin replication.
Source§impl<S: SyncEngineRef> ReplicationEngine<S>
impl<S: SyncEngineRef> ReplicationEngine<S>
Sourcepub fn with_sync_engine(
config: ReplicationEngineConfig,
config_rx: Receiver<ReplicationEngineConfig>,
sync_engine: Arc<S>,
) -> Self
pub fn with_sync_engine( config: ReplicationEngineConfig, config_rx: Receiver<ReplicationEngineConfig>, sync_engine: Arc<S>, ) -> Self
Create a new replication engine with a sync-engine reference.
This is the primary constructor used by the daemon.
§Arguments
config- Replication configurationconfig_rx- Watch channel for config updatessync_engine- Reference to local sync-engine (for writes and dedup)
Sourcepub fn sync_engine(&self) -> &Arc<S>
pub fn sync_engine(&self) -> &Arc<S>
Get a reference to the sync engine.
Sourcepub fn circuit(&self) -> &Arc<SyncEngineCircuit>
pub fn circuit(&self) -> &Arc<SyncEngineCircuit>
Get a reference to the circuit breaker for sync-engine protection.
Sourcepub fn state(&self) -> EngineState
pub fn state(&self) -> EngineState
Get current engine state.
Sourcepub fn state_receiver(&self) -> Receiver<EngineState>
pub fn state_receiver(&self) -> Receiver<EngineState>
Get a receiver to watch state changes.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if engine is running.
Sourcepub async fn health_check(&self) -> HealthCheck
pub async fn health_check(&self) -> HealthCheck
Get comprehensive health status for monitoring endpoints.
Returns a HealthCheck struct containing:
- Engine state and readiness
- Sync-engine backpressure status
- Per-peer connectivity, circuit breaker state, and lag
Performance: This method performs no network I/O. All data is collected from cached internal state (atomics, mutexes, watch channels).
§Example
let health = engine.health_check().await;
// For /ready endpoint
if health.ready {
HttpResponse::Ok()
} else {
HttpResponse::ServiceUnavailable()
}
// For /health endpoint (full diagnostics)
HttpResponse::Ok().json(serde_json::json!({
"healthy": health.healthy,
"state": health.state.to_string(),
"peers_connected": health.peers_connected,
"peers_total": health.peers_total,
"sync_engine_accepting_writes": health.sync_engine_accepting_writes,
}))Sourcepub async fn start(&mut self) -> Result<()>
pub async fn start(&mut self) -> Result<()>
Start the replication engine.
- Opens cursor store (SQLite)
- Connects to all enabled peers
- Spawns hot path tailers for each peer
- Spawns cold path repair task (if enabled)
Sourcepub async fn shutdown(&mut self)
pub async fn shutdown(&mut self)
Shutdown the replication engine gracefully.
Shutdown sequence:
- Signal all hot/cold path tasks to stop
- Wait for tasks to flush pending batches (with timeout)
- Shutdown peer connections
- Checkpoint and close cursor store
Sourcepub fn peer_manager(&self) -> &Arc<PeerManager>
pub fn peer_manager(&self) -> &Arc<PeerManager>
Get the peer manager (for metrics/diagnostics).
Auto Trait Implementations§
impl<S = NoOpSyncEngine> !Freeze for ReplicationEngine<S>
impl<S = NoOpSyncEngine> !RefUnwindSafe for ReplicationEngine<S>
impl<S> Send for ReplicationEngine<S>
impl<S> Sync for ReplicationEngine<S>
impl<S> Unpin for ReplicationEngine<S>
impl<S = NoOpSyncEngine> !UnwindSafe for ReplicationEngine<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more