Skip to content

Commit

Permalink
Merge pull request #962 from drmingdrmer/51-refine-change-membership
Browse files Browse the repository at this point in the history
Chore: simplify calling change_membership(): no need for btreeset
  • Loading branch information
drmingdrmer authored Dec 7, 2023
2 parents b84e414 + 2123bec commit dec6e32
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/tests/client_api/t50_lagging_network_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn lagging_network_write() -> Result<()> {
router.wait_for_log(&btreeset![0, 1, 2], Some(log_index), timeout(), "write one log").await?;

let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![0, 1, 2], false).await?;
node.change_membership([0, 1, 2], false).await?;
log_index += 2;
router.wait_for_state(&btreeset![0], ServerState::Leader, None, "changed").await?;
router.wait_for_state(&btreeset![1, 2], ServerState::Follower, None, "changed").await?;
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/membership/t11_add_learner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async fn add_learner_when_previous_membership_not_committed() -> Result<()> {

let node = router.get_raft_handle(&0)?;
tokio::spawn(async move {
let res = node.change_membership(btreeset![0, 1], false).await;
let res = node.change_membership([0, 1], false).await;
tracing::info!("do not expect res: {:?}", res);
unreachable!("do not expect any res");
});
Expand Down Expand Up @@ -272,7 +272,7 @@ async fn check_learner_after_leader_transferred() -> Result<()> {
router.wait_for_log(&btreeset![0, 1], Some(log_index), timeout(), "add learner").await?;

let node = router.get_raft_handle(&orig_leader_id)?;
node.change_membership(btreeset![1, 3, 4], false).await?;
node.change_membership([1, 3, 4], false).await?;
log_index += 2; // 2 change_membership log

tracing::info!(log_index, "--- old leader commits 2 membership log");
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/membership/t20_change_membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn update_membership_state() -> anyhow::Result<()> {
tracing::info!(log_index, "--- change membership from 012 to 01234");
{
let leader = router.get_raft_handle(&0)?;
let res = leader.change_membership(btreeset! {0,1,2,3,4}, false).await?;
let res = leader.change_membership([0, 1, 2, 3, 4], false).await?;
log_index += 2;

tracing::info!(log_index, "--- change_membership blocks until success: {:?}", res);
Expand Down Expand Up @@ -84,7 +84,7 @@ async fn change_with_new_learner_blocking() -> anyhow::Result<()> {
router.wait_for_log(&btreeset![0], Some(log_index), timeout(), "add learner").await?;

let node = router.get_raft_handle(&0)?;
let res = node.change_membership(btreeset! {0,1}, false).await?;
let res = node.change_membership([0, 1], false).await?;
log_index += 2;
tracing::info!(log_index, "--- change_membership blocks until success: {:?}", res);

Expand Down Expand Up @@ -116,7 +116,7 @@ async fn change_without_adding_learner() -> anyhow::Result<()> {
"--- change membership without adding-learner, allow_lagging=true"
);
{
let res = leader.change_membership(btreeset! {0,1}, false).await;
let res = leader.change_membership([0, 1], false).await;
let raft_err = res.unwrap_err();
tracing::debug!("raft_err: {:?}", raft_err);

Expand All @@ -132,7 +132,7 @@ async fn change_without_adding_learner() -> anyhow::Result<()> {

tracing::info!(log_index, "--- change membership without adding-learner");
{
let res = leader.change_membership(btreeset! {0,1}, false).await;
let res = leader.change_membership([0, 1], false).await;
let raft_err = res.unwrap_err();
match raft_err.api_error().unwrap() {
ClientWriteError::ChangeMembershipError(ChangeMembershipError::LearnerNotFound(err)) => {
Expand Down Expand Up @@ -173,7 +173,7 @@ async fn change_with_turn_removed_voter_to_learner() -> anyhow::Result<()> {

{
let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![0, 1], true).await?;
node.change_membership([0, 1], true).await?;
// 2 for change_membership
log_index += 2;

Expand Down
6 changes: 3 additions & 3 deletions tests/tests/membership/t30_commit_joint_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn commit_joint_config_during_0_to_012() -> Result<()> {
let router = router.clone();
async move {
let node = router.get_raft_handle(&0).unwrap();
let _x = node.change_membership(btreeset! {0,1,2}, false).await;
let _x = node.change_membership([0, 1, 2], false).await;
}
.instrument(tracing::debug_span!("spawn-change-membership"))
});
Expand Down Expand Up @@ -115,7 +115,7 @@ async fn commit_joint_config_during_012_to_234() -> Result<()> {

tracing::info!(log_index, "--- changing config to 0,1,2");
let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![0, 1, 2], false).await?;
node.change_membership([0, 1, 2], false).await?;
log_index += 2;

router.wait_for_log(&btreeset![0, 1, 2], Some(log_index), None, "cluster of 0,1,2").await?;
Expand All @@ -127,7 +127,7 @@ async fn commit_joint_config_during_012_to_234() -> Result<()> {
tokio::spawn(
async move {
let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![2, 3, 4], false).await?;
node.change_membership([2, 3, 4], false).await?;
Ok::<(), anyhow::Error>(())
}
.instrument(tracing::debug_span!("spawn-change-membership")),
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/membership/t31_remove_leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn remove_leader() -> Result<()> {
router.wait_for_log(&btreeset![0, 1], Some(log_index), timeout(), "add learner").await?;

let node = router.get_raft_handle(&orig_leader)?;
node.change_membership(btreeset![1, 2, 3], false).await?;
node.change_membership([1, 2, 3], false).await?;
// 2 for change_membership
log_index += 2;

Expand Down Expand Up @@ -133,7 +133,7 @@ async fn remove_leader_and_convert_to_learner() -> Result<()> {
tracing::info!(log_index, "--- change membership and retain removed node as learner");
{
let node = router.get_raft_handle(&old_leader)?;
node.change_membership(btreeset![1, 2, 3], true).await?;
node.change_membership([1, 2, 3], true).await?;
log_index += 2;
}

Expand Down Expand Up @@ -195,7 +195,7 @@ async fn remove_leader_access_new_cluster() -> Result<()> {
tracing::info!(log_index, "--- change membership 012 to 2");
{
let node = router.get_raft_handle(&orig_leader)?;
node.change_membership(btreeset![2], false).await?;
node.change_membership([2], false).await?;
// 2 change_membership logs
log_index += 2;

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/membership/t31_removed_follower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn stop_replication_to_removed_follower() -> Result<()> {
tracing::info!(log_index, "--- changing config to 0,3,4");
{
let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![0, 3, 4], false).await?;
node.change_membership([0, 3, 4], false).await?;
log_index += 2;

for i in [0, 3, 4] {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/membership/t51_remove_unreachable_follower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn stop_replication_to_removed_unreachable_follower_network_failure() -> R
tracing::info!(log_index, "--- changing config to 0,1,2");
{
let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![0, 1, 2], false).await?;
node.change_membership([0, 1, 2], false).await?;
log_index += 2;

for i in &[0, 1, 2] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn t99_issue_584_replication_state_reverted() -> Result<()> {
);
{
let leader = router.get_raft_handle(&0)?;
leader.change_membership(btreeset![0, 1], false).await?;
leader.change_membership([0, 1], false).await?;
log_index += 2; // 2 change_membership log

let _ = log_index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn snapshot_to_unreachable_node_should_not_block() -> Result<()> {
"--- change membership to {{0}}, replication should be closed and re-spawned, snapshot streaming should stop at once"
);
{
n0.change_membership(btreeset! {0}, true).await?;
n0.change_membership([0], true).await?;
n0.wait(timeout()).voter_ids([0], "change membership to {{0}}").await?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn state_machine_apply_membership() -> Result<()> {

tracing::info!(log_index, "--- changing cluster config");
let node = router.get_raft_handle(&0)?;
node.change_membership(btreeset![0, 1, 2], false).await?;
node.change_membership([0, 1, 2], false).await?;

log_index += 2;

Expand Down

0 comments on commit dec6e32

Please sign in to comment.