Skip to main content

StorageReplicationManager

Struct StorageReplicationManager 

Source
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: RmReplicationPolicy

Policy 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

Source

pub fn new(policy: RmReplicationPolicy) -> Self

Create a new manager with the supplied policy.

Source

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.

Source

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.

Source

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.

Source

pub fn mark_unhealthy(&mut self, node_id: &str) -> bool

Mark a node as unhealthy.

Returns true if the node was found.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn under_replicated_cids(&self) -> Vec<&str>

Return all CIDs that are UnderReplicated or Missing, sorted.

Source

pub fn over_replicated_cids(&self) -> Vec<&str>

Return all CIDs that are OverReplicated, sorted.

Source

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):

  1. Node must be healthy.
  2. Node must not already hold a replica of the given CID.
  3. Node’s utilization must be ≤ max_node_utilization.

Among eligible nodes, those with the most available_bytes are preferred.

Source

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.

Source

pub fn cid_count(&self) -> usize

Returns the total number of distinct CIDs being tracked.

Source

pub fn node_count(&self) -> usize

Returns the total number of registered nodes.

Source

pub fn healthy_node_count(&self) -> usize

Returns the number of nodes currently marked as healthy.

Source

pub fn stats(&self) -> RmReplicationStats

Compute aggregate statistics for the current state.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more