Skip to main content

CacheCoordinator

Struct CacheCoordinator 

Source
pub struct CacheCoordinator {
    pub clients: HashMap<NodeId, DistributedCacheClient>,
    pub replication: ReplicationFactor,
}
Expand description

Cluster-level coordinator.

Tracks all node clients and the replication policy for the cluster. In a real distributed system the coordinator would issue RPCs; here it simulates the routing and quorum decisions.

Fields§

§clients: HashMap<NodeId, DistributedCacheClient>

Map from NodeId to per-node client.

§replication: ReplicationFactor

Cluster-wide replication factor.

Implementations§

Source§

impl CacheCoordinator

Source

pub fn new(replication: ReplicationFactor) -> Self

Create a new CacheCoordinator with the given replication factor.

Source

pub fn add_client(&mut self, client: DistributedCacheClient)

Register a DistributedCacheClient for its local_node.

Source

pub fn remove_client(&mut self, node_id: NodeId)

Remove the client (and node) identified by node_id.

Source

pub fn primary_node_for(&self, key: &[u8]) -> Option<NodeId>

Determine the primary owner of key according to the first registered client’s ring.

Returns None when no clients are registered.

Source

pub fn replica_nodes_for(&self, key: &[u8], n: usize) -> Vec<NodeId>

Return up to n replica nodes for key according to the first registered client’s ring.

Source

pub fn can_write_quorum(&self, key: &[u8], available_nodes: &[NodeId]) -> bool

Simulate a write operation: determine the owner nodes for key and check whether a quorum can be formed from available_nodes.

Source

pub fn can_read_quorum(&self, key: &[u8], available_nodes: &[NodeId]) -> bool

Simulate a read operation: determine the owner nodes for key and check whether a quorum can be formed from available_nodes.

Source

pub fn node_count(&self) -> usize

Return the number of registered clients/nodes.

Trait Implementations§

Source§

impl Debug for CacheCoordinator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.