github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/consistent_replicate_storage_file/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_storage_file.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 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_storage_file;" ${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_storage_file 38 run_sql "CREATE table consistent_replicate_storage_file.check1(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 39 run_sql_file $CUR/data/prepare.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT} 40 check_table_exists "consistent_replicate_storage_file.usertable" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 41 check_table_exists "consistent_replicate_storage_file.check1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 120 42 check_table_exists "consistent_replicate_storage_file.t2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 120 43 44 check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 45 46 # Inject the failpoint to prevent sink execution, but the global resolved can be moved forward. 47 # Then we can apply redo log to reach an eventual consistent state in downstream. 48 cleanup_process $CDC_BINARY 49 export GO_FAILPOINTS='github.com/pingcap/tiflow/cdc/sink/dmlsink/txn/mysql/MySQLSinkHangLongTime=return(true)' 50 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY 51 run_sql "create table consistent_replicate_storage_file.usertable2 like consistent_replicate_storage_file.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 52 run_sql "ALTER TABLE consistent_replicate_storage_file.t1 EXCHANGE PARTITION p3 WITH TABLE consistent_replicate_storage_file.t2" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 53 run_sql "insert into consistent_replicate_storage_file.t2 values (100),(101),(102),(103),(104),(105);" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 54 run_sql "insert into consistent_replicate_storage_file.t1 values (25),(29);" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 55 run_sql "insert into consistent_replicate_storage_file.usertable2 select * from consistent_replicate_storage_file.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 56 57 # to ensure row changed events have been replicated to TiCDC 58 sleep 20 59 60 storage_path="file://$WORK_DIR/redo" 61 tmp_download_path=$WORK_DIR/cdc_data/redo/$changefeed_id 62 current_tso=$(cdc cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1) 63 ensure 50 check_redo_resolved_ts $changefeed_id $current_tso $storage_path $tmp_download_path/meta 64 cleanup_process $CDC_BINARY 65 66 export GO_FAILPOINTS='' 67 68 # This value is generated by: 69 # echo -n '123456' | base64 70 # MTIzNDU2 71 # Use this value here to test redo apply function works well 72 # when use base64 encoded password 73 ENPASSWORD="MTIzNDU2" 74 75 cdc redo apply --tmp-dir="$tmp_download_path/apply" \ 76 --storage="$storage_path" \ 77 --sink-uri="mysql://normal:${ENPASSWORD}@127.0.0.1:3306/" 78 check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 79 } 80 81 trap stop EXIT 82 run $* 83 check_logs $WORK_DIR 84 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"