github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/shardddl4/run.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 cur=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 6 source $cur/../_utils/test_prepare 7 WORK_DIR=$TEST_DIR/$TEST_NAME 8 source $cur/../_utils/shardddl_lib.sh 9 10 function DM_119_CASE { 11 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1,1);" 12 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2,2);" 13 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3,3);" 14 15 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx(c1,c2);" 16 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4,4);" 17 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5,5);" 18 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6,6);" 19 20 run_sql_source2 "alter table ${shardddl1}.${tb1} add index idx(c1,c3);" 21 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7,7);" 22 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8,8);" 23 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9,9);" 24 25 # FIXME: DM should detect conflicts and give human readable error messages. 26 # For example: 27 # if [[ "$1" = "pessimistic" ]]; then 28 # check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log 29 # else 30 # run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 31 # "query-status test" \ 32 # "because schema conflict detected" 1 33 # fi 34 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 10 "fail" 35 } 36 37 # Add index with the same name but with different fields. 38 function DM_119 { 39 run_case 119 "double-source-pessimistic" \ 40 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int);\"; \ 41 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int);\"; \ 42 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, c3 int);\"" \ 43 "clean_table" "pessimistic" 44 run_case 119 "double-source-optimistic" \ 45 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int);\"; \ 46 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int);\"; \ 47 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, c3 int);\"" \ 48 "clean_table" "optimistic" 49 } 50 51 function DM_120_CASE { 52 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 53 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" 54 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3);" 55 56 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx1(c1), add index idx2(c2);" 57 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 58 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 59 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6);" 60 61 run_sql_source2 "alter table ${shardddl1}.${tb1} add index idx1(c1), add index idx2(c2);" 62 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 63 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 64 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 65 66 run_sql_source2 "alter table ${shardddl1}.${tb2} add index idx1(c1), add index idx2(c2);" 67 run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,10,10);" 68 run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,11,11);" 69 run_sql_source2 "insert into ${shardddl1}.${tb2} values(12,12,12);" 70 71 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 72 } 73 74 # Add multiple indexes to a single table. 75 function DM_120 { 76 run_case 120 "double-source-pessimistic" \ 77 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 78 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 79 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int);\"" \ 80 "clean_table" "pessimistic" 81 run_case 120 "double-source-optimistic" \ 82 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 83 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 84 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int);\"" \ 85 "clean_table" "optimistic" 86 } 87 88 function DM_121_CASE { 89 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 90 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" 91 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3);" 92 93 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx(c1);" 94 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 95 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 96 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6);" 97 98 run_sql_source2 "alter table ${shardddl1}.${tb1} add index idx(c1,c2);" 99 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 100 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 101 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 102 103 # FIXME: DM should detect conflicts and give human readable error messages. 104 # For example: 105 # if [[ "$1" = "pessimistic" ]]; then 106 # check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log 107 # else 108 # run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 109 # "query-status test" \ 110 # "because schema conflict detected" 1 111 # fi 112 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 10 "fail" 113 } 114 115 # Add index with the same name but with different fields. 116 function DM_121 { 117 run_case 121 "double-source-pessimistic" \ 118 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 119 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 120 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int);\"" \ 121 "clean_table" "pessimistic" 122 run_case 121 "double-source-optimistic" \ 123 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 124 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 125 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int);\"" \ 126 "clean_table" "optimistic" 127 } 128 129 function DM_122_CASE { 130 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 131 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" 132 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3);" 133 134 run_sql_source1 "alter table ${shardddl1}.${tb1} drop index idx1, drop index idx2;" 135 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 136 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 137 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6);" 138 139 run_sql_source2 "alter table ${shardddl1}.${tb1} drop index idx1, drop index idx2;" 140 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 141 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 142 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 143 144 run_sql_source2 "alter table ${shardddl1}.${tb2} drop index idx1, drop index idx2;" 145 run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,10,10);" 146 run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,11,11);" 147 run_sql_source2 "insert into ${shardddl1}.${tb2} values(12,12,12);" 148 149 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 150 } 151 152 # Drop multiple indexes from a single table. 153 function DM_122 { 154 run_case 122 "double-source-pessimistic" \ 155 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 156 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 157 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"" \ 158 "clean_table" "pessimistic" 159 run_case 122 "double-source-optimistic" \ 160 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 161 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 162 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"" \ 163 "clean_table" "optimistic" 164 } 165 166 function DM_123_CASE { 167 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1,1,1);" 168 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2,2,2);" 169 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3,3,3);" 170 171 run_sql_source1 "alter table ${shardddl1}.${tb1} drop index idx1, add index idx1(c2,c1), drop index idx2, add index idx2(c4,c3);" 172 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4,4,4);" 173 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5,5,5);" 174 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6,6,6);" 175 176 run_sql_source2 "alter table ${shardddl1}.${tb1} drop index idx1, add index idx1(c2,c1), drop index idx2, add index idx2(c4,c3);" 177 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7,7,7);" 178 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8,8,8);" 179 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9,9,9);" 180 181 run_sql_source2 "alter table ${shardddl1}.${tb2} drop index idx1, add index idx1(c2,c1), drop index idx2, add index idx2(c4,c3);" 182 run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,10,10,10,10);" 183 run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,11,11,11,11);" 184 run_sql_source2 "insert into ${shardddl1}.${tb2} values(12,12,12,12,12);" 185 186 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 187 } 188 189 # Adjust multiple indexes combination. 190 function DM_123 { 191 run_case 123 "double-source-pessimistic" \ 192 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 193 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 194 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"" \ 195 "clean_table" "pessimistic" 196 run_case 123 "double-source-optimistic" \ 197 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 198 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 199 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"" \ 200 "clean_table" "optimistic" 201 } 202 203 function DM_124_CASE { 204 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 205 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" 206 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3);" 207 208 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx1(c1), add index idx2(c2);" 209 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 210 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 211 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6);" 212 213 run_sql_source1 "alter table ${shardddl1}.${tb1} drop index idx1, drop index idx2;" 214 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 215 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 216 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 217 218 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 219 } 220 221 # Add multiple indexes and then rollback. 222 function DM_124 { 223 # run_case 124 "double-source-pessimistic" \ 224 # "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 225 # run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 226 # run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int);\"" \ 227 # "clean_table" "pessimistic" 228 run_case 124 "double-source-optimistic" \ 229 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 230 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int);\"; \ 231 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int);\"" \ 232 "clean_table" "optimistic" 233 } 234 235 function DM_125_CASE { 236 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 237 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" 238 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3);" 239 240 run_sql_source1 "alter table ${shardddl1}.${tb1} drop index idx1, drop index idx2;" 241 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 242 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 243 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6);" 244 245 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx1(c1), add index idx2(c2);" 246 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 247 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 248 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 249 250 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 251 # FIXME: dm-master should remove this lock after all shards are synced. 252 run_dm_ctl_with_rematch $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 253 "shard-ddl-lock" \ 254 "\"unsynced\": \[[\n ]*\]" 1 255 } 256 257 # Drop multiple indexes and then rollback. 258 function DM_125 { 259 # run_case 125 "double-source-pessimistic" \ 260 # "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 261 # run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 262 # run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"" \ 263 # "clean_table" "pessimistic" 264 run_case 125 "double-source-optimistic" \ 265 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 266 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"; \ 267 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, index idx1(c1), index idx2(c2));\"" \ 268 "clean_table" "optimistic" 269 } 270 271 function DM_126_CASE { 272 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1,1,1);" 273 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2,2,2);" 274 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3,3,3);" 275 276 run_sql_source1 "alter table ${shardddl1}.${tb1} drop index idx1, add index idx1(c2,c1), drop index idx2, add index idx2(c4,c3);" 277 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4,4,4);" 278 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5,5,5);" 279 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6,6,6);" 280 281 run_sql_source1 "alter table ${shardddl1}.${tb1} drop index idx1, add index idx1(c1,c2), drop index idx2, add index idx2(c3,c4);" 282 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7,7,7);" 283 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8,8,8);" 284 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9,9,9);" 285 286 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 287 # FIXME: dm-master should remove this lock after all shards are synced. 288 run_dm_ctl_with_rematch $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 289 "shard-ddl-lock" \ 290 "\"unsynced\": \[[\n ]*\]" 1 291 } 292 293 # Ajust multiple indexes combination and then rollback. 294 function DM_126 { 295 # run_case 126 "double-source-pessimistic" \ 296 # "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 297 # run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 298 # run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"" \ 299 # "clean_table" "pessimistic" 300 run_case 126 "double-source-optimistic" \ 301 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 302 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"; \ 303 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, c3 int, c4 int, index idx1(c1, c2), index idx2(c3, c4));\"" \ 304 "clean_table" "optimistic" 305 } 306 307 function DM_127_CASE { 308 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1,1);" 309 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2,2);" 310 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3,3);" 311 312 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx2(c2), drop index idx1;" 313 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4,4);" 314 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5,5);" 315 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6,6);" 316 317 run_sql_source1 "alter table ${shardddl1}.${tb1} add index idx1(c1), drop index idx2;" 318 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7,7);" 319 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8,8);" 320 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9,9);" 321 322 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 323 # FIXME: dm-master should remove this lock after all shards are synced. 324 run_dm_ctl_with_rematch $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 325 "shard-ddl-lock" \ 326 "\"unsynced\": \[[\n ]*\]" 1 327 } 328 329 # Add and drop index at the same time and then rollback. 330 function DM_127 { 331 # run_case 127 "double-source-pessimistic" \ 332 # "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1));\"; \ 333 # run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1));\"; \ 334 # run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, index idx1(c1));\"" \ 335 # "clean_table" "pessimistic" 336 run_case 127 "double-source-optimistic" \ 337 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1));\"; \ 338 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, c1 int, c2 int, index idx1(c1));\"; \ 339 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, c1 int, c2 int, index idx1(c1));\"" \ 340 "clean_table" "optimistic" 341 } 342 343 function DM_128_CASE() { 344 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 345 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2);" 346 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3);" 347 348 run_sql_source1 "alter table ${shardddl1}.${tb1} modify b int not null;" 349 run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4);" 350 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);" 351 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6);" 352 353 run_sql_source2 "alter table ${shardddl1}.${tb1} modify b int not null;" 354 run_sql_source1 "insert into ${shardddl1}.${tb1} values(7,7);" 355 run_sql_source2 "insert into ${shardddl1}.${tb1} values(8,8);" 356 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9);" 357 358 run_sql_source2 "alter table ${shardddl1}.${tb2} modify b int not null;" 359 run_sql_source1 "insert into ${shardddl1}.${tb1} values(10,10);" 360 run_sql_source2 "insert into ${shardddl1}.${tb1} values(11,11);" 361 run_sql_source2 "insert into ${shardddl1}.${tb2} values(12,12);" 362 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 363 } 364 365 # Change NULL to NOT NULL. 366 function DM_128() { 367 run_case 128 "double-source-pessimistic" \ 368 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 369 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 370 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \ 371 "clean_table" "pessimistic" 372 run_case 128 "double-source-optimistic" \ 373 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 374 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int);\"; \ 375 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int);\"" \ 376 "clean_table" "optimistic" 377 } 378 379 function DM_129_CASE() { 380 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 381 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2);" 382 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3);" 383 384 run_sql_source1 "alter table ${shardddl1}.${tb1} modify b int default 10;" 385 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(4);" 386 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);" 387 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6);" 388 389 run_sql_source2 "alter table ${shardddl1}.${tb1} modify b int default 10;" 390 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(7);" 391 run_sql_source2 "insert into ${shardddl1}.${tb1}(a) values(8);" 392 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9);" 393 394 run_sql_source2 "alter table ${shardddl1}.${tb2} modify b int default 10;" 395 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(10);" 396 run_sql_source2 "insert into ${shardddl1}.${tb1}(a) values(11);" 397 run_sql_source2 "insert into ${shardddl1}.${tb2}(a) values(12);" 398 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 399 } 400 401 # Change NOT NULL to NULL with the same default value. 402 function DM_129() { 403 run_case 129 "double-source-pessimistic" \ 404 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 405 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 406 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int not null);\"" \ 407 "clean_table" "pessimistic" 408 run_case 129 "double-source-optimistic" \ 409 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 410 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 411 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int not null);\"" \ 412 "clean_table" "optimistic" 413 } 414 415 function DM_130_CASE() { 416 run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,1);" 417 run_sql_source2 "insert into ${shardddl1}.${tb1} values(2,2);" 418 run_sql_source2 "insert into ${shardddl1}.${tb2} values(3,3);" 419 420 run_sql_source1 "alter table ${shardddl1}.${tb1} modify b int default 0;" 421 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(4);" 422 run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);" 423 run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6);" 424 425 if [[ "$1" = "optimistic" ]]; then 426 check_log_contain_with_retry "finish to handle ddls in optimistic shard mode.*alter table ${shardddl1}.${tb1} modify b int default 0" \ 427 $WORK_DIR/worker1/log/dm-worker.log $WORK_DIR/worker2/log/dm-worker.log 428 fi 429 430 run_sql_source2 "alter table ${shardddl1}.${tb1} modify b int default -1;" 431 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(7);" 432 run_sql_source2 "insert into ${shardddl1}.${tb1}(a) values(8);" 433 run_sql_source2 "insert into ${shardddl1}.${tb2} values(9,9);" 434 435 run_sql_source2 "alter table ${shardddl1}.${tb2} modify b int default -1;" 436 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(10);" 437 run_sql_source2 "insert into ${shardddl1}.${tb1}(a) values(11);" 438 run_sql_source2 "insert into ${shardddl1}.${tb2}(a) values(12);" 439 if [[ "$1" = "pessimistic" ]]; then 440 check_log_contain_with_retry "is different with" $WORK_DIR/master/log/dm-master.log 441 else 442 # skip first ddl 443 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 444 "query-status test" \ 445 "blockingDDLs" 2 \ 446 "ALTER TABLE \`${shardddl}\`.\`${tb}\` MODIFY COLUMN \`b\` INT DEFAULT -1" 1 \ 447 "blockDDLOwner" 2 \ 448 "\"${SOURCE_ID2}-\`${shardddl1}\`.\`${tb1}\`\"" 1 449 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 450 "shard-ddl-lock unlock test-\`${shardddl}\`.\`${tb}\` -s ${SOURCE_ID2} -d ${shardddl1} -t ${tb1} --action skip" \ 451 "\"result\": true" 1 452 # skip second ddl 453 run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 454 "query-status test" \ 455 "blockingDDLs" 2 \ 456 "ALTER TABLE \`${shardddl}\`.\`${tb}\` MODIFY COLUMN \`b\` INT DEFAULT -1" 1 \ 457 "blockDDLOwner" 2 \ 458 "\"${SOURCE_ID2}-\`${shardddl1}\`.\`${tb2}\`\"" 1 459 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 460 "shard-ddl-lock unlock test-\`${shardddl}\`.\`${tb}\` -s ${SOURCE_ID2} -d ${shardddl1} -t ${tb2} --action skip" \ 461 "\"result\": true" 1 462 # check whether both locks are unlocked 463 run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ 464 "query-status test" \ 465 "\"result\": true" 3 \ 466 "\"blockDDLOwner\": \"\"" 2 467 run_sql_source1 "insert into ${shardddl1}.${tb1}(a) values(13);" 468 run_sql_source2 "insert into ${shardddl1}.${tb1}(a) values(14);" 469 run_sql_source2 "insert into ${shardddl1}.${tb2}(a) values(15);" 470 check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 471 fi 472 } 473 474 # Change NOT NULL to NULL with the different default value. 475 function DM_130() { 476 run_case 130 "double-source-pessimistic" \ 477 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 478 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 479 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int not null);\"" \ 480 "clean_table" "pessimistic" 481 run_case 130 "double-source-optimistic" \ 482 "run_sql_source1 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 483 run_sql_source2 \"create table ${shardddl1}.${tb1} (a int primary key, b int not null);\"; \ 484 run_sql_source2 \"create table ${shardddl1}.${tb2} (a int primary key, b int not null);\"" \ 485 "clean_table" "optimistic" 486 } 487 488 function run() { 489 init_cluster 490 init_database 491 start=119 492 end=130 493 for i in $(seq -f "%03g" ${start} ${end}); do 494 DM_${i} 495 sleep 1 496 done 497 } 498 499 cleanup_data $shardddl 500 cleanup_data $shardddl1 501 cleanup_data $shardddl2 502 # also cleanup dm processes in case of last run failed 503 cleanup_process $* 504 run $* 505 cleanup_process $* 506 507 echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"