Skip to content

Instantly share code, notes, and snippets.

@NingLin-P
Created March 22, 2022 14:04
Show Gist options
  • Save NingLin-P/966e92dae16afa5bd61ec4109c7ea3c5 to your computer and use it in GitHub Desktop.
Save NingLin-P/966e92dae16afa5bd61ec4109c7ea3c5 to your computer and use it in GitHub Desktop.
#[test]
fn test_fake_merge_target_message() {
let mut cluster = new_node_cluster(0, 4);
configure_for_merge(&mut cluster);
let pd_client = Arc::clone(&cluster.pd_client);
pd_client.disable_default_operator();
let r1 = cluster.run_conf_change();
pd_client.must_add_peer(r1, new_peer(2, 2));
pd_client.must_add_peer(r1, new_peer(3, 3));
pd_client.must_add_peer(r1, new_learner_peer(4, 4));
cluster.must_put(b"k1", b"v1");
cluster.must_put(b"k3", b"v3");
for i in 1..4 {
must_get_equal(&cluster.get_engine(i), b"k1", b"v1");
must_get_equal(&cluster.get_engine(i), b"k3", b"v3");
}
let region = pd_client.get_region(b"k1").unwrap();
cluster.must_split(&region, b"k2");
let left = pd_client.get_region(b"k1").unwrap();
let right = pd_client.get_region(b"k3").unwrap();
let schedule_merge_fp = "on_schedule_merge";
fail::cfg(schedule_merge_fp, "return()").unwrap();
cluster.must_try_merge(right.get_id(), left.get_id());
// Wait until all peer apply prepare merge
sleep_ms(100);
// isolate peer 4
cluster.stop_node(4);
// remove peer from target region to trigger rollback.
pd_client.must_remove_peer(left.get_id(), find_peer(&left, 2).unwrap().clone());
must_get_none(&cluster.get_engine(2), b"k1");
fail::remove(schedule_merge_fp);
// wait until merge rollback
sleep_ms(100);
// isolate peer 3
cluster.stop_node(3);
// remove and recover peer 4 so it will destroy itself by tombstone message
pd_client.must_remove_peer(right.get_id(), new_learner_peer(4, 4));
cluster.run_node(4).unwrap();
must_get_none(&cluster.get_engine(4), b"k3");
// isolate peer 1 and peer 2, so peer 3 will send message to peer 4
cluster.stop_node(1);
cluster.stop_node(2);
// recover peer 3, it will send message to peer 4 and responses by a gc message with merge target
// thus destroy itself
cluster.run_node(3).unwrap();
// wait destroy
sleep_ms(500);
must_get_equal(&cluster.get_engine(3), b"3", b"v3");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment