pub struct ReplicaManager { /* private fields */ }Expand description
Central manager for shard-level replica tracking and failover coordination.
Implementations§
Source§impl ReplicaManager
impl ReplicaManager
Sourcepub fn new(replication_factor: usize) -> Self
pub fn new(replication_factor: usize) -> Self
Create a new manager with the given target replication_factor.
replication_factor must be at least 1 (1 = primary only, no replicas).
Sourcepub fn register_replica(
&mut self,
replica: ShardReplica,
) -> Result<(), VectorError>
pub fn register_replica( &mut self, replica: ShardReplica, ) -> Result<(), VectorError>
Register a new replica.
§Errors
Returns VectorError::InvalidData when:
- A replica with the same
(shard_id, replica_id)already exists. replica.stateisPrimarybut a primary is already registered for that shard.
Sourcepub fn unregister_replica(&mut self, shard_id: u64, replica_id: &str) -> bool
pub fn unregister_replica(&mut self, shard_id: u64, replica_id: &str) -> bool
Unregister a replica by (shard_id, replica_id).
Returns true if the replica was found and removed.
Sourcepub fn promote_to_primary(
&mut self,
shard_id: u64,
replica_id: &str,
) -> Result<(), VectorError>
pub fn promote_to_primary( &mut self, shard_id: u64, replica_id: &str, ) -> Result<(), VectorError>
Promote replica_id to Primary for shard_id.
Any existing primary is demoted to Replica first.
§Errors
Returns VectorError::InvalidData when the target replica is not found or
is in the Failed state.
Sourcepub fn mark_failed(&mut self, shard_id: u64, replica_id: &str)
pub fn mark_failed(&mut self, shard_id: u64, replica_id: &str)
Mark a replica as Failed.
If the failed replica was the primary, no automatic failover occurs here —
call promote_to_primary on a healthy replica to elect a new one.
A no-op when the (shard_id, replica_id) pair does not exist.
Sourcepub fn auto_failover(&mut self, shard_id: u64) -> Result<String, VectorError>
pub fn auto_failover(&mut self, shard_id: u64) -> Result<String, VectorError>
Attempt automatic failover for shard_id when the current primary fails.
Selects the healthy replica with the largest vector_count (most up-to-date)
and promotes it. Returns the promoted replica’s ID on success.
§Errors
Returns VectorError::InvalidData when no healthy replica exists for the shard.
Sourcepub fn update_sync_progress(
&mut self,
shard_id: u64,
replica_id: &str,
progress: f64,
)
pub fn update_sync_progress( &mut self, shard_id: u64, replica_id: &str, progress: f64, )
Update the progress of a CatchingUp replica.
When progress reaches 1.0, the replica is automatically promoted to Replica.
Sourcepub fn get_primary(&self, shard_id: u64) -> Option<&ShardReplica>
pub fn get_primary(&self, shard_id: u64) -> Option<&ShardReplica>
Return the primary replica for shard_id, if any.
Sourcepub fn get_replicas(&self, shard_id: u64) -> Vec<&ShardReplica>
pub fn get_replicas(&self, shard_id: u64) -> Vec<&ShardReplica>
Return all replicas for shard_id (including primary).
Sourcepub fn get_healthy_replicas(&self, shard_id: u64) -> Vec<&ShardReplica>
pub fn get_healthy_replicas(&self, shard_id: u64) -> Vec<&ShardReplica>
Return all healthy (non-failed) replicas for shard_id.
Sourcepub fn replication_factor(&self) -> usize
pub fn replication_factor(&self) -> usize
The configured replication factor.
Sourcepub fn needs_rebalancing(&self) -> bool
pub fn needs_rebalancing(&self) -> bool
Returns true when any shard is under- or over-replicated relative to
the configured replication_factor.
Sourcepub fn replication_status(&self) -> ReplicationStatus
pub fn replication_status(&self) -> ReplicationStatus
Produce a ReplicationStatus summary of the cluster’s health.
Auto Trait Implementations§
impl Freeze for ReplicaManager
impl RefUnwindSafe for ReplicaManager
impl Send for ReplicaManager
impl Sync for ReplicaManager
impl Unpin for ReplicaManager
impl UnsafeUnpin for ReplicaManager
impl UnwindSafe for ReplicaManager
Blanket Implementations§
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
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.