pub struct ClusterCoordinator { /* private fields */ }Expand description
Cluster coordinator managing membership and health
Implementations§
Source§impl ClusterCoordinator
impl ClusterCoordinator
Sourcepub fn new(config: ClusterConfig, local_node_id: String) -> Self
pub fn new(config: ClusterConfig, local_node_id: String) -> Self
Create a new cluster coordinator
Sourcepub fn with_gossip(
config: ClusterConfig,
local_node_id: String,
local_address: SocketAddr,
api_address: String,
role: NodeRole,
gossip_config: GossipConfig,
) -> Self
pub fn with_gossip( config: ClusterConfig, local_node_id: String, local_address: SocketAddr, api_address: String, role: NodeRole, gossip_config: GossipConfig, ) -> Self
Create a cluster coordinator with gossip protocol enabled
§Arguments
config- Cluster configurationlocal_node_id- Unique identifier for this nodelocal_address- Socket address for gossip communication (e.g., “0.0.0.0:7946”)api_address- API address for client communication (e.g., “http://localhost:8080”)role- Role of this node in the clustergossip_config- Gossip protocol configuration
Sourcepub async fn start_gossip(&self) -> Result<(), String>
pub async fn start_gossip(&self) -> Result<(), String>
Start the gossip protocol
Sourcepub fn stop_gossip(&self)
pub fn stop_gossip(&self)
Stop the gossip protocol
Sourcepub async fn leave_cluster(&self) -> Result<(), String>
pub async fn leave_cluster(&self) -> Result<(), String>
Leave the cluster gracefully
Sourcepub async fn process_gossip_events(&mut self) -> Result<usize, String>
pub async fn process_gossip_events(&mut self) -> Result<usize, String>
Process pending gossip events and update cluster state
Sourcepub fn gossip(&self) -> Option<&Arc<GossipProtocol>>
pub fn gossip(&self) -> Option<&Arc<GossipProtocol>>
Get the gossip protocol instance
Sourcepub async fn get_gossip_members(&self) -> Vec<GossipMember>
pub async fn get_gossip_members(&self) -> Vec<GossipMember>
Get all members from the gossip protocol
Sourcepub async fn broadcast_metadata(
&self,
key: String,
value: String,
) -> Result<(), String>
pub async fn broadcast_metadata( &self, key: String, value: String, ) -> Result<(), String>
Broadcast metadata update via gossip
Sourcepub fn register_node(&self, node: NodeInfo) -> Result<(), String>
pub fn register_node(&self, node: NodeInfo) -> Result<(), String>
Register a node with the cluster
Sourcepub fn deregister_node(&self, node_id: &str) -> Result<Option<NodeInfo>, String>
pub fn deregister_node(&self, node_id: &str) -> Result<Option<NodeInfo>, String>
Deregister a node from the cluster
Sourcepub fn update_node_health(
&self,
node_id: &str,
health: NodeHealth,
) -> Result<(), String>
pub fn update_node_health( &self, node_id: &str, health: NodeHealth, ) -> Result<(), String>
Update node health status
Sourcepub fn record_health_success(&self, node_id: &str) -> Result<(), String>
pub fn record_health_success(&self, node_id: &str) -> Result<(), String>
Record a successful health check
Sourcepub fn record_health_failure(&self, node_id: &str) -> Result<(), String>
pub fn record_health_failure(&self, node_id: &str) -> Result<(), String>
Record a failed health check
Sourcepub fn get_state(&self) -> ClusterState
pub fn get_state(&self) -> ClusterState
Get current cluster state
Sourcepub fn get_healthy_nodes_for_shard(&self, shard_id: u32) -> Vec<NodeInfo>
pub fn get_healthy_nodes_for_shard(&self, shard_id: u32) -> Vec<NodeInfo>
Get healthy nodes for a shard
Sourcepub fn get_primary_for_shard(&self, shard_id: u32) -> Option<NodeInfo>
pub fn get_primary_for_shard(&self, shard_id: u32) -> Option<NodeInfo>
Get primary node for a shard
Sourcepub fn get_healthy_nodes(&self) -> Vec<NodeInfo>
pub fn get_healthy_nodes(&self) -> Vec<NodeInfo>
Get all healthy nodes
Sourcepub fn has_quorum(&self) -> bool
pub fn has_quorum(&self) -> bool
Check if cluster has quorum
Sourcepub fn uptime_secs(&self) -> u64
pub fn uptime_secs(&self) -> u64
Get cluster uptime in seconds
Auto Trait Implementations§
impl !Freeze for ClusterCoordinator
impl !RefUnwindSafe for ClusterCoordinator
impl Send for ClusterCoordinator
impl Sync for ClusterCoordinator
impl Unpin for ClusterCoordinator
impl UnsafeUnpin for ClusterCoordinator
impl !UnwindSafe for ClusterCoordinator
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