-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consider joint config when starting up and committing.
- Change: MembershipConfig support more than 2 configs - Makes fields in MembershipConfig privates. Provides methods to manipulate membership. - Fix: commit without replication only when membership contains only one node. Previously it just checks the first config, which results in data loss if the cluster is in a joint config. - Fix: when starting up, count all nodes but not only the nodes in the first config to decide if it is a single node cluster.
- Loading branch information
1 parent
2320b8a
commit 6c0ccaf
Showing
26 changed files
with
280 additions
and
308 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[test] | ||
fn test_raft_core_initial_state() -> anyhow::Result<()> { | ||
// TODO(xp): test initial state decided by has_log, is single and is_voter | ||
Ok(()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use maplit::btreeset; | ||
|
||
use crate::raft::MembershipConfig; | ||
|
||
#[test] | ||
fn test_membership() -> anyhow::Result<()> { | ||
let m1 = MembershipConfig::new_multi(vec![btreeset! {1}]); | ||
let m123 = MembershipConfig::new_multi(vec![btreeset! {1,2,3}]); | ||
let m123_345 = MembershipConfig::new_multi(vec![btreeset! {1,2,3}, btreeset! {3,4,5}]); | ||
|
||
assert_eq!(Some(btreeset! {1}), m1.get_ith_config(0).cloned()); | ||
assert_eq!(Some(btreeset! {1,2,3}), m123.get_ith_config(0).cloned()); | ||
assert_eq!(Some(btreeset! {1,2,3}), m123_345.get_ith_config(0).cloned()); | ||
|
||
assert_eq!(None, m1.get_ith_config(1).cloned()); | ||
assert_eq!(None, m123.get_ith_config(1).cloned()); | ||
assert_eq!(Some(btreeset! {3,4,5}), m123_345.get_ith_config(1).cloned()); | ||
|
||
assert!(m1.is_in_ith_config(0, &1)); | ||
assert!(!m1.is_in_ith_config(0, &2)); | ||
assert!(!m1.is_in_ith_config(1, &1)); | ||
assert!(!m1.is_in_ith_config(1, &2)); | ||
|
||
assert!(m123.is_in_ith_config(0, &1)); | ||
assert!(m123.is_in_ith_config(0, &2)); | ||
assert!(!m123.is_in_ith_config(1, &1)); | ||
assert!(!m123.is_in_ith_config(1, &2)); | ||
|
||
assert!(m123_345.is_in_ith_config(0, &1)); | ||
assert!(m123_345.is_in_ith_config(0, &2)); | ||
assert!(!m123_345.is_in_ith_config(1, &1)); | ||
assert!(m123_345.is_in_ith_config(1, &4)); | ||
|
||
assert_eq!(vec![1], m1.ith_config(0)); | ||
assert_eq!(vec![1, 2, 3], m123.ith_config(0)); | ||
assert_eq!(vec![1, 2, 3], m123_345.ith_config(0)); | ||
assert_eq!(vec![3, 4, 5], m123_345.ith_config(1)); | ||
|
||
assert_eq!(&btreeset! {1}, m1.all_nodes()); | ||
assert_eq!(&btreeset! {1,2,3}, m123.all_nodes()); | ||
assert_eq!(&btreeset! {1,2,3,4,5}, m123_345.all_nodes()); | ||
|
||
assert!(!m1.contains(&0)); | ||
assert!(m1.contains(&1)); | ||
assert!(m123_345.contains(&4)); | ||
assert!(!m123_345.contains(&6)); | ||
|
||
assert!(!m123.is_in_joint_consensus()); | ||
assert!(m123_345.is_in_joint_consensus()); | ||
|
||
assert_eq!( | ||
MembershipConfig::new_single(btreeset! {3,4,5}), | ||
m123_345.to_final_config() | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_membership_update() -> anyhow::Result<()> { | ||
// --- replace | ||
|
||
let mut m123 = MembershipConfig::new_single(btreeset! {1,2,3}); | ||
m123.replace(vec![btreeset! {2,3}, btreeset! {3,4}]); | ||
|
||
assert_eq!(&btreeset! {2,3,4}, m123.all_nodes()); | ||
assert_eq!(&vec![btreeset! {2,3}, btreeset! {3,4}], m123.get_configs()); | ||
|
||
// --- push | ||
|
||
m123.push(btreeset! {3,5}); | ||
|
||
assert_eq!(&btreeset! {2,3,4,5}, m123.all_nodes()); | ||
assert_eq!( | ||
&vec![btreeset! {2,3}, btreeset! {3,4}, btreeset! {3,5}], | ||
m123.get_configs() | ||
); | ||
|
||
// --- to final | ||
|
||
let got = m123.to_final_config(); | ||
|
||
assert_eq!(&btreeset! {3,5}, got.all_nodes()); | ||
assert_eq!(&vec![btreeset! {3,5}], got.get_configs()); | ||
|
||
Ok(()) | ||
} |
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
Oops, something went wrong.