pub struct SyncEngine { /* private fields */ }Expand description
The primary entry-point for the sync layer.
Call SyncEngine::new once per database, then use
record_mutation after every write and
apply_remote_ops when you receive a
batch from a peer.
Implementations§
Source§impl SyncEngine
impl SyncEngine
Sourcepub fn new(db: &AgentDB, node_id: &str) -> Result<Self>
pub fn new(db: &AgentDB, node_id: &str) -> Result<Self>
Open the sync layer on top of an existing AgentDB connection.
Creates _adb_sync_log and _adb_sync_peers if they don’t exist yet.
Sourcepub fn record_mutation(
&mut self,
table: &str,
record_id: &str,
op: OpType,
payload: Option<Value>,
) -> Result<String>
pub fn record_mutation( &mut self, table: &str, record_id: &str, op: OpType, payload: Option<Value>, ) -> Result<String>
Record a mutation in the sync log and return its op_id.
Sourcepub fn get_ops_since(&self, since_hlc: i64) -> Result<Vec<SyncOp>>
pub fn get_ops_since(&self, since_hlc: i64) -> Result<Vec<SyncOp>>
Return all ops with hlc_ts > since_hlc, ordered by timestamp.
Sourcepub fn apply_remote_ops(&mut self, ops: Vec<SyncOp>) -> Result<SyncResult>
pub fn apply_remote_ops(&mut self, ops: Vec<SyncOp>) -> Result<SyncResult>
Apply a batch of ops received from a remote peer.
For each op:
- If no existing op exists for the same
(table_name, record_id)→ insert it (counts asapplied). - If a conflict exists → apply the configured
ConflictStrategy: the winning op is inserted/updated;conflictsis always incremented; the losing op incrementsskipped.
Sourcepub fn add_peer(&self, peer_id: &str, endpoint: Option<&str>) -> Result<()>
pub fn add_peer(&self, peer_id: &str, endpoint: Option<&str>) -> Result<()>
Register a peer node, optionally with a network endpoint.
Sourcepub fn sync_status(&self) -> Result<Vec<PeerStatus>>
pub fn sync_status(&self) -> Result<Vec<PeerStatus>>
Return the sync status of every registered peer.
Sourcepub fn set_strategy(&mut self, strategy: ConflictStrategy)
pub fn set_strategy(&mut self, strategy: ConflictStrategy)
Change the conflict resolution strategy (default: LastWriterWins).
Auto Trait Implementations§
impl Freeze for SyncEngine
impl RefUnwindSafe for SyncEngine
impl Send for SyncEngine
impl Sync for SyncEngine
impl Unpin for SyncEngine
impl UnsafeUnpin for SyncEngine
impl UnwindSafe for SyncEngine
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
Mutably borrows from an owned value. Read more