diff --git a/dm/syncer/err-operator/operator.go b/dm/syncer/err-operator/operator.go index e99e57c4e44..5b5c2c1f89d 100644 --- a/dm/syncer/err-operator/operator.go +++ b/dm/syncer/err-operator/operator.go @@ -189,6 +189,14 @@ func (h *Holder) MatchAndApply(startLocation, endLocation binlog.Location, curre return false, pb.ErrorOp_InvalidErrorOp } + if operator.op == pb.ErrorOp_Inject { + // if last event's position already equals currentEvent, this is repeatedly match, need remove last event before recalculate + if last := operator.events[len(operator.events)-1]; last.Header.LogPos == currentEvent.Header.LogPos { + h.logger.Info("re-match and apply a inject operator", zap.Stringer("startlocation", startLocation), zap.Stringer("endlocation", endLocation), zap.Stringer("operator", operator)) + return true, operator.op + } + } + // set LogPos as start position for _, ev := range operator.events { ev.Header.LogPos = startLocation.Position.Pos diff --git a/dm/tests/handle_error/run.sh b/dm/tests/handle_error/run.sh index 7d9dc6855d7..00182ede2ca 100644 --- a/dm/tests/handle_error/run.sh +++ b/dm/tests/handle_error/run.sh @@ -495,87 +495,445 @@ function DM_CROSS_DDL_SHARDING_WITH_REPLACE_ERROR() { "clean_table" "optimistic" } -# replace add column unique # one source, one table, no sharding function DM_INJECT_DDL_ERROR_CASE() { run_sql_source1 "insert into ${db}.${tb1} values(1,1);" + run_sql_source2 "insert into ${db}.${tb2} values(1,1);" # error in TiDB run_sql_source1 "alter table ${db}.${tb1} add column c int default 100 unique not null;" run_sql_source1 "insert into ${db}.${tb1} values(2,2,2);" + run_sql_source2 "alter table ${db}.${tb2} add column c int default 100 unique not null;" + run_sql_source2 "insert into ${db}.${tb2} values(2,2,2);" run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ "query-status test" \ - "unsupported add column .* constraint UNIQUE KEY" 1 \ - "origin SQL: \[alter table ${db}.${tb1} add column c int default 100 unique not null\]" 1 + "unsupported add column .* constraint UNIQUE KEY" 2 # replace sql but there has a mistake which is use 'c' as pk run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "binlog replace test alter table ${db}.${tb1} add column c int default 100; alter table ${db}.${tb1} add primary key (c);" \ + "binlog replace test -s mysql-replica-01 alter table ${db}.${tb1} add column c int default 100; alter table ${db}.${tb1} add primary key (c);" \ + "\"result\": true" 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test -s mysql-replica-02 alter table ${db}.${tb2} add column c int default 100; alter table ${db}.${tb2} add primary key (c);" \ "\"result\": true" 2 # error in TiDB run_sql_source1 "alter table ${db}.${tb1} modify column c double;" run_sql_source1 "insert into ${db}.${tb1} values(3,3,3.5);" + run_sql_source2 "alter table ${db}.${tb2} modify column c double;" + run_sql_source2 "insert into ${db}.${tb2} values(3,3,3.5);" run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ "query-status test" \ - "Unsupported modify column: this column has primary key flag" 1 + "Unsupported modify column: this column has primary key flag" 2 + + # inject sqls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-01 alter table ${db}.${tb1} drop primary key; alter table ${db}.${tb1} add unique(c);" \ + "\"result\": true" 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-02 alter table ${db}.${tb2} drop primary key; alter table ${db}.${tb2} add unique(c);" \ + "\"result\": true" 2 + + run_sql_tidb_with_retry "select count(1) from ${db}.${tb1} where c = 3.5;" "count(1): 1" + run_sql_tidb_with_retry "select count(1) from ${db}.${tb2} where c = 3.5;" "count(1): 1" +} + +function DM_INJECT_DDL_ERROR_SHARDING_BASE_CASE() { + run_sql_source1 "alter table ${db}.${tb1} add column c int default 100 unique not null;" + run_sql_source2 "alter table ${db}.${tb1} add column c int default 100 unique not null;" + run_sql_source1 "insert into ${db}.${tb1} values(1,1,1);" + run_sql_source2 "insert into ${db}.${tb1} values(2,2,2);" + + # first ddl: unsupport error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "unsupported add column .* constraint UNIQUE KEY" 2 + + # begin to handle error + # replace first ddl into two ddls, but add c as pk + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test alter table ${db}.${tb1} add column c int default 100; alter table ${db}.${tb1} add primary key (c);" \ + "\"result\": true" 3 + + if [[ "$1" = "pessimistic" ]]; then + run_sql_source1 "alter table ${db}.${tb1} modify column c double;" + run_sql_source1 "insert into ${db}.${tb1} values(3,3,3.5);" + + run_sql_source2 "alter table ${db}.${tb1} modify column c double;" + run_sql_source2 "insert into ${db}.${tb1} values(4,4,4.5);" + + # second ddl: unsupport error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "Unsupported modify column: this column has primary key flag" 2 + + # inject into two ddls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test alter table ${db}.${tb1} drop primary key; alter table ${db}.${tb1} add unique(c);" \ + "\"result\": true" 3 + else + run_sql_source1 "alter table ${db}.${tb1} drop column c;" + run_sql_source1 "insert into ${db}.${tb1} values(3,3);" + + run_sql_source2 "alter table ${db}.${tb1} drop column c;" + run_sql_source2 "insert into ${db}.${tb1} values(4,4);" + + # second ddl: unsupport error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "can't drop column .* with composite index covered or Primary Key covered now" 2 + + # inject into two ddls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test alter table ${db}.${tb1} drop primary key;" \ + "\"result\": true" 3 + fi + + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "\"stage\": \"Running\"" 4 + + run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 4" +} + +# two source, 4 tables +function DM_INJECT_DDL_ERROR_SHARDING_BASE2_CASE() { + # 11/21 first ddl + run_sql_source1 "alter table ${db}.${tb1} add column c int default 100 unique not null;" + run_sql_source2 "alter table ${db}.${tb1} add column c int default 100 unique not null;" + run_sql_source1 "insert into ${db}.${tb1} values(1,1,1);" + run_sql_source2 "insert into ${db}.${tb1} values(2,2,2);" + + # 12/22 first ddl + run_sql_source1 "alter table ${db}.${tb2} add column c int default 100 unique not null;" + run_sql_source2 "alter table ${db}.${tb2} add column c int default 100 unique not null;" + run_sql_source1 "insert into ${db}.${tb2} values(4,4,4);" + run_sql_source2 "insert into ${db}.${tb2} values(5,5,5);" + + # 11/21 first ddl error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "unsupported add column .* constraint UNIQUE KEY" 2 + + # replace 11/21 first ddl + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test alter table ${db}.${tb1} add column c int default 100; alter table ${db}.${tb1} add primary key (c);" \ + "\"result\": true" 3 + + if [[ "$1" = "pessimistic" ]]; then + # 11/21 second ddl + run_sql_source1 "alter table ${db}.${tb1} modify column c double;" + run_sql_source2 "alter table ${db}.${tb1} modify column c double;" + run_sql_source1 "insert into ${db}.${tb1} values(3,3,3.5);" + run_sql_source2 "insert into ${db}.${tb1} values(6,6,6.6);" + + # 12/22 second ddl + run_sql_source1 "alter table ${db}.${tb2} modify column c double;" + run_sql_source2 "alter table ${db}.${tb2} modify column c double;" + run_sql_source1 "insert into ${db}.${tb2} values(7,7,7.7);" + run_sql_source2 "insert into ${db}.${tb2} values(8,8,8.8);" + + # 11/21 inject with 12/22 first ddl conflict + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "detect inconsistent DDL sequence from source" 2 + + # replace 12/22 first ddl into two ddls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test -s mysql-replica-01,mysql-replica-02 alter table ${db}.${tb2} add column c int default 100; alter table ${db}.${tb2} add primary key (c);" \ + "\"result\": true" 3 + + # 11/21 second ddl: unsupport error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "Unsupported modify column: this column has primary key flag" 2 + + # inject 11/21 second ddl + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test alter table ${db}.${tb1} drop primary key; alter table ${db}.${tb1} add unique(c);" \ + "\"result\": true" 3 + + # 11/21 inject ddl with 12/22 second ddl: detect conflict + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "detect inconsistent DDL sequence from source" 2 + + # inject 12/22 second ddl + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-01 alter table ${db}.${tb2} drop primary key; alter table ${db}.${tb2} add unique(c);" \ + "\"result\": true" 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-02 alter table ${db}.${tb2} drop primary key; alter table ${db}.${tb2} add unique(c);;" \ + "\"result\": true" 2 + else + # 11/21 second ddl + run_sql_source1 "alter table ${db}.${tb1} drop column c;" + run_sql_source2 "alter table ${db}.${tb1} drop column c;" + run_sql_source1 "insert into ${db}.${tb1} values(3,3);" + run_sql_source2 "insert into ${db}.${tb1} values(6,6);" + + # 12/22 second ddl + run_sql_source1 "alter table ${db}.${tb2} drop column c;" + run_sql_source2 "alter table ${db}.${tb2} drop column c;" + run_sql_source1 "insert into ${db}.${tb2} values(7,7);" + run_sql_source2 "insert into ${db}.${tb2} values(8,8);" + + # 12/22 first ddl error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "unsupported add column .* constraint UNIQUE KEY" 2 + + # replace 12/22 first ddl + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test alter table ${db}.${tb2} add column c int default 100; alter table ${db}.${tb2} add primary key (c);" \ + "\"result\": true" 3 + + # 11/21 second ddl error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "can't drop column .* with composite index covered or Primary Key covered now" 2 + + # inject 11/21 second ddl + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test alter table ${db}.${tb1} drop primary key;" \ + "\"result\": true" 3 + + # 12/22 second ddl error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "can't drop column .* with composite index covered or Primary Key covered now" 2 + + # inject 12/22 second ddl + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test alter table ${db}.${tb2} drop primary key;" \ + "\"result\": true" 3 + fi - # inject sql but length is 10 + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "\"stage\": \"Running\"" 4 + + run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 8" +} + +# two source, 4 tables, cross ddls +# source1: tb1 first ddl -> tb1 second ddl -> tb2 first ddl -> tb2 second ddl +# source2: tb1 first ddl -> tb1 second ddl -> tb2 first ddl -> tb2 second ddl +function DM_INJECT_DDL_ERROR_SHARDING_CROSS_CASE() { + # 11/21 first ddl + run_sql_source1 "alter table ${db}.${tb1} add column c int unique;" + run_sql_source2 "alter table ${db}.${tb1} add column c int unique;" + run_sql_source1 "insert into ${db}.${tb1} values(1,1,1);" + run_sql_source2 "insert into ${db}.${tb1} values(2,2,2);" + + # 11/21 first ddl: unsupport error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "unsupported add column .* constraint UNIQUE KEY" 2 + + # 11/21 second ddl + run_sql_source1 "alter table ${db}.${tb1} modify column c double;" + run_sql_source2 "alter table ${db}.${tb1} modify column c double;" + run_sql_source1 "insert into ${db}.${tb1} values(3,3,3.5);" + run_sql_source2 "insert into ${db}.${tb1} values(6,6,6.6);" + + # 12/22 first ddl + run_sql_source1 "alter table ${db}.${tb2} add column c int unique;" + run_sql_source2 "alter table ${db}.${tb2} add column c int unique;" + run_sql_source1 "insert into ${db}.${tb2} values(4,4,4);" + run_sql_source2 "insert into ${db}.${tb2} values(5,5,5);" + + # 12/22 second ddl + run_sql_source1 "alter table ${db}.${tb2} modify column c double;" + run_sql_source2 "alter table ${db}.${tb2} modify column c double;" + run_sql_source1 "insert into ${db}.${tb2} values(7,7,7.7);" + run_sql_source2 "insert into ${db}.${tb2} values(8,8,8.8);" + + # begin to handle error + # split 11/21 first ddl into two ddls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test alter table ${db}.${tb1} add column c int; alter table ${db}.${tb1} add primary key (c);" \ + "\"result\": true" 3 + + # 12/22 first ddl with 11/21 inject replace ddl conflict + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "detect inconsistent DDL sequence from source" 2 + + # split 12,22 first ddl into two ddls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test -s mysql-replica-01,mysql-replica-02 alter table ${db}.${tb2} add column c int; alter table ${db}.${tb2} add primary key (c);" \ + "\"result\": true" 3 + + # 11/21 second ddl: unsupport error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "Unsupported modify column: this column has primary key flag" 2 + + # inject 11/21 second ddl into two ddls run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ "binlog inject test alter table ${db}.${tb1} drop primary key; alter table ${db}.${tb1} add unique(c);" \ + "\"result\": true" 3 + + # 12/22 second ddl with 11/21 inject ddl conflict + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "detect inconsistent DDL sequence from source" 2 + + # inject 12/22 second ddl into two ddls + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-01 alter table ${db}.${tb2} drop primary key; alter table ${db}.${tb2} add unique(c);" \ "\"result\": true" 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-02 alter table ${db}.${tb2} drop primary key; alter table ${db}.${tb2} add unique(c);;" \ + "\"result\": true" 2 + + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "\"stage\": \"Running\"" 4 - run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where c = 3.5;" "count(1): 1" + run_sql_tidb_with_retry "select count(1) from ${db}.${tb}" "count(1): 8" +} + +# test inject fail on second ddl +# two sources, two tables +function DM_INJECT_ERROR_MULTIPLE_CASE() { + run_sql_source1 "alter table ${db}.${tb1} add primary key (id);" + run_sql_source2 "alter table ${db}.${tb1} add primary key (id);" + run_sql_source1 "alter table ${db}.${tb1} drop column id;" + run_sql_source2 "alter table ${db}.${tb1} drop column id;" + run_sql_source1 "insert into ${db}.${tb1} values(1,1);" + run_sql_source2 "insert into ${db}.${tb1} values(2,2);" + + # 11, 21 unspported error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "can't drop column id with composite index covered or Primary Key covered now" 2 + + # inject and have an error + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test \"alter table ${db}.${tb1} add unique(b); alter table ${db}.${tb1} add primary key (a);\"" \ + "\"result\": true" 3 + + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "Multiple primary key defined" 2 + + # revert + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog revert test" \ + "\"result\": true" 3 + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "can't drop column id with composite index covered or Primary Key covered now" 2 + + # drop pk + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test \"alter table ${db}.${tb1} drop primary key;\"" \ + "\"result\": true" 3 + + run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "query-status test" \ + "\"stage\": \"Running\"" 4 + + run_sql_tidb_with_retry "select count(1) from ${db}.${tb};" "count(1): 2" +} + +function DM_INJECT_DDL_ERROR() { + run_case INJECT_DDL_ERROR "double-source-no-sharding" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb2} (a int unique, b int);\"" \ + "clean_table" "" + + run_case INJECT_DDL_ERROR_SHARDING_BASE "double-source-pessimistic" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb1} (a int unique, b int);\"" \ + "clean_table" "pessimistic" + run_case INJECT_DDL_ERROR_SHARDING_BASE "double-source-optimistic" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb1} (a int unique, b int);\"" \ + "clean_table" "optimistic" + + run_case INJECT_DDL_ERROR_SHARDING_BASE2 "double-source-pessimistic" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source1 \"create table ${db}.${tb2} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb2} (a int unique, b int);\"" \ + "clean_table" "pessimistic" + run_case INJECT_DDL_ERROR_SHARDING_BASE2 "double-source-optimistic" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source1 \"create table ${db}.${tb2} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb2} (a int unique, b int);\"" \ + "clean_table" "optimistic" + + run_case INJECT_DDL_ERROR_SHARDING_CROSS "double-source-pessimistic" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source1 \"create table ${db}.${tb2} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb1} (a int unique, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb2} (a int unique, b int);\"" \ + "clean_table" "" + + run_case INJECT_ERROR_MULTIPLE "double-source-pessimistic" \ + "run_sql_source1 \"create table ${db}.${tb1} (id int unique, a int, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb1} (id int unique, a int, b int);\"" \ + "clean_table" "" } -# inject dml can not run, because get position is invalid. function DM_INJECT_DML_ERROR_CASE() { run_sql_source1 "insert into ${db}.${tb1} values(1,1);" + run_sql_source2 "insert into ${db}.${tb2} values(1,1);" # error in TiDB run_sql_source1 "alter table ${db}.${tb1} add column c varchar(10) unique;" run_sql_source1 "insert into ${db}.${tb1} values(2,2,'22');" + run_sql_source2 "alter table ${db}.${tb2} add column c varchar(10) unique;" + run_sql_source2 "insert into ${db}.${tb2} values(2,2,'22');" run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ "query-status test" \ - "unsupported add column .* constraint UNIQUE KEY" 1 \ - "origin SQL: \[alter table ${db}.${tb1} add column c varchar(10) unique\]" 1 + "unsupported add column .* constraint UNIQUE KEY" 2 # replace sql but there has a mistake which is add unque to column 'b' run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "binlog replace test alter table ${db}.${tb1} add column c varchar(10); alter table ${db}.${tb1} add unique (b);" \ + "binlog replace test -s mysql-replica-01 alter table ${db}.${tb1} add column c varchar(10); alter table ${db}.${tb1} add unique (b);" \ + "\"result\": true" 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog replace test -s mysql-replica-02 alter table ${db}.${tb2} add column c varchar(10); alter table ${db}.${tb2} add unique (b);" \ "\"result\": true" 2 - # error in TiDB - run_sql_source1 "insert into ${db}.${tb1} values(3,2,'33');" + # error in TiDB, the second dml will be error + run_sql_source1 "start transaction;insert into ${db}.${tb1} values(3,3,'33');insert into ${db}.${tb1} values(4,2,'44');insert into ${db}.${tb1} values(5,2,'55');commit;" + run_sql_source2 "start transaction;insert into ${db}.${tb2} values(3,3,'33');insert into ${db}.${tb2} values(4,2,'44');insert into ${db}.${tb2} values(5,2,'55');commit;" run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ "query-status test" \ - "Duplicate entry '2' for key 'b'" 1 + "Duplicate entry '2' for key 'b'" 4 - # inject sql but length is 10 + # inject sqls run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "binlog inject test alter table ${db}.${tb1} drop index b;alter table ${db}.${tb1} add unique(c);" \ + "binlog inject test -s mysql-replica-01 alter table ${db}.${tb1} drop index b;alter table ${db}.${tb1} add unique(c);" \ + "\"result\": true" 2 + run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ + "binlog inject test -s mysql-replica-02 alter table ${db}.${tb2} drop index b;alter table ${db}.${tb2} add unique(c);" \ "\"result\": true" 2 - run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where b = 2;" "count(1): 2" + run_sql_tidb_with_retry "select count(1) from ${db}.${tb1} where b = 2;" "count(1): 3" + run_sql_tidb_with_retry "select count(1) from ${db}.${tb2} where b = 2;" "count(1): 3" } -function DM_INJECT_ERROR() { - # inject at ddl - run_case INJECT_DDL_ERROR "single-source-no-sharding" \ - "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"" \ - "clean_table" "" - # inject at dml - run_case INJECT_DML_ERROR "single-source-no-sharding" \ - "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b varchar(10));\"" \ +# TODO inject at dml will support at other pr +function DM_INJECT_DML_ERROR() { + run_case INJECT_DML_ERROR "double-source-no-sharding" \ + "run_sql_source1 \"create table ${db}.${tb1} (a int primary key, b int);\"; \ + run_sql_source2 \"create table ${db}.${tb2} (a int primary key, b int);\"" \ "clean_table" "" } function DM_LIST_ERROR_CASE() { - run_sql_source1 "insert into ${db}.${tb1} values(1,1);" + run_sql_source1 "insert into ${db}.${tb1} values(1, 1);" run_sql_source1 "alter table ${db}.${tb1} add column c int default 100; alter table ${db}.${tb1} add primary key (c)" run_sql_source1 "alter table ${db}.${tb1} modify c varchar(10);" run_sql_source1 "alter table ${db}.${tb1} modify c varchar(20);" @@ -586,7 +944,7 @@ function DM_LIST_ERROR_CASE() { "Unsupported modify column: this column has primary key flag" 1 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ - "binlog test" \ + "binlog list test" \ "\"msg\": \"\[\]\"" 1 first_pos1=$(get_start_pos 127.0.0.1:$MASTER_PORT $source1) @@ -622,13 +980,13 @@ function DM_LIST_ERROR_CASE() { "binlog skip test" \ "\"result\": true" 2 - run_sql_source1 "insert into ${db}.${tb1} values(1,1,2.2);" + run_sql_source1 "insert into ${db}.${tb1} values(2,1,2.2);" run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where c = 2.2;" "count(1): 1" } function DM_LIST_ERROR() { - run_case INJECT_DDL_ERROR "single-source-no-sharding" \ + run_case LIST_ERROR "single-source-no-sharding" \ "run_sql_source1 \"create table ${db}.${tb1} (a int unique, b int);\"" \ "clean_table" "" } @@ -1070,7 +1428,9 @@ function run() { init_cluster init_database - DM_INJECT_ERROR + DM_INJECT_DDL_ERROR + # TODO inject at dml will support at other pr + # DM_INJECT_DML_ERROR DM_LIST_ERROR DM_SKIP_ERROR DM_SKIP_ERROR_SHARDING