github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/consistent_replicate_ddl/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=$OUT_DIR/$TEST_NAME 8 CDC_BINARY=cdc.test 9 SINK_TYPE=$1 10 11 rm -rf "$WORK_DIR" 12 mkdir -p "$WORK_DIR" 13 14 stop() { 15 # to distinguish whether the test failed in the DML synchronization phase or the DDL synchronization phase 16 echo $(mysql -h${DOWN_TIDB_HOST} -P${DOWN_TIDB_PORT} -uroot -e "SELECT count(*) FROM consistent_replicate_ddl.usertable;") 17 stop_tidb_cluster 18 } 19 20 function run() { 21 # we only support eventually consistent replication with MySQL sink 22 if [ "$SINK_TYPE" != "mysql" ]; then 23 return 24 fi 25 26 start_tidb_cluster --workdir $WORK_DIR 27 28 cd $WORK_DIR 29 run_sql "set @@global.tidb_enable_exchange_partition=on" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 30 31 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix consistent_replicate_ddl.server1 32 33 SINK_URI="mysql://normal:123456@127.0.0.1:3306/" 34 changefeed_id=$(cdc cli changefeed create --sink-uri="$SINK_URI" --config="$CUR/conf/changefeed.toml" 2>&1 | tail -n2 | head -n1 | awk '{print $2}') 35 36 run_sql "CREATE DATABASE consistent_replicate_ddl CHARACTER SET utf8 COLLATE utf8_unicode_ci" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 37 go-ycsb load mysql -P $CUR/conf/workload -p mysql.host=${UP_TIDB_HOST} -p mysql.port=${UP_TIDB_PORT} -p mysql.user=root -p mysql.db=consistent_replicate_ddl 38 run_sql "CREATE TABLE consistent_replicate_ddl.usertable1 like consistent_replicate_ddl.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 39 run_sql "CREATE TABLE consistent_replicate_ddl.usertable2 like consistent_replicate_ddl.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 40 run_sql "CREATE TABLE consistent_replicate_ddl.usertable3 like consistent_replicate_ddl.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 41 run_sql "CREATE TABLE consistent_replicate_ddl.usertable_bak like consistent_replicate_ddl.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 42 check_table_exists "consistent_replicate_ddl.usertable1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 43 check_table_exists "consistent_replicate_ddl.usertable2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 120 44 check_table_exists "consistent_replicate_ddl.usertable3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 120 45 check_table_exists "consistent_replicate_ddl.usertable_bak" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 120 46 sleep 5 47 cleanup_process $CDC_BINARY 48 # Inject the failpoint to prevent sink execution, but the global resolved can be moved forward. 49 # Then we can apply redo log to reach an eventual consistent state in downstream. 50 export GO_FAILPOINTS='github.com/pingcap/tiflow/cdc/sink/dmlsink/txn/mysql/MySQLSinkHangLongTime=return(true);github.com/pingcap/tiflow/cdc/sink/ddlsink/mysql/MySQLSinkExecDDLDelay=return(true)' 51 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix consistent_replicate_ddl.server2 52 53 # case 1: 54 # global ddl tests -> ActionRenameTable 55 # table ddl tests -> ActionDropTable 56 run_sql "DROP TABLE consistent_replicate_ddl.usertable1" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 57 run_sql "RENAME TABLE consistent_replicate_ddl.usertable_bak TO consistent_replicate_ddl.usertable1" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 58 run_sql "INSERT INTO consistent_replicate_ddl.usertable1 SELECT * FROM consistent_replicate_ddl.usertable limit 10" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 59 run_sql "RENAME TABLE consistent_replicate_ddl.usertable1 TO consistent_replicate_ddl.usertable1_1" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 60 run_sql "INSERT IGNORE INTO consistent_replicate_ddl.usertable1_1 SELECT * FROM consistent_replicate_ddl.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 61 62 # case 2: 63 # global ddl tests -> ActionCreateSchema, ActionModifySchemaCharsetAndCollate 64 # table ddl tests -> ActionMultiSchemaChange, ActionAddColumn, ActionDropColumn, ActionModifyTableCharsetAndCollate 65 run_sql "CREATE DATABASE consistent_replicate_ddl1" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 66 run_sql "ALTER DATABASE consistent_replicate_ddl CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 67 run_sql "ALTER TABLE consistent_replicate_ddl.usertable2 CHARACTER SET utf8mb4 COLLATE utf8mb4_bin" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 68 run_sql "INSERT INTO consistent_replicate_ddl.usertable2 SELECT * FROM consistent_replicate_ddl.usertable limit 20" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 69 run_sql "ALTER TABLE consistent_replicate_ddl.usertable2 DROP COLUMN FIELD0" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 70 run_sql "ALTER TABLE consistent_replicate_ddl.usertable2 ADD COLUMN dummy varchar(30)" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 71 72 # case 3: 73 # global ddl tests -> ActionDropSchema, ActionRenameTables 74 # table ddl tests -> ActionModifyColumn 75 run_sql "DROP DATABASE consistent_replicate_ddl1" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 76 run_sql "ALTER TABLE consistent_replicate_ddl.usertable3 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 77 run_sql "RENAME TABLE consistent_replicate_ddl.usertable2 to consistent_replicate_ddl.usertable2_1, consistent_replicate_ddl.usertable3 TO consistent_replicate_ddl.usertable3_1" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 78 run_sql "ALTER TABLE consistent_replicate_ddl.usertable3_1 MODIFY COLUMN FIELD1 varchar(100)" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 79 run_sql "INSERT INTO consistent_replicate_ddl.usertable3_1 SELECT * FROM consistent_replicate_ddl.usertable limit 31" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 80 81 run_sql "CREATE table consistent_replicate_ddl.check1(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 82 83 # to ensure row changed events have been replicated to TiCDC 84 sleep 120 85 cleanup_process $CDC_BINARY 86 87 storage_path="file://$WORK_DIR/redo" 88 tmp_download_path=$WORK_DIR/cdc_data/redo/$changefeed_id 89 export GO_FAILPOINTS='' 90 91 rts=$(cdc redo meta --storage="$storage_path" --tmp-dir="$tmp_download_path" | grep -oE "resolved-ts:[0-9]+" | awk -F: '{print $2}') 92 sed "s/<placeholder>/$rts/g" $CUR/conf/diff_config.toml >$WORK_DIR/diff_config.toml 93 94 cat $WORK_DIR/diff_config.toml 95 cdc redo apply --tmp-dir="$tmp_download_path/apply" \ 96 --storage="$storage_path" \ 97 --sink-uri="mysql://normal:123456@127.0.0.1:3306/" 98 99 check_table_exists "consistent_replicate_ddl.check1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 120 100 check_sync_diff $WORK_DIR $WORK_DIR/diff_config.toml 101 } 102 103 trap stop EXIT 104 run $* 105 check_logs $WORK_DIR 106 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"