pub struct LoadBalancer { /* private fields */ }Expand description
Load Balancer
Implementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn new(config: LoadBalancerConfig) -> Self
pub fn new(config: LoadBalancerConfig) -> Self
Create a new load balancer
Sourcepub fn add_node(&mut self, endpoint: NodeEndpoint)
pub fn add_node(&mut self, endpoint: NodeEndpoint)
Add a node to the load balancer
Sourcepub fn remove_node(&mut self, node_id: &NodeId)
pub fn remove_node(&mut self, node_id: &NodeId)
Remove a node from the load balancer
Sourcepub fn select_for_read(&self) -> Result<NodeEndpoint>
pub fn select_for_read(&self) -> Result<NodeEndpoint>
Select a node for a read query
Sourcepub fn select_for_write(&self) -> Result<NodeEndpoint>
pub fn select_for_write(&self) -> Result<NodeEndpoint>
Select a node for a write query
Sourcepub async fn set_node_health(&self, node_id: &NodeId, health: NodeHealth)
pub async fn set_node_health(&self, node_id: &NodeId, health: NodeHealth)
Set node health state
Supports granular health states for graceful degradation:
- Healthy: Normal operation
- Degraded: High latency/lag but still usable for reads
- Transitioning: Failover in progress
- Unhealthy: Do not route traffic
Sourcepub async fn set_node_healthy(&self, node_id: &NodeId, healthy: bool)
pub async fn set_node_healthy(&self, node_id: &NodeId, healthy: bool)
Legacy method for backward compatibility
Sourcepub async fn set_node_transitioning(&self, node_id: &NodeId)
pub async fn set_node_transitioning(&self, node_id: &NodeId)
Mark node as transitioning (failover in progress)
Sourcepub async fn update_latency(&self, node_id: &NodeId, latency_ms: f64)
pub async fn update_latency(&self, node_id: &NodeId, latency_ms: f64)
Update node latency and adjust health state accordingly
Sourcepub async fn update_replication_lag(&self, node_id: &NodeId, lag_ms: u64)
pub async fn update_replication_lag(&self, node_id: &NodeId, lag_ms: u64)
Update node replication lag and adjust health state
Sourcepub async fn update_node_metrics(
&self,
node_id: &NodeId,
latency_ms: f64,
replication_lag_ms: u64,
failure_rate: f64,
)
pub async fn update_node_metrics( &self, node_id: &NodeId, latency_ms: f64, replication_lag_ms: u64, failure_rate: f64, )
Update node health based on combined metrics
Sourcepub async fn increment_connections(&self, node_id: &NodeId)
pub async fn increment_connections(&self, node_id: &NodeId)
Increment connection count for a node
Sourcepub async fn decrement_connections(&self, node_id: &NodeId)
pub async fn decrement_connections(&self, node_id: &NodeId)
Decrement connection count for a node
Sourcepub async fn record_failure(&self, node_id: &NodeId)
pub async fn record_failure(&self, node_id: &NodeId)
Record a failure for a node
Sourcepub fn requests_routed(&self) -> u64
pub fn requests_routed(&self) -> u64
Get total requests routed
Sourcepub async fn node_stats(&self, node_id: &NodeId) -> Option<NodeStats>
pub async fn node_stats(&self, node_id: &NodeId) -> Option<NodeStats>
Get node statistics
Auto Trait Implementations§
impl !Freeze for LoadBalancer
impl !RefUnwindSafe for LoadBalancer
impl Send for LoadBalancer
impl Sync for LoadBalancer
impl Unpin for LoadBalancer
impl UnsafeUnpin for LoadBalancer
impl !UnwindSafe for LoadBalancer
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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