pub struct StorageMirrorSync {
pub local_id: MirrorId,
pub local_state: HashMap<String, SyncItem>,
pub remote_states: HashMap<MirrorId, HashMap<String, SyncItem>>,
pub default_resolution: MsConflictResolution,
pub audit_log: VecDeque<SyncOperation>,
/* private fields */
}Expand description
Bidirectional synchronisation between storage mirrors.
Maintains the local state, one or more remote mirror states, resolves conflicts, executes sync plans, and retains a bounded audit log.
Fields§
§local_id: MirrorIdThe identifier for the local mirror.
local_state: HashMap<String, SyncItem>Current state of the local mirror (CID → SyncItem).
remote_states: HashMap<MirrorId, HashMap<String, SyncItem>>States of all registered remote mirrors.
default_resolution: MsConflictResolutionDefault strategy for automatically resolving conflicts.
audit_log: VecDeque<SyncOperation>Bounded audit log of executed operations (newest at the back).
Implementations§
Source§impl StorageMirrorSync
impl StorageMirrorSync
Sourcepub fn new(local_id: MirrorId, default_resolution: MsConflictResolution) -> Self
pub fn new(local_id: MirrorId, default_resolution: MsConflictResolution) -> Self
Creates a new StorageMirrorSync with the given local identifier and default conflict
resolution strategy.
Sourcepub fn register_mirror(&mut self, mirror_id: MirrorId)
pub fn register_mirror(&mut self, mirror_id: MirrorId)
Registers a remote mirror. If the mirror is already registered this is a no-op.
Sourcepub fn update_local(&mut self, item: SyncItem) -> bool
pub fn update_local(&mut self, item: SyncItem) -> bool
Inserts or updates an item in the local state.
Returns true if the CID was not previously present (new insertion).
Sourcepub fn remove_local(&mut self, cid: &str) -> bool
pub fn remove_local(&mut self, cid: &str) -> bool
Removes an item from the local state by CID.
Returns true if the item existed and was removed.
Sourcepub fn update_remote(&mut self, mirror_id: &MirrorId, item: SyncItem) -> bool
pub fn update_remote(&mut self, mirror_id: &MirrorId, item: SyncItem) -> bool
Inserts or updates an item in a remote mirror’s state.
Returns true if the CID was not previously present in that mirror.
Returns false if the mirror is not registered.
Sourcepub fn diff(&self, mirror_id: &MirrorId) -> SyncPlan
pub fn diff(&self, mirror_id: &MirrorId) -> SyncPlan
Computes the set of operations needed to synchronise the local mirror with mirror_id.
Conflict resolution follows self.default_resolution.
Sourcepub fn apply_plan(&mut self, plan: &SyncPlan, now: u64) -> MsSyncResult
pub fn apply_plan(&mut self, plan: &SyncPlan, now: u64) -> MsSyncResult
Simulates executing all operations in plan, updating local/remote states and audit log.
now is the UNIX timestamp (ms) to stamp on newly created items.
Sourcepub fn detect_conflicts(&self, mirror_id: &MirrorId) -> Vec<SyncConflict>
pub fn detect_conflicts(&self, mirror_id: &MirrorId) -> Vec<SyncConflict>
Returns all CIDs present in both local and mirror_id that have differing checksums.
Sourcepub fn local_only_cids(&self, mirror_id: &MirrorId) -> Vec<&str>
pub fn local_only_cids(&self, mirror_id: &MirrorId) -> Vec<&str>
Returns all CIDs present only in the local state (not in mirror_id), sorted.
Sourcepub fn remote_only_cids(&self, mirror_id: &MirrorId) -> Vec<&str>
pub fn remote_only_cids(&self, mirror_id: &MirrorId) -> Vec<&str>
Returns all CIDs present only in mirror_id (not in local state), sorted.
Sourcepub fn in_sync_with(&self, mirror_id: &MirrorId) -> bool
pub fn in_sync_with(&self, mirror_id: &MirrorId) -> bool
Returns true when every CID in both local and mirror_id has the same checksum.
Returns false for unregistered mirrors.
Sourcepub fn audit_log_tail(&self, n: usize) -> Vec<&SyncOperation>
pub fn audit_log_tail(&self, n: usize) -> Vec<&SyncOperation>
Returns up to the n most-recently logged operations (newest last).
Sourcepub fn stats(&self) -> MirrorSyncStats
pub fn stats(&self) -> MirrorSyncStats
Returns aggregate statistics for this instance.
Auto Trait Implementations§
impl Freeze for StorageMirrorSync
impl RefUnwindSafe for StorageMirrorSync
impl Send for StorageMirrorSync
impl Sync for StorageMirrorSync
impl Unpin for StorageMirrorSync
impl UnsafeUnpin for StorageMirrorSync
impl UnwindSafe for StorageMirrorSync
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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