datafusion_dist/
cluster.rs

1use std::{
2    collections::HashMap,
3    fmt::{Debug, Display},
4};
5
6use serde::{Deserialize, Serialize};
7
8use crate::DistResult;
9
10#[async_trait::async_trait]
11pub trait DistCluster: Debug + Send + Sync {
12    // Send heartbeat
13    async fn heartbeat(&self, node_id: NodeId, state: NodeState) -> DistResult<()>;
14    // Get alive nodes
15    async fn alive_nodes(&self) -> DistResult<HashMap<NodeId, NodeState>>;
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
19pub struct NodeId {
20    pub host: String,
21    pub port: u16,
22}
23
24impl Display for NodeId {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        write!(f, "{}:{}", self.host, self.port)
27    }
28}
29
30#[derive(Debug, Clone, Default, Serialize, Deserialize)]
31pub struct NodeState {
32    pub total_memory: u64,
33    pub used_memory: u64,
34    pub free_memory: u64,
35    pub available_memory: u64,
36    pub global_cpu_usage: f32,
37    pub num_running_tasks: u32,
38}