pub struct ReplicationManager { /* private fields */ }Expand description
Coordinates data replication across the DHT.
The manager does not perform any networking itself — it produces
ReplicationTasks that a higher-level transport layer executes.
Implementations§
Source§impl ReplicationManager
impl ReplicationManager
Sourcepub fn new(config: ReplicationConfig) -> Self
pub fn new(config: ReplicationConfig) -> Self
Create a new replication manager with the given configuration.
Sourcepub fn with_factor(factor: usize) -> Self
pub fn with_factor(factor: usize) -> Self
Create with default config but a custom replication factor.
Sourcepub fn schedule_replication(
&mut self,
key: [u8; 32],
value: Bytes,
closest_peers: &[PeerInfo],
) -> Vec<ReplicationTask>
pub fn schedule_replication( &mut self, key: [u8; 32], value: Bytes, closest_peers: &[PeerInfo], ) -> Vec<ReplicationTask>
Schedule replication for a newly stored (or updated) value.
Returns the tasks that should be executed by the transport layer.
Sourcepub fn confirm_replication(&mut self, key: [u8; 32], peer: PeerId)
pub fn confirm_replication(&mut self, key: [u8; 32], peer: PeerId)
Confirm that a replica was successfully stored on a peer.
Sourcepub fn take_pending_tasks(&mut self) -> Vec<ReplicationTask>
pub fn take_pending_tasks(&mut self) -> Vec<ReplicationTask>
Drain and return all pending tasks.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Peek at the number of pending tasks.
Sourcepub fn check_refresh(&mut self, dht: &DHTNode) -> Vec<ReplicationTask>
pub fn check_refresh(&mut self, dht: &DHTNode) -> Vec<ReplicationTask>
Scan for keys that need a refresh (their replicas haven’t been
refreshed within refresh_interval).
The caller must supply the local DHT node so we can read stored values and closest peers.
Sourcepub fn handle_peer_lost(
&mut self,
lost_peer: &PeerId,
dht: &DHTNode,
) -> Vec<ReplicationTask>
pub fn handle_peer_lost( &mut self, lost_peer: &PeerId, dht: &DHTNode, ) -> Vec<ReplicationTask>
Handle the loss of a peer — re-replicate any data it held.
Sourcepub fn cleanup_expired(&mut self) -> usize
pub fn cleanup_expired(&mut self) -> usize
Remove tracking for expired keys.
Sourcepub fn replica_count(&self, key: &[u8; 32]) -> usize
pub fn replica_count(&self, key: &[u8; 32]) -> usize
How many confirmed replicas exist for a key.
Sourcepub fn is_fully_replicated(&self, key: &[u8; 32]) -> bool
pub fn is_fully_replicated(&self, key: &[u8; 32]) -> bool
Whether a key is fully replicated.
Sourcepub fn under_replicated_keys(&self) -> Vec<[u8; 32]>
pub fn under_replicated_keys(&self) -> Vec<[u8; 32]>
Get all keys that are under-replicated.
Sourcepub fn holders(&self, key: &[u8; 32]) -> HashSet<PeerId>
pub fn holders(&self, key: &[u8; 32]) -> HashSet<PeerId>
Get the set of peers holding replicas of a key.
Sourcepub fn stats(&self) -> ReplicationStats
pub fn stats(&self) -> ReplicationStats
Aggregate statistics.
Sourcepub fn config(&self) -> &ReplicationConfig
pub fn config(&self) -> &ReplicationConfig
Get the replication configuration