Skip to content

Commit

Permalink
[server] Configurable cluster timeouts #1447 (#1455)
Browse files Browse the repository at this point in the history
configurable timeout
  • Loading branch information
michaelvlach authored Jan 3, 2025
1 parent 22178fb commit 583956d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions agdb_server/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down
12 changes: 12 additions & 0 deletions agdb_server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url>,
#[serde(skip)]
pub(crate) cluster_node_id: usize,
Expand Down Expand Up @@ -81,6 +83,8 @@ pub(crate) fn new(config_file: &str) -> ServerResult<Config> {
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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions agdb_server/tests/routes/misc_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>::new().into());

let _server = TestServerImpl::with_config(config).await?;
Expand Down
4 changes: 4 additions & 0 deletions agdb_server/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>::new().into());

Self::with_config(config).await
Expand Down Expand Up @@ -379,6 +381,8 @@ pub async fn create_cluster(nodes: usize) -> anyhow::Result<Vec<TestServerImpl>>
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}"));
Expand Down

0 comments on commit 583956d

Please sign in to comment.