-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* raftstore,server: support follower read Signed-off-by: 5kbpers <tangminghua@pingcap.com> * raftstore: fix condition check of read on replica Signed-off-by: 5kbpers <tangminghua@pingcap.com> * raftstore: follower read waits for apply index reaches read index Signed-off-by: 5kbpers <tangminghua@pingcap.com> * add a test of waiting for read index Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test_wait_for_apply_index Signed-off-by: 5kbpers <tangminghua@pingcap.com> * dec pending reads count after follower handle read index cmd Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * remove unused file Signed-off-by: 5kbpers <tangminghua@pingcap.com> * fix test_wait_for_apply_index Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update comments Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update test_wait_for_apply_index Signed-off-by: 5kbpers <tangminghua@pingcap.com> * update dependency 'kvproto' Signed-off-by: 5kbpers <tangminghua@pingcap.com>
- Loading branch information
Showing
8 changed files
with
165 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use std::sync::Arc; | ||
|
||
use fail; | ||
use std::time::Duration; | ||
use test_raftstore::*; | ||
use tikv_util::HandyRwLock; | ||
|
||
#[test] | ||
fn test_wait_for_apply_index() { | ||
let _guard = crate::setup(); | ||
let mut cluster = new_server_cluster(0, 3); | ||
|
||
// Increase the election tick to make this test case running reliably. | ||
configure_for_lease_read(&mut cluster, Some(50), Some(10_000)); | ||
let pd_client = Arc::clone(&cluster.pd_client); | ||
pd_client.disable_default_operator(); | ||
|
||
let r1 = cluster.run_conf_change(); | ||
cluster.must_put(b"k0", b"v0"); | ||
let p2 = new_peer(2, 2); | ||
cluster.pd_client.must_add_peer(r1, p2.clone()); | ||
let p3 = new_peer(3, 3); | ||
cluster.pd_client.must_add_peer(r1, p3.clone()); | ||
must_get_equal(&cluster.get_engine(3), b"k0", b"v0"); | ||
|
||
let region = cluster.get_region(b"k0"); | ||
cluster.must_transfer_leader(region.get_id(), p2.clone()); | ||
|
||
// Block all write cmd applying of Peer 3. | ||
fail::cfg("on_apply_write_cmd", "sleep(2000)").unwrap(); | ||
cluster.must_put(b"k1", b"v1"); | ||
must_get_equal(&cluster.get_engine(2), b"k1", b"v1"); | ||
|
||
// Peer 3 does not apply the cmd of putting 'k1' right now, then the follower read must | ||
// be blocked. | ||
must_get_none(&cluster.get_engine(3), b"k1"); | ||
let mut request = new_request( | ||
region.get_id(), | ||
region.get_region_epoch().clone(), | ||
vec![new_get_cf_cmd("default", b"k1")], | ||
false, | ||
); | ||
request.mut_header().set_peer(p3.clone()); | ||
request.mut_header().set_follower_read(true); | ||
let (cb, rx) = make_cb(&request); | ||
cluster | ||
.sim | ||
.rl() | ||
.async_command_on_node(3, request, cb) | ||
.unwrap(); | ||
// Must timeout here | ||
assert!(rx.recv_timeout(Duration::from_millis(500)).is_err()); | ||
fail::cfg("on_apply_write_cmd", "off").unwrap(); | ||
|
||
// After write cmd applied, the follower read will be executed. | ||
match rx.recv_timeout(Duration::from_secs(3)) { | ||
Ok(resp) => { | ||
assert_eq!(resp.get_responses().len(), 1); | ||
assert_eq!(resp.get_responses()[0].get_get().get_value(), b"v1"); | ||
} | ||
Err(_) => panic!("follower read failed"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters