Skip to content

Commit

Permalink
fixes and improvements (#5)
Browse files Browse the repository at this point in the history
* some improvements

Signed-off-by: qupeng <[email protected]>

* fix a little bug

Signed-off-by: qupeng <[email protected]>

* remove useless code

Signed-off-by: qupeng <[email protected]>
  • Loading branch information
hicqu authored and Fullstop000 committed Dec 17, 2019
1 parent 0ad4a1a commit 4259f29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
29 changes: 14 additions & 15 deletions src/progress/progress_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ impl Configuration {
}
}

/// Take learners
pub fn take_learners(&mut self) -> HashSet<u64> {
std::mem::replace(&mut self.learners, HashSet::default())
}

/// Create a new `ConfState` from the configuration itself.
pub fn to_conf_state(&self) -> ConfState {
let mut state = ConfState::default();
Expand Down Expand Up @@ -432,22 +427,26 @@ impl ProgressSet {
F: FnMut(u64, bool),
{
let mut active = HashSet::default();
let learners = self.configuration.take_learners();
for (&id, pr) in self.iter_mut() {
if id == perspective_of {
active.insert(id);
continue;
}
f(id, pr.recent_active);
if learners.contains(&id) {
for id in &self.configuration.voters {
if *id == perspective_of {
active.insert(*id);
continue;
}
let pr = self.progress.get_mut(id).unwrap();
f(*id, pr.recent_active);
if pr.recent_active {
active.insert(id);
active.insert(*id);
}
pr.recent_active = false;
}
for id in &self.configuration.learners {
if *id == perspective_of {
continue;
}
let pr = self.progress.get_mut(id).unwrap();
f(*id, pr.recent_active);
pr.recent_active = false;
}
self.configuration.set_learners(learners);
self.configuration.has_quorum(&active)
}

Expand Down
4 changes: 2 additions & 2 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ impl<T: Storage> Raft<T> {
/// message from a peer.
#[allow(clippy::collapsible_if)]
pub fn step(&mut self, m: Message) -> Result<()> {
if m.term != 0 && m.get_group_id() != INVALID_ID {
if self.groups.update_group_id(m.from, m.get_group_id()) {
if m.term != 0 && m.group_id != INVALID_ID && self.is_leader() {
if self.groups.update_group_id(m.from, m.group_id) {
let prs = self.take_prs();
self.groups.resolve_delegates(&prs);
self.set_prs(prs);
Expand Down

0 comments on commit 4259f29

Please sign in to comment.