pub struct DistributedStateStore { /* private fields */ }Expand description
Distributed state store with consistent FNV-1a hashing for key-to-partition mapping.
Each key is routed to exactly one partition. Replication is handled by
replicate_to which returns a snapshot of a partition for a peer node.
Implementations§
Source§impl DistributedStateStore
impl DistributedStateStore
Sourcepub fn new(partition_count: u32, replication_factor: usize) -> Self
pub fn new(partition_count: u32, replication_factor: usize) -> Self
Create a new store with partition_count partitions.
Sourcepub fn partition_for(&self, key: &str) -> u32
pub fn partition_for(&self, key: &str) -> u32
Determine which partition a key belongs to (consistent hashing).
Sourcepub fn get(&self, key: &str) -> Option<&PartitionStateValue>
pub fn get(&self, key: &str) -> Option<&PartitionStateValue>
Get a value by key, or None if absent.
Sourcepub fn set(&mut self, key: &str, value: PartitionStateValue) -> u64
pub fn set(&mut self, key: &str, value: PartitionStateValue) -> u64
Set a key-value pair. Returns the new partition version number.
Sourcepub fn delete(&mut self, key: &str) -> bool
pub fn delete(&mut self, key: &str) -> bool
Delete a key. Returns true if the key previously existed.
Sourcepub fn replicate_to(
&self,
_peer: &str,
partition_id: u32,
) -> Vec<(String, PartitionStateValue)>
pub fn replicate_to( &self, _peer: &str, partition_id: u32, ) -> Vec<(String, PartitionStateValue)>
Return all key-value pairs from partition_id for replication to peer.
Sourcepub fn checkpoint_partition(&mut self, partition_id: u32) -> StatePartition
pub fn checkpoint_partition(&mut self, partition_id: u32) -> StatePartition
Snapshot a partition (clone it) and record last_checkpointed timestamp.
Sourcepub fn restore_partition(&mut self, partition: StatePartition)
pub fn restore_partition(&mut self, partition: StatePartition)
Restore a partition from a previously-created checkpoint snapshot.
Sourcepub fn partition_count(&self) -> u32
pub fn partition_count(&self) -> u32
Total number of partitions in this store.
Sourcepub fn total_keys(&self) -> usize
pub fn total_keys(&self) -> usize
Total number of keys across all partitions.
Sourcepub fn replication_factor(&self) -> usize
pub fn replication_factor(&self) -> usize
The configured replication factor.
Sourcepub fn coordinator(&self) -> &StateCoordinator
pub fn coordinator(&self) -> &StateCoordinator
Read-only reference to the coordinator.
Sourcepub fn coordinator_mut(&mut self) -> &mut StateCoordinator
pub fn coordinator_mut(&mut self) -> &mut StateCoordinator
Mutable reference to the coordinator.
Auto Trait Implementations§
impl Freeze for DistributedStateStore
impl RefUnwindSafe for DistributedStateStore
impl Send for DistributedStateStore
impl Sync for DistributedStateStore
impl Unpin for DistributedStateStore
impl UnsafeUnpin for DistributedStateStore
impl UnwindSafe for DistributedStateStore
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.