use tokio::sync::mpsc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ClusterStatusView {
pub node_id: u64,
pub is_leader: bool,
pub current_leader: Option<u64>,
pub term: u64,
pub last_applied_index: Option<u64>,
pub member_count: usize,
pub voter_count: usize,
}
#[async_trait::async_trait]
pub trait CoordinationBackend: Send + Sync {
async fn publish(&self, topic: &str, payload: &[u8]) -> Result<(), String>;
async fn subscribe(&self, topic: &str) -> Result<mpsc::Receiver<Vec<u8>>, String>;
async fn set(&self, key: &str, value: &[u8]) -> Result<(), String>;
async fn get(&self, key: &str) -> Result<Option<Vec<u8>>, String>;
async fn cas(&self, key: &str, old_val: Option<&[u8]>, new_val: &[u8]) -> Result<bool, String>;
async fn acquire_lock(&self, key: &str, value: &[u8], ttl_ms: u64) -> Result<bool, String>;
async fn renew_lock(&self, key: &str, value: &[u8], ttl_ms: u64) -> Result<bool, String>;
async fn release_lock(&self, key: &str, value: &[u8]) -> Result<bool, String> {
let _ = (key, value);
Ok(false)
}
fn cluster_size(&self) -> usize {
1
}
fn owns_partition_key(&self, key: &str) -> bool {
let _ = key;
true
}
fn is_leader(&self) -> bool {
true
}
fn cluster_status(&self) -> Option<ClusterStatusView> {
None
}
async fn shutdown(&self) {}
}