Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: CalvinNeo <[email protected]>
  • Loading branch information
CalvinNeo committed Jan 4, 2024
1 parent c3fa44b commit a19b89b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,17 @@ impl<T: Transport + 'static, ER: RaftEngine> ProxyForwarder<T, ER> {
true
};

let mut should_check_fap_snapshot = self.packed_envs.engine_store_cfg.enable_unips;
(|| {
fail::fail_point!("post_apply_snapshot_allow_no_unips", |_| {
// UniPS can't provide a snapshot currently
should_check_fap_snapshot = true;
});
})();
// We should handle fap snapshot even if enable_fast_add_peer is false.
// However, if enable_unips, by no means can we handle fap snapshot.
#[allow(clippy::collapsible_if)]
if self.packed_envs.engine_store_cfg.enable_unips {
if should_check_fap_snapshot {
let mut maybe_cached_info: Option<Arc<CachedRegionInfo>> = None;
let mut restart = false;
if self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::mixed_engine::write_batch::RocksWriteBatchVec;
pub trait ElementaryWriteBatch: Send {
fn as_any(&self) -> &dyn std::any::Any;

// If it uses default write batch(usually rocksdb's wb)
fn use_default(&self) -> bool;

fn put(&mut self, key: &[u8], value: &[u8]) -> Result<()>;
Expand Down
5 changes: 5 additions & 0 deletions proxy_components/engine_tiflash/src/proxy_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ pub fn log_check_double_write(_: &RocksWriteBatchVec) -> bool {

#[cfg(any(test, feature = "testexport"))]
pub fn log_check_double_write(batch: &RocksWriteBatchVec) -> bool {
if !batch.element_wb.use_default() {
// This is check if we don't use unips.
// It will print out dummy infomation when using unips.
return false;
}
check_double_write(batch);
// TODO(tiflash) re-support this tracker.
let mut e = true;
Expand Down
22 changes: 12 additions & 10 deletions proxy_tests/proxy/shared/fast_add_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum PauseType {
fn basic_fast_add_peer() {
tikv_util::set_panic_hook(true, "./");
let (mut cluster, pd_client) = new_mock_cluster(0, 2);
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;
// fail::cfg("on_pre_write_apply_state", "return").unwrap();
fail::cfg("fap_mock_fake_snapshot", "return(1)").unwrap();
Expand Down Expand Up @@ -67,7 +67,7 @@ fn test_overlap_last_apply_old() {
let (mut cluster, pd_client) = new_mock_cluster_snap(0, 3);
pd_client.disable_default_operator();
disable_auto_gen_compact_log(&mut cluster);
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;
tikv_util::set_panic_hook(true, "./");
// Can always apply snapshot immediately
Expand All @@ -89,13 +89,15 @@ fn test_overlap_last_apply_old() {
pd_client.must_add_peer(1, new_learner_peer(3, 3003));
std::thread::sleep(std::time::Duration::from_millis(1000));

debug!("prepare split");
// Split
check_key(&cluster, b"k1", b"v1", Some(true), None, Some(vec![1]));
check_key(&cluster, b"k3", b"v3", Some(true), None, Some(vec![1]));
// Generates 2 peers {1001@1, 1002@3} for region 1.
// However, we use the older snapshot, so the 1002 peer is not inited.
cluster.must_split(&cluster.get_region(b"k1"), b"k2");

debug!("prepare remove peer");
let new_one_1000_k1 = cluster.get_region(b"k1");
let old_one_1_k3 = cluster.get_region(b"k3"); // region_id = 1
assert_ne!(new_one_1000_k1.get_id(), old_one_1_k3.get_id());
Expand Down Expand Up @@ -196,7 +198,7 @@ fn test_overlap_apply_legacy_in_the_middle() {
let (mut cluster, pd_client) = new_mock_cluster_snap(0, 3);
pd_client.disable_default_operator();
disable_auto_gen_compact_log(&mut cluster);
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;
cluster.cfg.tikv.raft_store.store_batch_system.pool_size = 4;
cluster.cfg.tikv.raft_store.apply_batch_system.pool_size = 4;
Expand Down Expand Up @@ -348,7 +350,7 @@ fn simple_fast_add_peer(
// The case in TiFlash is (DelayedPeer, false, Build)
tikv_util::set_panic_hook(true, "./");
let (mut cluster, pd_client) = new_mock_cluster(0, 3);
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;
if !check_timeout {
fail::cfg("fap_core_fallback_millis", "return(1000000)").unwrap();
Expand Down Expand Up @@ -764,7 +766,7 @@ fn test_existing_peer() {

tikv_util::set_panic_hook(true, "./");
let (mut cluster, pd_client) = new_mock_cluster(0, 2);
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;
// fail::cfg("on_pre_write_apply_state", "return").unwrap();
disable_auto_gen_compact_log(&mut cluster);
Expand Down Expand Up @@ -813,7 +815,7 @@ fn test_existing_peer() {
fn test_apply_snapshot() {
tikv_util::set_panic_hook(true, "./");
let (mut cluster, pd_client) = new_mock_cluster(0, 3);
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;
// fail::cfg("on_pre_write_apply_state", "return").unwrap();
disable_auto_gen_compact_log(&mut cluster);
Expand Down Expand Up @@ -893,7 +895,7 @@ fn test_apply_snapshot() {
fn test_split_no_fast_add() {
let (mut cluster, pd_client) = new_mock_cluster_snap(0, 3);
pd_client.disable_default_operator();
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;

tikv_util::set_panic_hook(true, "./");
Expand Down Expand Up @@ -936,7 +938,7 @@ fn test_split_no_fast_add() {
fn test_split_merge() {
let (mut cluster, pd_client) = new_mock_cluster_snap(0, 3);
pd_client.disable_default_operator();
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;

tikv_util::set_panic_hook(true, "./");
Expand Down Expand Up @@ -989,7 +991,7 @@ fn test_split_merge() {
fn test_fall_back_to_slow_path() {
let (mut cluster, pd_client) = new_mock_cluster_snap(0, 2);
pd_client.disable_default_operator();
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;

tikv_util::set_panic_hook(true, "./");
Expand Down Expand Up @@ -1028,7 +1030,7 @@ fn test_fall_back_to_slow_path() {
fn test_single_replica_migrate() {
let (mut cluster, pd_client) = new_mock_cluster_snap(0, 3);
pd_client.disable_default_operator();
cluster.cfg.proxy_cfg.engine_store.enable_unips = true;
fail::cfg("post_apply_snapshot_allow_no_unips", "");
cluster.cfg.proxy_cfg.engine_store.enable_fast_add_peer = true;

tikv_util::set_panic_hook(true, "./");
Expand Down

0 comments on commit a19b89b

Please sign in to comment.