From e06012f5221ac1b79deb3d8d6b034d55b7fed54d Mon Sep 17 00:00:00 2001 From: Hoverbear Date: Sat, 10 Nov 2018 06:55:52 -0800 Subject: [PATCH 1/2] Correct lease with check quorum. --- src/raft.rs | 7 ++----- tests/integration_cases/test_raft.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/raft.rs b/src/raft.rs index 4457babb1..e2482068e 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -1427,14 +1427,11 @@ impl Raft { 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); diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index cacbeb7be..00246596d 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -2308,7 +2308,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); } From 9fb53296bd2734fac6abae873079fd722d8cc28a Mon Sep 17 00:00:00 2001 From: Hoverbear Date: Wed, 14 Nov 2018 06:20:01 -0800 Subject: [PATCH 2/2] Add config check for LeaseBased read only option --- src/config.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/config.rs b/src/config.rs index 3a11a6013..c5aea3399 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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. @@ -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(()) } }