pub struct StorageReplicationManager {
pub policy: RmReplicationPolicy,
pub nodes: HashMap<String, ReplicaNode>,
pub replicas: HashMap<String, Vec<RmReplicaLocation>>,
}Expand description
Manages block replication across a set of storage nodes.
Tracks the health and capacity of each node, records where each CID is stored, and exposes methods to query replication status, select candidate nodes for new replicas, and evict stale nodes.
Fields§
§policy: RmReplicationPolicyPolicy controlling replication factors and node selection.
nodes: HashMap<String, ReplicaNode>Registered nodes, keyed by node_id.
replicas: HashMap<String, Vec<RmReplicaLocation>>Replica locations, keyed by CID. Each entry is a list of locations.
Implementations§
Source§impl StorageReplicationManager
impl StorageReplicationManager
Sourcepub fn new(policy: RmReplicationPolicy) -> Self
pub fn new(policy: RmReplicationPolicy) -> Self
Create a new manager with the supplied policy.
Sourcepub fn register_node(
&mut self,
node: ReplicaNode,
) -> Result<(), ReplicationError>
pub fn register_node( &mut self, node: ReplicaNode, ) -> Result<(), ReplicationError>
Register a new storage node.
Returns ReplicationError::NodeAlreadyRegistered if a node with the
same node_id is already present.
Sourcepub fn deregister_node(&mut self, node_id: &str) -> Result<(), ReplicationError>
pub fn deregister_node(&mut self, node_id: &str) -> Result<(), ReplicationError>
Remove a node and all replica records that reference it.
Returns ReplicationError::NodeNotFound if the node is not present.
Sourcepub fn mark_healthy(&mut self, node_id: &str, now: u64) -> bool
pub fn mark_healthy(&mut self, node_id: &str, now: u64) -> bool
Mark a node as healthy and update its last_seen timestamp.
Returns true if the node was found.
Sourcepub fn mark_unhealthy(&mut self, node_id: &str) -> bool
pub fn mark_unhealthy(&mut self, node_id: &str) -> bool
Mark a node as unhealthy.
Returns true if the node was found.
Sourcepub fn record_replica(
&mut self,
cid: String,
node_id: &str,
checksum: u64,
now: u64,
) -> Result<(), ReplicationError>
pub fn record_replica( &mut self, cid: String, node_id: &str, checksum: u64, now: u64, ) -> Result<(), ReplicationError>
Record that a CID has been stored on a node.
Returns ReplicationError::NodeNotFound if node_id is not registered.
Sourcepub fn verify_replica(&mut self, cid: &str, node_id: &str, now: u64) -> bool
pub fn verify_replica(&mut self, cid: &str, node_id: &str, now: u64) -> bool
Update the verified_at timestamp for a specific CID + node pair.
Returns true if the replica record was found and updated.
Sourcepub fn remove_replica(&mut self, cid: &str, node_id: &str) -> bool
pub fn remove_replica(&mut self, cid: &str, node_id: &str) -> bool
Remove a specific replica location.
Returns true if the location was found and removed.
Sourcepub fn replication_status(&self, cid: &str) -> RmReplicationStatus
pub fn replication_status(&self, cid: &str) -> RmReplicationStatus
Return the replication status for a CID.
A “healthy replica” is one where both the replica record exists and the backing node is registered and marked healthy.
Sourcepub fn under_replicated_cids(&self) -> Vec<&str>
pub fn under_replicated_cids(&self) -> Vec<&str>
Return all CIDs that are UnderReplicated or Missing, sorted.
Sourcepub fn over_replicated_cids(&self) -> Vec<&str>
pub fn over_replicated_cids(&self) -> Vec<&str>
Return all CIDs that are OverReplicated, sorted.
Sourcepub fn select_nodes_for_replication(
&self,
cid: &str,
count: usize,
) -> Vec<&ReplicaNode>
pub fn select_nodes_for_replication( &self, cid: &str, count: usize, ) -> Vec<&ReplicaNode>
Select up to count healthy nodes suitable for storing a new replica of cid.
Eligibility criteria (in order of filtering):
- Node must be healthy.
- Node must not already hold a replica of the given CID.
- Node’s utilization must be ≤
max_node_utilization.
Among eligible nodes, those with the most available_bytes are preferred.
Sourcepub fn evict_stale_nodes(&mut self, max_age_ms: u64, now: u64) -> usize
pub fn evict_stale_nodes(&mut self, max_age_ms: u64, now: u64) -> usize
Remove nodes whose last_seen is more than max_age_ms milliseconds
before now, and clean up associated replica records.
Returns the number of nodes evicted.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the total number of registered nodes.
Sourcepub fn healthy_node_count(&self) -> usize
pub fn healthy_node_count(&self) -> usize
Returns the number of nodes currently marked as healthy.
Sourcepub fn stats(&self) -> RmReplicationStats
pub fn stats(&self) -> RmReplicationStats
Compute aggregate statistics for the current state.
Auto Trait Implementations§
impl Freeze for StorageReplicationManager
impl RefUnwindSafe for StorageReplicationManager
impl Send for StorageReplicationManager
impl Sync for StorageReplicationManager
impl Unpin for StorageReplicationManager
impl UnsafeUnpin for StorageReplicationManager
impl UnwindSafe for StorageReplicationManager
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