Skip to content

Commit

Permalink
tests: cover all possible scenarios in upgrading tests (pingcap#1681) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 20, 2021
1 parent 2a1f987 commit eaa57ca
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
41 changes: 41 additions & 0 deletions tests/tiup/conf/diff_config_pessimistic.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use-checksum = true

# tables need to check.
[[check-tables]]
schema = "pes_db_target"
tables = ["t_target"]

[[table-config]]
schema = "pes_db_target"
table = "t_target"
is-sharding = true

[[table-config.source-tables]]
instance-id = "source-1"
schema = "pes_sharding1"
table = "~t.*"

[[table-config.source-tables]]
instance-id = "source-2"
schema = "pes_sharding2"
table = "~t.*"

[[source-db]]
host = "mysql1"
port = 3306
user = "root"
password = ""
instance-id = "source-1"

[[source-db]]
host = "mariadb2"
port = 3306
user = "root"
password = ""
instance-id = "source-2"

[target-db]
host = "tidb"
port = 4000
user = "root"
password = ""
39 changes: 39 additions & 0 deletions tests/tiup/conf/task_pessimistic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: upgrade_via_tiup_pessimistic
task-mode: all
is-sharding: true
shard-mode: pessimistic
enable-heartbeat: true

target-database:
host: tidb
port: 4000
user: "root"
password: ""

mysql-instances:
- source-id: "mysql-replica-01"
black-white-list: "instance"
route-rules: ["sharding-route-rules-table", "sharding-route-rules-schema"]

- source-id: "mariadb-replica-02"
black-white-list: "instance"
route-rules: ["sharding-route-rules-table", "sharding-route-rules-schema"]

black-white-list:
instance:
do-dbs: ["~^pes_sharding[\\d]+"]
do-tables:
- db-name: "~^pes_sharding[\\d]+"
tbl-name: "~^t[\\d]+"

routes:
sharding-route-rules-table:
schema-pattern: pes_sharding*
table-pattern: t*
target-schema: pes_db_target
target-table: t_target

sharding-route-rules-schema:
schema-pattern: pes_sharding*
target-schema: pes_db_target
54 changes: 53 additions & 1 deletion tests/tiup/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ WORK_DIR=$TEST_DIR/$TEST_NAME
mkdir -p $WORK_DIR

TASK_NAME="upgrade_via_tiup"
TASK_PESS_NAME="upgrade_via_tiup_pessimistic"
TASK_OPTI_NAME="upgrade_via_tiup_optimistic"

DB1=sharding1
DB2=sharding2
DB3=opt_sharding1
DB4=opt_sharding2
DB5=pes_sharding1
DB6=pes_sharding2
TBL1=t1
TBL2=t2
TBL3=t3
Expand All @@ -34,8 +38,11 @@ function exec_full_stage() {
exec_sql mariadb2 3306 "DROP DATABASE IF EXISTS $DB2;"
exec_sql mysql1 3306 "DROP DATABASE IF EXISTS $DB3;"
exec_sql mariadb2 3306 "DROP DATABASE IF EXISTS $DB4;"
exec_sql mysql1 3306 "DROP DATABASE IF EXISTS $DB5;"
exec_sql mariadb2 3306 "DROP DATABASE IF EXISTS $DB6;"
exec_sql tidb 4000 "DROP DATABASE IF EXISTS db_target;"
exec_sql tidb 4000 "DROP DATABASE IF EXISTS opt_db_target;"
exec_sql tidb 4000 "DROP DATABASE IF EXISTS pes_db_target;"
exec_sql tidb 4000 "DROP DATABASE IF EXISTS dm_meta;"

# # prepare full data
Expand Down Expand Up @@ -63,6 +70,19 @@ function exec_full_stage() {
exec_sql mysql1 3306 "INSERT INTO $DB3.$TBL2 (c1, c2) VALUES (2, '2');"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL2 (c1, c2) VALUES (11, '11');"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL3 (c1, c2) VALUES (12, '12');"

# prepare pessimistic full data
exec_sql mysql1 3306 "CREATE DATABASE $DB5;"
exec_sql mariadb2 3306 "CREATE DATABASE $DB6;"
exec_sql mysql1 3306 "CREATE TABLE $DB5.$TBL1 (c1 INT PRIMARY KEY, c2 TEXT);"
exec_sql mysql1 3306 "CREATE TABLE $DB5.$TBL2 (c1 INT PRIMARY KEY, c2 TEXT);"
exec_sql mariadb2 3306 "CREATE TABLE $DB6.$TBL2 (c1 INT PRIMARY KEY, c2 TEXT);"
exec_sql mariadb2 3306 "CREATE TABLE $DB6.$TBL3 (c1 INT PRIMARY KEY, c2 TEXT);"

exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL1 (c1, c2) VALUES (1, '1');"
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL2 (c1, c2) VALUES (2, '2');"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL2 (c1, c2) VALUES (11, '11');"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL3 (c1, c2) VALUES (12, '12');"
}

function exec_incremental_stage1() {
Expand All @@ -88,7 +108,23 @@ function exec_incremental_stage1() {
exec_sql mysql1 3306 "INSERT INTO $DB3.$TBL1 (c1, c2, c3) VALUES (103, '103', 103);"
exec_sql mysql1 3306 "INSERT INTO $DB3.$TBL2 (c1, c2, c4) VALUES (104, '104', 104);"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL2 (c1, c2, c3) VALUES (113, '113', 113);"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL3 (c1, c2, c4) VALUES (114, '113', 113);"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL3 (c1, c2, c4) VALUES (114, '114', 114);"

# prepare pessimistic incremental data
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL1 (c1, c2) VALUES (101, '101');"
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL2 (c1, c2) VALUES (102, '102');"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL2 (c1, c2) VALUES (111, '111');"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL3 (c1, c2) VALUES (112, '112');"

# pessimistic shard ddls
exec_sql mysql1 3306 "ALTER TABLE $DB5.$TBL1 ADD COLUMN c3 INT;"
exec_sql mysql1 3306 "ALTER TABLE $DB5.$TBL2 ADD COLUMN c3 INT;"

# prepare pessimistic incremental data
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL1 (c1, c2, c3) VALUES (103, '103', 103);"
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL2 (c1, c2, c3) VALUES (104, '104', 104);"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL2 (c1, c2) VALUES (113, '113');"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL3 (c1, c2) VALUES (114, '114');"
}

function exec_incremental_stage2() {
Expand All @@ -115,6 +151,22 @@ function exec_incremental_stage2() {
exec_sql mysql1 3306 "INSERT INTO $DB3.$TBL2 (c1, c2, c3, c4) VALUES (204, '204', 204, 204);"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL2 (c1, c2, c3, c4) VALUES (213, '213', 213, 213);"
exec_sql mariadb2 3306 "INSERT INTO $DB4.$TBL3 (c1, c2, c3, c4) VALUES (214, '214', 214, 214);"

# prepare pessimistic incremental data
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL1 (c1, c2, c3) VALUES (201, '201', 201);"
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL2 (c1, c2, c3) VALUES (202, '202', 202);"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL2 (c1, c2) VALUES (211, '211');"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL3 (c1, c2) VALUES (212, '212');"

# pessimistic shard ddls
exec_sql mariadb2 3306 "ALTER TABLE $DB6.$TBL2 ADD COLUMN c3 INT;"
exec_sql mariadb2 3306 "ALTER TABLE $DB6.$TBL3 ADD COLUMN c3 INT;"

# prepare pessimistic incremental data
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL1 (c1, c2, c3) VALUES (203, '203', 203);"
exec_sql mysql1 3306 "INSERT INTO $DB5.$TBL2 (c1, c2, c3) VALUES (204, '204', 204);"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL2 (c1, c2, c3) VALUES (213, '213', 213);"
exec_sql mariadb2 3306 "INSERT INTO $DB6.$TBL3 (c1, c2, c3) VALUES (214, '214', 214);"
}

function patch_nightly_with_tiup_mirror() {
Expand Down
13 changes: 13 additions & 0 deletions tests/tiup/upgrade-from-v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ function migrate_in_previous_v2() {

tiup dmctl:$PRE_VER --master-addr=master1:8261 start-task $CUR/conf/task.yaml
tiup dmctl:$PRE_VER --master-addr=master1:8261 start-task $CUR/conf/task_optimistic.yaml
tiup dmctl:$PRE_VER --master-addr=master1:8261 start-task $CUR/conf/task_pessimistic.yaml

exec_incremental_stage1

check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml

tiup dmctl:$PRE_VER --master-addr=master1:8261 pause-task $TASK_NAME

run_dmctl_with_retry $CUR_VER "query-status" "Running" 2 "Paused" 1
}

function upgrade_to_current_v2() {
Expand All @@ -53,6 +58,13 @@ function upgrade_to_current_v2() {
}

function migrate_in_v2 {
run_dmctl_with_retry $CUR_VER "query-status" "Running" 2 "Paused" 1
run_dmctl_with_retry $CUR_VER "show-ddl-locks" "\"result\": true" 1 "\"task\": \"$TASK_PESS_NAME\"" 1 "\"task\": \"$TASK_OPTI_NAME\"" 1

tiup dmctl:$CUR_VER --master-addr=master1:8261 resume-task $TASK_NAME

run_dmctl_with_retry $CUR_VER "query-status" "Running" 3

exec_incremental_stage2

echo "check sources"
Expand All @@ -62,6 +74,7 @@ function migrate_in_v2 {

check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
check_sync_diff $WORK_DIR $CUR/conf/diff_config_optimistic.toml
check_sync_diff $WORK_DIR $CUR/conf/diff_config_pessimistic.toml

echo "check locks"
run_dmctl_with_retry $CUR_VER "show-ddl-locks" "no DDL lock exists" 1
Expand Down

0 comments on commit eaa57ca

Please sign in to comment.