Skip to main content

ShardRegistry

Struct ShardRegistry 

Source
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

Source

pub fn new() -> Self

Create a new empty shard registry.

Source

pub fn with_heartbeat_timeout(timeout_ms: u64) -> Self

Create a registry with custom heartbeat timeout.

Source

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.

Source

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.

Source

pub fn get(&self, id: &ShardId) -> Option<&ShardInfo>

Get shard info by ID.

Source

pub fn get_registered(&self, id: &ShardId) -> Option<&RegisteredShard>

Get registered shard by ID (includes status).

Source

pub fn get_registered_mut( &mut self, id: &ShardId, ) -> Option<&mut RegisteredShard>

Get mutable registered shard by ID.

Source

pub fn remove(&mut self, id: &ShardId) -> Option<ShardInfo>

Remove a shard from the registry.

Source

pub fn all(&self) -> Vec<ShardInfo>

Get all shard infos.

Source

pub fn all_ids(&self) -> Vec<ShardId>

Get all shard IDs.

Source

pub fn count(&self) -> usize

Get the number of registered shards.

Source

pub fn contains(&self, id: &ShardId) -> bool

Check if a shard exists.

Source

pub fn heartbeat(&mut self, id: &ShardId)

Update heartbeat timestamp for a shard.

Source

pub fn heartbeat_with_timestamp(&mut self, id: &ShardId, timestamp: u64)

Update heartbeat with explicit timestamp (for testing or remote sync).

Source

pub fn set_status(&mut self, id: &ShardId, status: ShardStatus)

Update shard status.

Source

pub fn get_status(&self, id: &ShardId) -> Option<ShardStatus>

Get the status of a shard.

Source

pub fn update_metrics( &mut self, id: &ShardId, document_count: usize, memory_bytes: u64, )

Update shard metrics.

Source

pub fn online_shards(&self) -> Vec<ShardInfo>

Get all online shards.

Source

pub fn shards_with_status(&self, status: ShardStatus) -> Vec<ShardInfo>

Get all shards with a specific status.

Source

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.

Source

pub fn total_documents(&self) -> u64

Get total document count across all shards.

Source

pub fn total_memory(&self) -> u64

Get total memory usage across all shards.

Source

pub fn least_loaded_shard(&self) -> Option<ShardId>

Get the shard with the least documents (for load balancing).

Trait Implementations§

Source§

impl Default for ShardRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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, 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