Skip to content

Commit

Permalink
refactor progress set to etcd/raft style
Browse files Browse the repository at this point in the history
Signed-off-by: qupeng <[email protected]>
  • Loading branch information
hicqu committed Nov 7, 2019
1 parent a5e0f13 commit fe07882
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 263 deletions.
32 changes: 8 additions & 24 deletions benches/suites/progress_set.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::DEFAULT_RAFT_SETS;
use criterion::{Bencher, Criterion};
use raft::eraftpb::ConfState;
use raft::{Progress, ProgressSet};

pub fn bench_progress_set(c: &mut Criterion) {
bench_progress_set_new(c);
bench_progress_set_with_capacity(c);
bench_progress_set_insert_voter(c);
bench_progress_set_insert_learner(c);
bench_progress_set_promote_learner(c);
Expand All @@ -16,13 +16,13 @@ pub fn bench_progress_set(c: &mut Criterion) {
}

fn quick_progress_set(voters: usize, learners: usize) -> ProgressSet {
let mut set = ProgressSet::with_capacity(voters, learners, raft::default_logger());
(0..voters).for_each(|id| {
set.insert_voter(id as u64, Progress::new(0, 10)).ok();
});
(voters..(learners + voters)).for_each(|id| {
set.insert_learner(id as u64, Progress::new(0, 10)).ok();
});
let (voters, learners) = (voters as u64, learners as u64);
let voter_ids: Vec<u64> = (1..=voters).collect();
let learner_ids: Vec<u64> = ((1 + voters)..=(voters + learners)).collect();
let conf_state = ConfState::from((voter_ids, learner_ids));

let mut set = ProgressSet::new(raft::default_logger());
set.restore_conf_state(&conf_state, 0, 10);
set
}

Expand All @@ -35,22 +35,6 @@ pub fn bench_progress_set_new(c: &mut Criterion) {
c.bench_function("ProgressSet::new", bench);
}

pub fn bench_progress_set_with_capacity(c: &mut Criterion) {
let bench = |voters, learners| {
move |b: &mut Bencher| {
// No setup.
b.iter(|| ProgressSet::with_capacity(voters, learners, raft::default_logger()));
}
};

DEFAULT_RAFT_SETS.iter().for_each(|(voters, learners)| {
c.bench_function(
&format!("ProgressSet::with_capacity ({}, {})", voters, learners),
bench(*voters, *learners),
);
});
}

pub fn bench_progress_set_insert_voter(c: &mut Criterion) {
let bench = |voters, learners| {
move |b: &mut Bencher| {
Expand Down
2 changes: 1 addition & 1 deletion examples/five_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn on_ready(
ConfChangeType::RemoveNode => raft_group.raft.remove_node(node_id).unwrap(),
ConfChangeType::AddLearnerNode => raft_group.raft.add_learner(node_id).unwrap(),
}
let cs = raft_group.raft.prs().configuration().to_conf_state();
let cs = raft_group.raft.prs().to_conf_state();
store.wl().set_conf_state(cs);
} else {
// For normal proposals, extract the key-value pair and then
Expand Down
Loading

0 comments on commit fe07882

Please sign in to comment.