Skip to content

Commit

Permalink
fix: allow a single node cluster to scale out to a multiple nodes clu…
Browse files Browse the repository at this point in the history
…ster

Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 authored and mergify[bot] committed Jan 26, 2024
1 parent 28f1315 commit f50a6f3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 34 deletions.
5 changes: 1 addition & 4 deletions curp/src/server/raw_curp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,7 @@ impl<C: Command, RC: RoleChange> RawCurp<C, RC> {
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(())
Expand Down
13 changes: 0 additions & 13 deletions curp/src/server/raw_curp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TestCommand>::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() {
Expand Down
17 changes: 0 additions & 17 deletions curp/tests/it/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f50a6f3

Please sign in to comment.