forked from databendlabs/openraft
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Prevent panic when calling
Raft::change_membership()
on uninit…
…ialized node Previously, `change_membership()` assumed the current membership config was always non-empty and used the last config entry. However, uninitialized nodes lack a membership config, leading to panics. This commit adds checks to prevent `change_membership()` from panicking
- Loading branch information
1 parent
d5a4ce0
commit 2d6441a
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/tests/membership/t52_change_membership_on_uninitialized_node.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use maplit::btreemap; | ||
use openraft::ChangeMembers; | ||
use openraft::Config; | ||
|
||
use crate::fixtures::init_default_ut_tracing; | ||
use crate::fixtures::RaftRouter; | ||
|
||
/// Call `Raft::change_membership()` on an uninitialized node should not panic due to empty | ||
/// membership. | ||
#[async_entry::test(worker_threads = 8, init = "init_default_ut_tracing()", tracing_span = "debug")] | ||
async fn change_membership_on_uninitialized_node() -> Result<()> { | ||
let config = Arc::new( | ||
Config { | ||
enable_heartbeat: false, | ||
..Default::default() | ||
} | ||
.validate()?, | ||
); | ||
|
||
let mut router = RaftRouter::new(config.clone()); | ||
router.new_raft_node(0).await; | ||
|
||
let n0 = router.get_raft_handle(&0)?; | ||
let res = n0.change_membership(ChangeMembers::AddVoters(btreemap! {0=>()}), false).await; | ||
tracing::info!("{:?}", res); | ||
|
||
let err = res.unwrap_err(); | ||
tracing::info!("{}", err); | ||
|
||
assert!(err.to_string().contains("forward request to")); | ||
|
||
Ok(()) | ||
} |