pub struct FormatCrdtProcessor<P: FormatBatchProcessor> { /* private fields */ }Expand description
CRDT-enabled processor for any format implementing FormatBatchProcessor
This wraps a FormatDsonProcessor and adds CRDT semantics:
- Vector clock tracking for causality
- Last-Writer-Wins (LWW) register semantics per field
- Delta-state synchronization
- Operation buffering for causal ordering
Implementations§
Source§impl<P: FormatBatchProcessor> FormatCrdtProcessor<P>
impl<P: FormatBatchProcessor> FormatCrdtProcessor<P>
Sourcepub fn new(batch_processor: P, replica_id: impl Into<String>) -> Self
pub fn new(batch_processor: P, replica_id: impl Into<String>) -> Self
Create a new CRDT processor with a replica ID
Sourcepub fn with_strategy(self, strategy: MergeStrategy) -> Self
pub fn with_strategy(self, strategy: MergeStrategy) -> Self
Create with a specific merge strategy
Sourcepub fn format_kind(&self) -> FormatKind
pub fn format_kind(&self) -> FormatKind
Get the format kind
Sourcepub fn replica_id(&self) -> &str
pub fn replica_id(&self) -> &str
Get the replica ID
Sourcepub const fn vector_clock(&self) -> &VectorClock
pub const fn vector_clock(&self) -> &VectorClock
Get the current vector clock
Sourcepub const fn lamport_timestamp(&self) -> u64
pub const fn lamport_timestamp(&self) -> u64
Get the current Lamport timestamp
Sourcepub fn process(
&mut self,
data: &[u8],
schema: &CompiledSchema,
) -> Result<FormatBatchResult>
pub fn process( &mut self, data: &[u8], schema: &CompiledSchema, ) -> Result<FormatBatchResult>
Process data with schema filtering and track as CRDT state
§Errors
Returns an error if processing fails
Sourcepub fn process_with_operations(
&mut self,
data: &[u8],
schema: &CompiledSchema,
operations: &[DsonOperation],
) -> Result<FormatBatchResult>
pub fn process_with_operations( &mut self, data: &[u8], schema: &CompiledSchema, operations: &[DsonOperation], ) -> Result<FormatBatchResult>
Sourcepub fn process_unfiltered(&mut self, data: &[u8]) -> Result<FormatBatchResult>
pub fn process_unfiltered(&mut self, data: &[u8]) -> Result<FormatBatchResult>
Sourcepub fn get_document(&self, doc_id: &str) -> Option<&str>
pub fn get_document(&self, doc_id: &str) -> Option<&str>
Get a document by ID
Sourcepub fn document_ids(&self) -> Vec<&str>
pub fn document_ids(&self) -> Vec<&str>
Get all document IDs
Sourcepub fn document_count(&self) -> usize
pub fn document_count(&self) -> usize
Get number of tracked documents
Sourcepub const fn dson_processor(&self) -> &FormatDsonProcessor<P>
pub const fn dson_processor(&self) -> &FormatDsonProcessor<P>
Get reference to underlying DSON processor
Sourcepub fn dson_processor_mut(&mut self) -> &mut FormatDsonProcessor<P>
pub fn dson_processor_mut(&mut self) -> &mut FormatDsonProcessor<P>
Get mutable reference to underlying DSON processor
Trait Implementations§
Source§impl<P: FormatBatchProcessor> CrdtMerge for FormatCrdtProcessor<P>
impl<P: FormatBatchProcessor> CrdtMerge for FormatCrdtProcessor<P>
Source§fn merge_operation(
&mut self,
op: CrdtOperation,
) -> Result<Option<MergeConflict>>
fn merge_operation( &mut self, op: CrdtOperation, ) -> Result<Option<MergeConflict>>
Merge a remote operation into local state Read more
Source§fn merge_field(
&mut self,
path: &str,
value: OperationValue,
timestamp: u64,
strategy: &MergeStrategy,
) -> Result<Option<MergeConflict>>
fn merge_field( &mut self, path: &str, value: OperationValue, timestamp: u64, strategy: &MergeStrategy, ) -> Result<Option<MergeConflict>>
Merge field with CRDT semantics Read more
Source§fn vector_clock(&self) -> &VectorClock
fn vector_clock(&self) -> &VectorClock
Get the current vector clock
Source§fn replica_id(&self) -> &str
fn replica_id(&self) -> &str
Get the replica ID
Source§fn resolve_conflict(
&mut self,
conflict: &MergeConflict,
strategy: &MergeStrategy,
) -> Result<OperationValue>
fn resolve_conflict( &mut self, conflict: &MergeConflict, strategy: &MergeStrategy, ) -> Result<OperationValue>
Resolve a conflict using the specified strategy Read more
Source§impl<P: FormatBatchProcessor> DeltaCrdt for FormatCrdtProcessor<P>
impl<P: FormatBatchProcessor> DeltaCrdt for FormatCrdtProcessor<P>
Source§type Delta = FormatDelta
type Delta = FormatDelta
Type representing a delta (difference from previous state)
Source§fn generate_delta(&self, since: &VectorClock) -> Self::Delta
fn generate_delta(&self, since: &VectorClock) -> Self::Delta
Generate delta since given vector clock
Source§fn apply_delta(&mut self, delta: Self::Delta) -> Result<Vec<MergeConflict>>
fn apply_delta(&mut self, delta: Self::Delta) -> Result<Vec<MergeConflict>>
Apply delta from remote replica Read more
Source§impl<P: FormatBatchProcessor> OpBasedCrdt for FormatCrdtProcessor<P>
impl<P: FormatBatchProcessor> OpBasedCrdt for FormatCrdtProcessor<P>
Source§fn prepare(&self, op: &DsonOperation) -> Result<CrdtOperation>
fn prepare(&self, op: &DsonOperation) -> Result<CrdtOperation>
Prepare an operation for broadcast (downstream precondition) Read more
Source§fn effect(&mut self, op: CrdtOperation) -> Result<Option<MergeConflict>>
fn effect(&mut self, op: CrdtOperation) -> Result<Option<MergeConflict>>
Effect an operation (apply after delivery) Read more
Source§fn is_causally_ready(&self, op: &CrdtOperation) -> bool
fn is_causally_ready(&self, op: &CrdtOperation) -> bool
Check if operation is causally ready to be applied
Source§fn buffer_operation(&mut self, op: CrdtOperation)
fn buffer_operation(&mut self, op: CrdtOperation)
Buffer operation until causally ready
Source§fn process_buffered(&mut self) -> Result<Vec<MergeConflict>>
fn process_buffered(&mut self) -> Result<Vec<MergeConflict>>
Process buffered operations that are now ready Read more
Auto Trait Implementations§
impl<P> Freeze for FormatCrdtProcessor<P>where
P: Freeze,
impl<P> RefUnwindSafe for FormatCrdtProcessor<P>where
P: RefUnwindSafe,
impl<P> Send for FormatCrdtProcessor<P>where
P: Send,
impl<P> Sync for FormatCrdtProcessor<P>where
P: Sync,
impl<P> Unpin for FormatCrdtProcessor<P>where
P: Unpin,
impl<P> UnwindSafe for FormatCrdtProcessor<P>where
P: UnwindSafe,
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
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>
Converts
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>
Converts
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