pub struct ShardRegistry { /* private fields */ }Expand description
Registry of active shards in the cluster.
The registry tracks all shards, their current status, and health metrics. It is used by the coordinator to manage the cluster topology and route requests to healthy shards.
Implementations§
Source§impl ShardRegistry
impl ShardRegistry
Sourcepub fn with_heartbeat_timeout(timeout_ms: u64) -> Self
pub fn with_heartbeat_timeout(timeout_ms: u64) -> Self
Create a registry with custom heartbeat timeout.
Sourcepub fn register(&mut self, info: ShardInfo) -> ShardId
pub fn register(&mut self, info: ShardInfo) -> ShardId
Register a new shard and return its assigned ID.
The shard will be assigned a unique ID and added to the registry. Its initial status will be set to Online.
Sourcepub fn register_with_id(&mut self, info: ShardInfo, id: ShardId) -> ShardId
pub fn register_with_id(&mut self, info: ShardInfo, id: ShardId) -> ShardId
Register a shard with a specific ID.
This is useful when restoring state or in deterministic testing. The next_id counter will be updated if necessary.
Sourcepub fn get_registered(&self, id: &ShardId) -> Option<&RegisteredShard>
pub fn get_registered(&self, id: &ShardId) -> Option<&RegisteredShard>
Get registered shard by ID (includes status).
Sourcepub fn get_registered_mut(
&mut self,
id: &ShardId,
) -> Option<&mut RegisteredShard>
pub fn get_registered_mut( &mut self, id: &ShardId, ) -> Option<&mut RegisteredShard>
Get mutable registered shard by ID.
Sourcepub fn heartbeat_with_timestamp(&mut self, id: &ShardId, timestamp: u64)
pub fn heartbeat_with_timestamp(&mut self, id: &ShardId, timestamp: u64)
Update heartbeat with explicit timestamp (for testing or remote sync).
Sourcepub fn set_status(&mut self, id: &ShardId, status: ShardStatus)
pub fn set_status(&mut self, id: &ShardId, status: ShardStatus)
Update shard status.
Sourcepub fn get_status(&self, id: &ShardId) -> Option<ShardStatus>
pub fn get_status(&self, id: &ShardId) -> Option<ShardStatus>
Get the status of a shard.
Sourcepub fn update_metrics(
&mut self,
id: &ShardId,
document_count: usize,
memory_bytes: u64,
)
pub fn update_metrics( &mut self, id: &ShardId, document_count: usize, memory_bytes: u64, )
Update shard metrics.
Sourcepub fn online_shards(&self) -> Vec<ShardInfo>
pub fn online_shards(&self) -> Vec<ShardInfo>
Get all online shards.
Sourcepub fn shards_with_status(&self, status: ShardStatus) -> Vec<ShardInfo>
pub fn shards_with_status(&self, status: ShardStatus) -> Vec<ShardInfo>
Get all shards with a specific status.
Sourcepub fn check_dead_shards(&mut self) -> Vec<ShardId>
pub fn check_dead_shards(&mut self) -> Vec<ShardId>
Check for and mark dead shards based on heartbeat timeout.
Returns the IDs of shards that were marked as offline.
Sourcepub fn total_documents(&self) -> u64
pub fn total_documents(&self) -> u64
Get total document count across all shards.
Sourcepub fn total_memory(&self) -> u64
pub fn total_memory(&self) -> u64
Get total memory usage across all shards.
Sourcepub fn least_loaded_shard(&self) -> Option<ShardId>
pub fn least_loaded_shard(&self) -> Option<ShardId>
Get the shard with the least documents (for load balancing).