Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some additional documentation. #106

Merged
merged 2 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/eraftpb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
37 changes: 26 additions & 11 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ pub struct Raft<T: Storage> {
/// The ID of this node.
pub id: u64,

/// The current read states
/// The current read states.
pub read_states: Vec<ReadState>,

/// The log
/// The persistent log.
pub raft_log: RaftLog<T>,

/// The maximum number of messages that can be inflight.
Expand All @@ -113,9 +113,14 @@ pub struct Raft<T: Storage> {
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<u64, bool>,

/// The list of messages.
Expand All @@ -125,7 +130,8 @@ pub struct Raft<T: Storage> {
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<u64>,

/// Only one conf change may be pending (in the log, but not yet
Expand All @@ -150,8 +156,14 @@ pub struct Raft<T: Storage> {

/// 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,
Expand Down Expand Up @@ -560,7 +572,7 @@ impl<T: Storage> Raft<T> {
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<Vec<u8>>) {
let self_id = self.id;
let mut prs = self.take_prs();
Expand Down Expand Up @@ -828,19 +840,22 @@ impl<T: Storage> Raft<T> {
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()
}

Expand Down
2 changes: 1 addition & 1 deletion src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<T: Storage> RawNode<T> {
}

/// 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<u8>, cc: ConfChange) -> Result<()> {
let data = protobuf::Message::write_to_bytes(&cc)?;
let mut m = Message::new();
Expand Down
2 changes: 1 addition & 1 deletion src/read_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down