Skip to content

Commit

Permalink
clippy/fmt run
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoverbear committed Aug 8, 2018
1 parent 2b7977a commit 53e77aa
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 59 deletions.
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::{INVALID_ID, errors::{Error, Result}};
pub use super::read_only::{ReadOnlyOption, ReadState};
use super::{
errors::{Error, Result}, INVALID_ID,
};

/// Config contains the parameters to start a raft.
pub struct Config {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ extern crate protobuf;
extern crate quick_error;
extern crate rand;

mod config;
/// This module supplies the needed message types. However, it is autogenerated and thus cannot be
/// documented by field.
pub mod eraftpb;
mod errors;
mod config;
mod log_unstable;
mod progress;
mod raft;
Expand All @@ -240,13 +240,13 @@ mod status;
pub mod storage;
pub mod util;

pub use self::config::Config;
pub use self::errors::{Error, Result, StorageError};
pub use self::log_unstable::Unstable;
pub use self::progress::{Inflights, Progress, ProgressSet, ProgressState};
pub use self::raft::{
quorum, vote_resp_msg_type, Raft, SoftState, StateRole, INVALID_ID, INVALID_INDEX,
};
pub use self::config::Config;
pub use self::raft_log::{RaftLog, NO_LIMIT};
pub use self::raw_node::{is_empty_snap, Peer, RawNode, Ready, SnapshotStatus};
pub use self::read_only::{ReadOnlyOption, ReadState};
Expand All @@ -271,8 +271,8 @@ pub mod prelude {
Snapshot, SnapshotMetadata,
};

pub use raft::Raft;
pub use config::Config;
pub use raft::Raft;

pub use storage::{RaftState, Storage};

Expand Down
11 changes: 5 additions & 6 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use errors::Error;
use fxhash::FxHashMap;
use std::cmp;
use std::collections::hash_map::HashMap;
use errors::Error;

/// The state of the progress.
#[derive(Debug, PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -105,12 +105,12 @@ impl ProgressSet {
}

/// Returns an iterator across all the nodes and their progress.
pub fn iter(&self) -> impl Iterator<Item=(&u64, &Progress)> {
pub fn iter(&self) -> impl Iterator<Item = (&u64, &Progress)> {
self.voters.iter().chain(&self.learners)
}

/// Returns a mutable iterator across all the nodes and their progress.
pub fn iter_mut(&mut self) -> impl Iterator<Item=(&u64, &mut Progress)> {
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&u64, &mut Progress)> {
self.voters.iter_mut().chain(&mut self.learners)
}

Expand Down Expand Up @@ -154,11 +154,10 @@ impl ProgressSet {
if !self.learners.contains_key(&id) {
Err(Error::NotExists(id, "learners"))?
}

self.learners.remove(&id).map(|mut learner| {
if let Some(mut learner) = self.learners.remove(&id) {
learner.is_learner = false;
self.voters.insert(id, learner);
});
}
Ok(())
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ use protobuf::RepeatedField;
use rand::{self, Rng};

use super::errors::{Error, Result, StorageError};
use super::Config;
use super::progress::{Inflights, Progress, ProgressSet, ProgressState};
use super::raft_log::{self, RaftLog};
use super::read_only::{ReadOnly, ReadOnlyOption, ReadState};
use super::storage::Storage;
use super::Config;

// CAMPAIGN_PRE_ELECTION represents the first phase of a normal election when
// Config.pre_vote is true.
Expand Down Expand Up @@ -1914,10 +1914,8 @@ impl<T: Storage> Raft<T> {
if let Err(e) = self.mut_prs().insert_learner(id, p) {
panic!("{}", e);
}
} else {
if let Err(e) = self.mut_prs().insert_voter(id, p) {
panic!("{}", e);
}
} else if let Err(e) = self.mut_prs().insert_voter(id, p) {
panic!("{}", e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ use eraftpb::{
};
use protobuf::{self, RepeatedField};

use super::errors::{Error, Result};
use super::{Raft, SoftState, INVALID_ID};
use super::config::Config;
use super::errors::{Error, Result};
use super::read_only::ReadState;
use super::Status;
use super::Storage;
use super::{Raft, SoftState, INVALID_ID};

/// Represents a Peer node in the cluster.
#[derive(Debug, Default)]
Expand Down
51 changes: 9 additions & 42 deletions tests/cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4206,16 +4206,8 @@ fn test_prevote_with_check_quorum() {
network.cut(1, 3);
network.cut(2, 3);

assert_eq!(
network.peers[&1].state,
StateRole::Leader,
"peer 1 state",
);
assert_eq!(
network.peers[&2].state,
StateRole::Follower,
"peer 2 state",
);
assert_eq!(network.peers[&1].state, StateRole::Leader, "peer 1 state",);
assert_eq!(network.peers[&2].state, StateRole::Follower, "peer 2 state",);

network.send(vec![new_message(3, 3, MessageType::MsgHup, 0)]);

Expand All @@ -4230,30 +4222,13 @@ fn test_prevote_with_check_quorum() {
network.send(vec![new_message(1, 2, MessageType::MsgTransferLeader, 0)]);

// check whether the term values are expected
assert_eq!(
network.peers[&1].term, 4,
"peer 1 term",
);
assert_eq!(
network.peers[&2].term, 4,
"peer 2 term",
);
assert_eq!(
network.peers[&3].term, 2,
"peer 3 term",
);
assert_eq!(network.peers[&1].term, 4, "peer 1 term",);
assert_eq!(network.peers[&2].term, 4, "peer 2 term",);
assert_eq!(network.peers[&3].term, 2, "peer 3 term",);

// check state
assert_eq!(
network.peers[&1].state,
StateRole::Leader,
"peer 1 state",
);
assert_eq!(
network.peers[&2].state,
StateRole::Follower,
"peer 2 state",
);
assert_eq!(network.peers[&1].state, StateRole::Leader, "peer 1 state",);
assert_eq!(network.peers[&2].state, StateRole::Follower, "peer 2 state",);
assert_eq!(
network.peers[&3].state,
StateRole::PreCandidate,
Expand All @@ -4274,14 +4249,6 @@ fn test_prevote_with_check_quorum() {
network.send(vec![new_message(2, 2, MessageType::MsgHup, 0)]);

// check state
assert_eq!(
network.peers[&2].state,
StateRole::Leader,
"peer 2 state",
);
assert_eq!(
network.peers[&3].state,
StateRole::Follower,
"peer 3 state",
);
assert_eq!(network.peers[&2].state, StateRole::Leader, "peer 2 state",);
assert_eq!(network.peers[&3].state, StateRole::Follower, "peer 3 state",);
}

0 comments on commit 53e77aa

Please sign in to comment.