Skip to main content

SyncEngine

Struct SyncEngine 

Source
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

Source

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.

Source

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.

Source

pub fn get_ops_since(&self, since_hlc: i64) -> Result<Vec<SyncOp>>

Return all ops with hlc_ts > since_hlc, ordered by timestamp.

Source

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 as applied).
  • If a conflict exists → apply the configured ConflictStrategy: the winning op is inserted/updated; conflicts is always incremented; the losing op increments skipped.
Source

pub fn add_peer(&self, peer_id: &str, endpoint: Option<&str>) -> Result<()>

Register a peer node, optionally with a network endpoint.

Source

pub fn sync_status(&self) -> Result<Vec<PeerStatus>>

Return the sync status of every registered peer.

Source

pub fn set_strategy(&mut self, strategy: ConflictStrategy)

Change the conflict resolution strategy (default: LastWriterWins).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.