From 583956da7ffc9feeb92c80fdbe9c5f86922f5df3 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Fri, 3 Jan 2025 17:48:38 +0100 Subject: [PATCH] [server] Configurable cluster timeouts #1447 (#1455) configurable timeout --- agdb_server/src/cluster.rs | 4 ++-- agdb_server/src/config.rs | 12 ++++++++++++ agdb_server/tests/routes/misc_routes.rs | 2 ++ agdb_server/tests/test_server.rs | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/agdb_server/src/cluster.rs b/agdb_server/src/cluster.rs index fea70191..37c26a73 100644 --- a/agdb_server/src/cluster.rs +++ b/agdb_server/src/cluster.rs @@ -184,8 +184,8 @@ pub(crate) async fn new(config: &Config, db: &ServerDb, db_pool: &DbPool) -> Ser hash, size: std::cmp::max(config.cluster.len() as u64, 1), election_factor: 1, - heartbeat_timeout: Duration::from_secs(1), - term_timeout: Duration::from_secs(3), + heartbeat_timeout: Duration::from_millis(config.cluster_heartbeat_timeout_ms), + term_timeout: Duration::from_millis(config.cluster_term_timeout_ms), }; let raft = Arc::new(RwLock::new(raft::Cluster::new(storage, settings))); let mut nodes = vec![]; diff --git a/agdb_server/src/config.rs b/agdb_server/src/config.rs index 1c407434..f9b075f1 100644 --- a/agdb_server/src/config.rs +++ b/agdb_server/src/config.rs @@ -24,6 +24,8 @@ pub(crate) struct ConfigImpl { pub(crate) data_dir: String, pub(crate) pepper_path: String, pub(crate) cluster_token: String, + pub(crate) cluster_heartbeat_timeout_ms: u64, + pub(crate) cluster_term_timeout_ms: u64, pub(crate) cluster: Vec, #[serde(skip)] pub(crate) cluster_node_id: usize, @@ -81,6 +83,8 @@ pub(crate) fn new(config_file: &str) -> ServerResult { data_dir: "agdb_server_data".to_string(), pepper_path: String::new(), cluster_token: "cluster".to_string(), + cluster_heartbeat_timeout_ms: 1000, + cluster_term_timeout_ms: 3000, cluster: vec![], cluster_node_id: 0, start_time: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(), @@ -169,6 +173,8 @@ mod tests { data_dir: "agdb_server_data".to_string(), pepper_path: String::new(), cluster_token: "cluster".to_string(), + cluster_heartbeat_timeout_ms: 1000, + cluster_term_timeout_ms: 3000, cluster: vec![Url::parse("localhost:3001").unwrap()], cluster_node_id: 0, start_time: 0, @@ -196,6 +202,8 @@ mod tests { data_dir: "agdb_server_data".to_string(), pepper_path: pepper_file.filename.to_string(), cluster_token: "cluster".to_string(), + cluster_heartbeat_timeout_ms: 1000, + cluster_term_timeout_ms: 3000, cluster: vec![], cluster_node_id: 0, start_time: 0, @@ -221,6 +229,8 @@ mod tests { data_dir: "agdb_server_data".to_string(), pepper_path: "missing_file".to_string(), cluster_token: "cluster".to_string(), + cluster_heartbeat_timeout_ms: 1000, + cluster_term_timeout_ms: 3000, cluster: vec![], cluster_node_id: 0, start_time: 0, @@ -245,6 +255,8 @@ mod tests { data_dir: "agdb_server_data".to_string(), pepper_path: pepper_file.filename.to_string(), cluster_token: "cluster".to_string(), + cluster_heartbeat_timeout_ms: 1000, + cluster_term_timeout_ms: 3000, cluster: vec![], cluster_node_id: 0, start_time: 0, diff --git a/agdb_server/tests/routes/misc_routes.rs b/agdb_server/tests/routes/misc_routes.rs index c8c14129..cec21fda 100644 --- a/agdb_server/tests/routes/misc_routes.rs +++ b/agdb_server/tests/routes/misc_routes.rs @@ -169,6 +169,8 @@ async fn basepath_test() -> anyhow::Result<()> { config.insert("log_level", "INFO".into()); config.insert("pepper_path", "".into()); config.insert("cluster_token", "test".into()); + config.insert("cluster_heartbeat_timeout_ms", 1000.into()); + config.insert("cluster_term_timeout_ms", 3000.into()); config.insert("cluster", Vec::::new().into()); let _server = TestServerImpl::with_config(config).await?; diff --git a/agdb_server/tests/test_server.rs b/agdb_server/tests/test_server.rs index 9bb9b123..19dbf5e4 100644 --- a/agdb_server/tests/test_server.rs +++ b/agdb_server/tests/test_server.rs @@ -141,6 +141,8 @@ impl TestServerImpl { config.insert("log_level", "INFO".into()); config.insert("pepper_path", "".into()); config.insert("cluster_token", "test".into()); + config.insert("cluster_heartbeat_timeout_ms", 1000.into()); + config.insert("cluster_term_timeout_ms", 3000.into()); config.insert("cluster", Vec::::new().into()); Self::with_config(config).await @@ -379,6 +381,8 @@ pub async fn create_cluster(nodes: usize) -> anyhow::Result> config.insert("data_dir", SERVER_DATA_DIR.into()); config.insert("pepper_path", "".into()); config.insert("cluster_token", "test".into()); + config.insert("cluster_heartbeat_timeout_ms", 1000.into()); + config.insert("cluster_term_timeout_ms", 3000.into()); configs.push(config); cluster.push(format!("http://{HOST}:{port}"));