From f50a6f3d822a0c7a3f93dfe08f013c38057dd3c7 Mon Sep 17 00:00:00 2001 From: Phoeniix Zhao Date: Thu, 25 Jan 2024 15:25:02 +0800 Subject: [PATCH] fix: allow a single node cluster to scale out to a multiple nodes cluster Signed-off-by: Phoeniix Zhao --- curp/src/server/raw_curp/mod.rs | 5 +---- curp/src/server/raw_curp/tests.rs | 13 ------------- curp/tests/it/server.rs | 17 ----------------- 3 files changed, 1 insertion(+), 34 deletions(-) diff --git a/curp/src/server/raw_curp/mod.rs b/curp/src/server/raw_curp/mod.rs index c6d5ed455..cd64c1db0 100644 --- a/curp/src/server/raw_curp/mod.rs +++ b/curp/src/server/raw_curp/mod.rs @@ -1246,10 +1246,7 @@ impl RawCurp { let mut all_nodes = HashSet::new(); all_nodes.extend(config.voters()); all_nodes.extend(&config.learners); - if statuses_ids.len() < 3 - || all_nodes != statuses_ids - || !config.voters().is_disjoint(&config.learners) - { + if all_nodes != statuses_ids || !config.voters().is_disjoint(&config.learners) { return Err(CurpError::invalid_config()); } Ok(()) diff --git a/curp/src/server/raw_curp/tests.rs b/curp/src/server/raw_curp/tests.rs index 24a8b6e16..20d02f7a6 100644 --- a/curp/src/server/raw_curp/tests.rs +++ b/curp/src/server/raw_curp/tests.rs @@ -845,19 +845,6 @@ fn remove_non_exists_node_should_return_node_not_exists_error() { assert!(matches!(resp, Err(CurpError::NodeNotExists(())))); } -#[traced_test] -#[test] -fn remove_node_should_return_invalid_config_error_when_nodes_count_less_than_3() { - let curp = { - let exe_tx = MockCEEventTxApi::::default(); - Arc::new(RawCurp::new_test(3, exe_tx, mock_role_change())) - }; - let follower_id = curp.cluster().get_id_by_name("S1").unwrap(); - let changes = vec![ConfChange::remove(follower_id)]; - let resp = curp.check_new_config(&changes); - assert!(matches!(resp, Err(CurpError::InvalidConfig(())))); -} - #[traced_test] #[test] fn update_node_should_update_the_address_of_node() { diff --git a/curp/tests/it/server.rs b/curp/tests/it/server.rs index 07860d42c..52b008775 100644 --- a/curp/tests/it/server.rs +++ b/curp/tests/it/server.rs @@ -386,23 +386,6 @@ async fn propose_update_node_should_success() { assert!(member.is_some_and(|m| m.addrs == ["new_addr"])); } -#[tokio::test(flavor = "multi_thread")] -#[abort_on_panic] -async fn propose_remove_node_should_failed_when_cluster_nodes_equals_to_three() { - init_logger(); - - let group = CurpGroup::new(3).await; - let client = group.new_client().await; - - let node_id = group.nodes.keys().next().copied().unwrap(); - let changes = vec![ConfChange::remove(node_id)]; - let res = client.propose_conf_change(changes).await; - assert!(matches!( - CurpError::from(res.unwrap_err()), - CurpError::InvalidConfig(()) - )); -} - #[tokio::test(flavor = "multi_thread")] #[abort_on_panic] async fn shutdown_rpc_should_shutdown_the_cluster_when_client_has_wrong_leader() {