From c72b24dc66f017c19e2bd6c300363db8effb10a9 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Tue, 30 Mar 2021 17:07:24 +0800 Subject: [PATCH] cherry pick #1548 to release-2.0 Signed-off-by: ti-srebot --- .../data/db1.increment.sql | 19 +--- .../data/db1.increment2.sql | 12 ++- tests/shardddl1/run.sh | 3 +- tests/shardddl3/run.sh | 91 +++++++++++++++++++ 4 files changed, 104 insertions(+), 21 deletions(-) diff --git a/tests/sequence_sharding_optimistic/data/db1.increment.sql b/tests/sequence_sharding_optimistic/data/db1.increment.sql index 4476682c10..dfea7e602b 100644 --- a/tests/sequence_sharding_optimistic/data/db1.increment.sql +++ b/tests/sequence_sharding_optimistic/data/db1.increment.sql @@ -27,24 +27,9 @@ alter table t2 drop column c1; insert into t1 (id, c2) values (100006, '120006'); insert into t2 (id, c2, c3) values (200006, '220006', 230006); -alter table t2 add column c1 varchar(20); --- at this point: --- t1(id, c2) --- t2(id, c1, c2, c3) -insert into t2 (id, c1, c2, c3) values (200007, '210007', '220007', 230007); -insert into t1 (id, c2) values (100007, '120007'); - -alter table t2 drop column c1; --- at this point: --- t1(id, c2) --- t2(id, c2, c3) -insert into t1 (id, c2) values (100008, '120008'); -insert into t2 (id, c2, c3) values (200008, '220008', 230008); - alter table t1 add column c3 int; -- at this point: -- t1(id, c2, c3) -- t2(id, c2, c3) -insert into t2 (id, c2, c3) values (200009, '220009', 230009); -insert into t1 (id, c2, c3) values (100009, '120009', 130009); - +insert into t2 (id, c2, c3) values (200007, '220007', 230007); +insert into t1 (id, c2, c3) values (100007, '120007', 130007); diff --git a/tests/sequence_sharding_optimistic/data/db1.increment2.sql b/tests/sequence_sharding_optimistic/data/db1.increment2.sql index f4d881f3c9..f289b3185d 100644 --- a/tests/sequence_sharding_optimistic/data/db1.increment2.sql +++ b/tests/sequence_sharding_optimistic/data/db1.increment2.sql @@ -1,8 +1,16 @@ use `sharding_seq_opt`; +alter table t2 add column c1 varchar(20); +-- at this point: +-- t1(id, c2, c3) +-- t2(id, c1, c2, c3) +insert into t2 (id, c1, c2, c3) values (200008, '210008', '220008', 230008); +insert into t1 (id, c2, c3) values (100008, '120008', 130008); + +alter table t2 drop column c1; -- at this point: -- t1(id, c2, c3) -- t2(id, c2, c3) -insert into t1 (id, c2, c3) values (100010, '120010', 130010); -insert into t2 (id, c2, c3) values (200010, '220010', 230010); +insert into t1 (id, c2, c3) values (100009, '120009', 130009); +insert into t2 (id, c2, c3) values (200009, '220009', 230009); diff --git a/tests/shardddl1/run.sh b/tests/shardddl1/run.sh index b306aec8fc..281fa5586a 100644 --- a/tests/shardddl1/run.sh +++ b/tests/shardddl1/run.sh @@ -535,8 +535,7 @@ function DM_RENAME_COLUMN_OPTIMISTIC_CASE() { "\"result\": true" 2 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "resume-task test -s mysql-replica-02" \ - "\"result\": true" 2 + "resume-task test -s mysql-replica-02" # source2.table2's ddl fails # Unknown column 'a' in 'tb2' diff --git a/tests/shardddl3/run.sh b/tests/shardddl3/run.sh index 8e23e39325..5d6f3f97b7 100644 --- a/tests/shardddl3/run.sh +++ b/tests/shardddl3/run.sh @@ -995,6 +995,97 @@ function DM_RestartMaster() { "clean_table" "optimistic" } +<<<<<<< HEAD +======= +function restart_master_on_pos() { + if [ "$1" = "$2" ]; then + restart_master + fi +} + +function DM_DropAddColumn_CASE() { + reset=$2 + + run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" + run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" + + check_sync_diff $WORK_DIR $cur/conf/diff_config.toml + + run_sql_source1 "alter table ${shardddl1}.${tb1} drop column c;" + run_sql_source1 "insert into ${shardddl1}.${tb1} values(3,3);" + + restart_master_on_pos $reset "1" + + run_sql_source1 "alter table ${shardddl1}.${tb1} drop column b;" + run_sql_source1 "insert into ${shardddl1}.${tb1} values(4);" + + restart_master_on_pos $reset "2" + + run_sql_source2 "alter table ${shardddl1}.${tb1} drop column c;" + run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);" + + restart_master_on_pos $reset "3" + + # make sure column c is fully dropped in the downstream + check_log_contain_with_retry 'finish to handle ddls in optimistic shard mode' $WORK_DIR/worker1/log/dm-worker.log + check_log_contain_with_retry 'finish to handle ddls in optimistic shard mode' $WORK_DIR/worker2/log/dm-worker.log + + run_sql_source1 "alter table ${shardddl1}.${tb1} add column c int;" + run_sql_source1 "insert into ${shardddl1}.${tb1} values(6,6);" + + restart_master_on_pos $reset "4" + + # make sure task to step in "Sync" stage + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "\"stage\": \"Running\"" 3 \ + "\"unit\": \"Sync\"" 2 + + run_sql_source1 "alter table ${shardddl1}.${tb1} add column b int after a;" + + restart_master_on_pos $reset "5" + + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "because schema conflict detected" 1 \ + "add column b that wasn't fully dropped in downstream" 1 + + check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 3 'fail' + + # try to fix data + echo 'CREATE TABLE `tb1` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin' > ${WORK_DIR}/schema.sql + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "operate-schema set test ${WORK_DIR}/schema.sql -s mysql-replica-01 -d ${shardddl1} -t ${tb1}" \ + "\"result\": true" 2 + + # skip this error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "handle-error test skip" \ + "\"result\": true" 2 \ + "\"source 'mysql-replica-02' has no error\"" 1 + + run_sql_source1 "update ${shardddl1}.${tb1} set b=1 where a=1;" + run_sql_source1 "update ${shardddl1}.${tb1} set b=3 where a=3;" + run_sql_source1 "update ${shardddl1}.${tb1} set b=4 where a=4;" + run_sql_source1 "update ${shardddl1}.${tb1} set b=6 where a=6;" + run_sql_source2 "alter table ${shardddl1}.${tb1} add column c int" + run_sql_source2 "insert into ${shardddl1}.${tb1} values(7,7,7);" + + check_sync_diff $WORK_DIR $cur/conf/diff_config.toml +} + +function DM_DropAddColumn() { + for i in `seq 0 5` + do + echo "run DM_DropAddColumn case #${i}" + run_case DropAddColumn "double-source-optimistic" \ + "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int, c int);\"; \ + run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int, c int);\"" \ + "clean_table" "optimistic" "$i" + done +} + +>>>>>>> 8cd3e8a4... test: fix unstabled drop then add column (#1548) function run() { init_cluster init_database