From 322a80b6af31fee717eccb5612e861d326537199 Mon Sep 17 00:00:00 2001 From: Hoverbear Date: Tue, 4 Sep 2018 11:09:31 -0700 Subject: [PATCH 1/2] Fix clippy lints. --- src/eraftpb.rs | 2 +- src/errors.rs | 4 ++-- src/lib.rs | 7 +++---- src/raft.rs | 2 +- src/raw_node.rs | 2 +- src/read_only.rs | 2 +- tests/tests.rs | 5 ++--- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/eraftpb.rs b/src/eraftpb.rs index e1fe5642c..18bae7dfa 100644 --- a/src/eraftpb.rs +++ b/src/eraftpb.rs @@ -3,7 +3,7 @@ // https://github.com/Manishearth/rust-clippy/issues/702 #![allow(unknown_lints)] -#![allow(clippy)] +#![cfg_attr(feature = "cargo-clippy", allow(clippy::all))] #![cfg_attr(rustfmt, rustfmt_skip)] diff --git a/src/errors.rs b/src/errors.rs index 41ee32689..4a7ea6f1f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -67,7 +67,7 @@ quick_error! { } impl cmp::PartialEq for Error { - #[allow(match_same_arms)] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] fn eq(&self, other: &Error) -> bool { match (self, other) { (&Error::StepPeerNotFound, &Error::StepPeerNotFound) => true, @@ -112,7 +112,7 @@ quick_error! { } impl cmp::PartialEq for StorageError { - #[allow(match_same_arms)] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] fn eq(&self, other: &StorageError) -> bool { match (self, other) { (&StorageError::Compacted, &StorageError::Compacted) => true, diff --git a/src/lib.rs b/src/lib.rs index 475d0bab3..152a5f014 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -212,9 +212,8 @@ For more information, check out an [example](examples/single_mem_node/main.rs#L1 */ -#![cfg_attr(feature = "dev", feature(plugin))] -#![cfg_attr(feature = "dev", plugin(clippy))] -#![cfg_attr(not(feature = "dev"), allow(unknown_lints))] +#![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))] +#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))] #![deny(missing_docs)] extern crate fxhash; @@ -289,6 +288,6 @@ pub mod prelude { /// Do any common test initialization. Eg set up logging, setup fail-rs. #[cfg(test)] -pub fn setup_for_test() { +fn setup_for_test() { let _ = env_logger::try_init(); } diff --git a/src/raft.rs b/src/raft.rs index 4f4f62823..b45163b64 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -560,7 +560,7 @@ impl Raft { self.bcast_heartbeat_with_ctx(ctx) } - #[allow(needless_pass_by_value)] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] fn bcast_heartbeat_with_ctx(&mut self, ctx: Option>) { let self_id = self.id; let mut prs = self.take_prs(); diff --git a/src/raw_node.rs b/src/raw_node.rs index 18d83c49a..42f1e4af2 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -286,7 +286,7 @@ impl RawNode { } /// ProposeConfChange proposes a config change. - #[allow(needless_pass_by_value)] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] pub fn propose_conf_change(&mut self, context: Vec, cc: ConfChange) -> Result<()> { let data = protobuf::Message::write_to_bytes(&cc)?; let mut m = Message::new(); diff --git a/src/read_only.rs b/src/read_only.rs index 0dbd6a279..efa57dc8c 100644 --- a/src/read_only.rs +++ b/src/read_only.rs @@ -135,7 +135,7 @@ impl ReadOnly { } *x == m.get_context() }) { - for _ in 0..i + 1 { + for _ in 0..=i { let rs = self.read_index_queue.pop_front().unwrap(); let status = self.pending_read_index.remove(&rs).unwrap(); rss.push(status); diff --git a/tests/tests.rs b/tests/tests.rs index de99854d1..0666745e4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -11,9 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg_attr(feature = "dev", feature(plugin))] -#![cfg_attr(feature = "dev", plugin(clippy))] -#![cfg_attr(not(feature = "dev"), allow(unknown_lints))] +#![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))] +#![cfg_attr(feature = "cargo-clippy", feature(tool_lints))] #[macro_use] extern crate log; From 4aaddc0d6bc759e063960eb3a47cda7a79b2f553 Mon Sep 17 00:00:00 2001 From: Hoverbear Date: Fri, 24 Aug 2018 11:42:19 -0700 Subject: [PATCH 2/2] Some additional documentation. --- src/raft.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/raft.rs b/src/raft.rs index b45163b64..3b8ee8bfa 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -95,10 +95,10 @@ pub struct Raft { /// The ID of this node. pub id: u64, - /// The current read states + /// The current read states. pub read_states: Vec, - /// The log + /// The persistent log. pub raft_log: RaftLog, /// The maximum number of messages that can be inflight. @@ -113,9 +113,14 @@ pub struct Raft { pub state: StateRole, /// Whether this is a learner node. + /// + /// Learners are not permitted to vote in elections, and are not counted for commit quorums. + /// They do replicate data from the leader. pub is_learner: bool, - /// The current votes. + /// The current votes for this node in an election. + /// + /// Reset when changing role. pub votes: FxHashMap, /// The list of messages. @@ -125,7 +130,8 @@ pub struct Raft { pub leader_id: u64, /// ID of the leader transfer target when its value is not None. - /// Follow the procedure defined in raft thesis 3.10. + /// + /// If this is Some(id), we follow the procedure defined in raft thesis 3.10. pub lead_transferee: Option, /// Only one conf change may be pending (in the log, but not yet @@ -150,8 +156,14 @@ pub struct Raft { /// Whether to check the quorum pub check_quorum: bool, - #[doc(hidden)] + + /// Enable the prevote algorithm. + /// + /// This enables a pre-election vote round on Candidates prior to disrupting the cluster. + /// + /// Enable this if greater cluster stability is preferred over faster elections. pub pre_vote: bool, + skip_bcast_commit: bool, heartbeat_timeout: usize, @@ -828,19 +840,22 @@ impl Raft { self.set_prs(prs); } - fn poll(&mut self, id: u64, t: MessageType, v: bool) -> usize { - if v { + /// Sets the vote of `id` to `vote`. + /// + /// Returns the number of votes for the `id` currently. + fn poll(&mut self, id: u64, msg_type: MessageType, vote: bool) -> usize { + if vote { info!( "{} received {:?} from {} at term {}", - self.tag, t, id, self.term + self.tag, msg_type, id, self.term ) } else { info!( "{} received {:?} rejection from {} at term {}", - self.tag, t, id, self.term + self.tag, msg_type, id, self.term ) } - self.votes.entry(id).or_insert(v); + self.votes.entry(id).or_insert(vote); self.votes.values().filter(|x| **x).count() }