pub struct PathOpLog { /* private fields */ }Expand description
The path operation log - an operation-based CRDT
This is a grow-only set of operations with causal ordering. Conflict resolution is deterministic based on:
- Lamport timestamp (higher wins for concurrent ops on same path)
- Peer ID (lexicographic tie-breaker)
Implementations§
Source§impl PathOpLog
impl PathOpLog
Sourcepub fn from_operation(op: &PathOperation) -> Self
pub fn from_operation(op: &PathOperation) -> Self
Create a log containing a single operation
Sourcepub fn rebuild_clock(&mut self)
pub fn rebuild_clock(&mut self)
Rebuild local clock from operations (call after deserialization)
Sourcepub fn record(
&mut self,
peer_id: PublicKey,
op_type: OpType,
path: impl Into<PathBuf>,
content_link: Option<Link>,
is_dir: bool,
) -> OpId
pub fn record( &mut self, peer_id: PublicKey, op_type: OpType, path: impl Into<PathBuf>, content_link: Option<Link>, is_dir: bool, ) -> OpId
Record a new local operation
The peer_id identifies who is recording this operation. Returns the OpId of the recorded operation.
Sourcepub fn merge(&mut self, other: &PathOpLog) -> usize
pub fn merge(&mut self, other: &PathOpLog) -> usize
Merge operations from another log (CRDT merge)
Returns the number of new operations added
Sourcepub fn merge_with_resolver(
&mut self,
other: &PathOpLog,
resolver: &dyn ConflictResolver,
local_peer: &PublicKey,
) -> MergeResult
pub fn merge_with_resolver( &mut self, other: &PathOpLog, resolver: &dyn ConflictResolver, local_peer: &PublicKey, ) -> MergeResult
Merge operations from another log with conflict resolution
Unlike the basic merge(), this method:
- Detects conflicts between local and incoming operations
- Uses the provided resolver to decide how to handle each conflict
- Returns detailed information about what conflicts were found and resolved
§Arguments
other- The incoming log to mergeresolver- The conflict resolution strategy to uselocal_peer- The local peer’s identity (for tie-breaking)
§Returns
A MergeResult containing:
- Number of operations added
- List of resolved conflicts
- List of unresolved conflicts (when using ForkOnConflict)
Sourcepub fn operations(&self) -> &BTreeMap<OpId, PathOperation>
pub fn operations(&self) -> &BTreeMap<OpId, PathOperation>
Get all operations
Sourcepub fn resolve_path(&self, path: impl AsRef<Path>) -> Option<&PathOperation>
pub fn resolve_path(&self, path: impl AsRef<Path>) -> Option<&PathOperation>
Resolve the current state of a path
Returns the winning operation for the path (if any). The operation with the highest OpId wins.
Sourcepub fn resolve_all(&self) -> BTreeMap<PathBuf, &PathOperation>
pub fn resolve_all(&self) -> BTreeMap<PathBuf, &PathOperation>
Resolve the entire filesystem state from operations
Returns a map of path -> winning operation for all paths that currently exist (excludes paths where Remove was the winning op)
Sourcepub fn clear_preserving_clock(&mut self)
pub fn clear_preserving_clock(&mut self)
Clear operations but preserve the local clock value.
This is used after persisting operations to a manifest. We clear the operations (since they’re now saved) but keep the clock so future operations have unique timestamps across save cycles.
Sourcepub fn ops_for_path(&self, path: impl AsRef<Path>) -> Vec<&PathOperation>
pub fn ops_for_path(&self, path: impl AsRef<Path>) -> Vec<&PathOperation>
Get operations affecting a specific path, in order
Sourcepub fn ops_in_order(&self) -> impl Iterator<Item = &PathOperation>
pub fn ops_in_order(&self) -> impl Iterator<Item = &PathOperation>
Get all operations in order (oldest to newest)
Trait Implementations§
Source§impl BlockEncoded<DagCborCodec> for PathOpLog
impl BlockEncoded<DagCborCodec> for PathOpLog
Source§impl<'de> Deserialize<'de> for PathOpLog
impl<'de> Deserialize<'de> for PathOpLog
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for PathOpLog
Auto Trait Implementations§
impl Freeze for PathOpLog
impl RefUnwindSafe for PathOpLog
impl Send for PathOpLog
impl Sync for PathOpLog
impl Unpin for PathOpLog
impl UnwindSafe for PathOpLog
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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