pub struct StorageReplicationTracker {
pub entries: HashMap<u64, BlockReplicationEntry>,
pub next_block_id: u64,
pub default_desired_replicas: usize,
}Expand description
Tracks replication of content blocks across a peer network.
Fields§
§entries: HashMap<u64, BlockReplicationEntry>All tracked block entries keyed by block_id.
next_block_id: u64Counter used to issue monotonically increasing block IDs.
default_desired_replicas: usizeReplication factor applied when register_block receives None.
Implementations§
Source§impl StorageReplicationTracker
impl StorageReplicationTracker
Sourcepub fn new(default_desired_replicas: usize) -> Self
pub fn new(default_desired_replicas: usize) -> Self
Creates a new tracker with the given default replication factor.
Sourcepub fn register_block(
&mut self,
cid: String,
desired_replicas: Option<usize>,
) -> u64
pub fn register_block( &mut self, cid: String, desired_replicas: Option<usize>, ) -> u64
Registers a new block and returns its assigned block_id.
If desired_replicas is None, the tracker’s default is used.
Sourcepub fn add_replica(
&mut self,
block_id: u64,
peer_id: String,
current_tick: u64,
is_primary: bool,
) -> bool
pub fn add_replica( &mut self, block_id: u64, peer_id: String, current_tick: u64, is_primary: bool, ) -> bool
Records that peer_id holds a replica of block_id at current_tick.
- Returns
falseifblock_idis not tracked. - If the peer already has a replica, its tick is updated; otherwise a
new
ReplicaLocationis appended. - Returns
trueon success.
Sourcepub fn remove_replica(&mut self, block_id: u64, peer_id: &str) -> bool
pub fn remove_replica(&mut self, block_id: u64, peer_id: &str) -> bool
Removes the replica held by peer_id from block_id.
Returns false when the block or peer is not found.
Sourcepub fn under_replicated_blocks(&self) -> Vec<&BlockReplicationEntry>
pub fn under_replicated_blocks(&self) -> Vec<&BlockReplicationEntry>
Returns all blocks that are ReplicationStatus::UnderReplicated or
ReplicationStatus::Critical, sorted by block_id ascending.
Sourcepub fn generate_tasks(&self) -> Vec<ReplicationTask>
pub fn generate_tasks(&self) -> Vec<ReplicationTask>
Generates replication tasks for every block with a positive deficit.
Tasks are ordered by priority descending then block_id ascending.
Sourcepub fn get_entry(&self, block_id: u64) -> Option<&BlockReplicationEntry>
pub fn get_entry(&self, block_id: u64) -> Option<&BlockReplicationEntry>
Returns a reference to the entry for block_id, if tracked.
Sourcepub fn stats(&self) -> ReplicationStats
pub fn stats(&self) -> ReplicationStats
Computes aggregate statistics across all tracked blocks.
Auto Trait Implementations§
impl Freeze for StorageReplicationTracker
impl RefUnwindSafe for StorageReplicationTracker
impl Send for StorageReplicationTracker
impl Sync for StorageReplicationTracker
impl Unpin for StorageReplicationTracker
impl UnsafeUnpin for StorageReplicationTracker
impl UnwindSafe for StorageReplicationTracker
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