Skip to content

Commit

Permalink
cherry pick pingcap#1548 to release-2.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
lance6716 authored and ti-srebot committed Mar 30, 2021
1 parent a6f917d commit c72b24d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 21 deletions.
19 changes: 2 additions & 17 deletions tests/sequence_sharding_optimistic/data/db1.increment.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 10 additions & 2 deletions tests/sequence_sharding_optimistic/data/db1.increment2.sql
Original file line number Diff line number Diff line change
@@ -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);

3 changes: 1 addition & 2 deletions tests/shardddl1/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
91 changes: 91 additions & 0 deletions tests/shardddl3/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c72b24d

Please sign in to comment.