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

Correct lease with check quorum. #141

Merged
merged 6 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub struct Config {
pub max_election_tick: usize,

/// Choose the linearizability mode or the lease mode to read data. If you don’t care about the read consistency and want a higher read performance, you can use the lease mode.
///
/// Setting this to `LeaseBased` requires `check_quorum = true`.
pub read_only_option: ReadOnlyOption,

/// Don't broadcast an empty raft entry to notify follower to commit an entry.
Expand Down Expand Up @@ -204,6 +206,12 @@ impl Config {
));
}

if self.read_only_option == ReadOnlyOption::LeaseBased && !self.check_quorum {
return Err(Error::ConfigInvalid(
"read_only_option == LeaseBased requires check_quorum == true".into(),
));
}

Ok(())
}
}
7 changes: 2 additions & 5 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,14 +1399,11 @@ impl<T: Storage> Raft<T> {
self.bcast_heartbeat_with_ctx(Some(ctx));
}
ReadOnlyOption::LeaseBased => {
let mut read_index = INVALID_INDEX;
if self.check_quorum {
read_index = self.raft_log.committed
}
let mut read_index = self.raft_log.committed;
if m.get_from() == INVALID_ID || m.get_from() == self.id {
// from local member
let rs = ReadState {
index: self.raft_log.committed,
index: read_index,
request_ctx: m.take_entries()[0].take_data(),
};
self.read_states.push(rs);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@ fn test_read_only_option_lease_without_check_quorum() {
let read_states = &nt.peers[&2].read_states;
assert!(!read_states.is_empty());
let rs = &read_states[0];
assert_eq!(rs.index, INVALID_ID);
assert_eq!(rs.index, 1);
let vec_ctx = ctx.as_bytes().to_vec();
assert_eq!(rs.request_ctx, vec_ctx);
}
Expand Down