github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/cyclic_abc/run.sh (about) 1 #!/bin/bash 2 3 set -e 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 TLS_DIR=$( cd $CUR/../_certificates && pwd ) 11 12 function run() { 13 # kafka is not supported yet. 14 if [ "$SINK_TYPE" == "kafka" ]; then 15 return 16 fi 17 18 rm -rf $WORK_DIR && mkdir -p $WORK_DIR 19 20 start_tidb_cluster --workdir $WORK_DIR 21 start_tls_tidb_cluster --workdir $WORK_DIR --tlsdir $TLS_DIR 22 23 echo " \ 24 [security] 25 ca-path = \"$TLS_DIR/ca.pem\" 26 cert-path = \"$TLS_DIR/server.pem\" 27 key-path = \"$TLS_DIR/server-key.pem\" 28 cert-allowed-cn = [\"fake_cn\"] 29 " > $WORK_DIR/server.toml 30 31 cd $WORK_DIR 32 33 # create table in all cluters. 34 run_sql "CREATE table test.simple(id1 int, id2 int, source int, primary key (id1, id2)) \ 35 partition by range (id1) ( \ 36 partition p0 values less than (10), \ 37 partition p1 values less than (20), \ 38 partition p3 values less than (30) \ 39 );" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 40 run_sql "CREATE table test.simple(id1 int, id2 int, source int, primary key (id1, id2)) \ 41 partition by range (id1) ( \ 42 partition p0 values less than (10), \ 43 partition p1 values less than (20), \ 44 partition p3 values less than (30) \ 45 );" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 46 run_sql "CREATE table test.simple(id1 int, id2 int, source int, primary key (id1, id2)) \ 47 partition by range (id1) ( \ 48 partition p0 values less than (10), \ 49 partition p1 values less than (20), \ 50 partition p3 values less than (30) \ 51 );" ${TLS_TIDB_HOST} ${TLS_TIDB_PORT} \ 52 --ssl-ca=$TLS_DIR/ca.pem \ 53 --ssl-cert=$TLS_DIR/server.pem \ 54 --ssl-key=$TLS_DIR/server-key.pem 55 56 run_cdc_cli changefeed cyclic create-marktables \ 57 --cyclic-upstream-dsn="root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/" \ 58 --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}" 59 60 run_cdc_cli changefeed cyclic create-marktables \ 61 --cyclic-upstream-dsn="root@tcp(${DOWN_TIDB_HOST}:${DOWN_TIDB_PORT})/" \ 62 --pd "http://${DOWN_PD_HOST}:${DOWN_PD_PORT}" 63 64 run_cdc_cli changefeed cyclic create-marktables \ 65 --cyclic-upstream-dsn="root@tcp(${TLS_TIDB_HOST}:${TLS_TIDB_PORT})/" \ 66 --pd "https://${TLS_PD_HOST}:${TLS_PD_PORT}" \ 67 --ca=$TLS_DIR/ca.pem \ 68 --cert=$TLS_DIR/client.pem \ 69 --key=$TLS_DIR/client-key.pem \ 70 --cyclic-upstream-ssl-ca=$TLS_DIR/ca.pem \ 71 --cyclic-upstream-ssl-cert=$TLS_DIR/server.pem \ 72 --cyclic-upstream-ssl-key=$TLS_DIR/server-key.pem 73 74 # record tso after we create tables to not block on waiting mark tables DDLs. 75 start_ts=$(run_cdc_cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1) 76 77 run_cdc_server \ 78 --workdir $WORK_DIR \ 79 --binary $CDC_BINARY \ 80 --logsuffix "_${TEST_NAME}_upsteam" \ 81 --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}" \ 82 --addr "127.0.0.1:8300" 83 84 run_cdc_server \ 85 --workdir $WORK_DIR \ 86 --binary $CDC_BINARY \ 87 --logsuffix "_${TEST_NAME}_downsteam" \ 88 --pd "http://${DOWN_PD_HOST}:${DOWN_PD_PORT}" \ 89 --addr "127.0.0.1:8301" 90 91 run_cdc_server \ 92 --workdir $WORK_DIR \ 93 --binary $CDC_BINARY \ 94 --logsuffix "_${TEST_NAME}_tls" \ 95 --pd "https://${TLS_PD_HOST}:${TLS_PD_PORT}" \ 96 --addr "127.0.0.1:8302" \ 97 --config "$WORK_DIR/server.toml" \ 98 --cert-allowed-cn "client" # The common name of client.pem 99 100 run_cdc_cli changefeed create --start-ts=$start_ts \ 101 --sink-uri="mysql://root@${DOWN_TIDB_HOST}:${DOWN_TIDB_PORT}/?safe-mode=true" \ 102 --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}" \ 103 --cyclic-replica-id 1 \ 104 --cyclic-filter-replica-ids 2 \ 105 --cyclic-sync-ddl true 106 107 run_cdc_cli changefeed create --start-ts=$start_ts \ 108 --sink-uri="mysql://root@${TLS_TIDB_HOST}:${TLS_TIDB_PORT}/?safe-mode=true&ssl-ca=${TLS_DIR}/ca.pem&ssl-cert=${TLS_DIR}/server.pem?ssl-key=${TLS_DIR}/server-key.pem" \ 109 --pd "http://${DOWN_PD_HOST}:${DOWN_PD_PORT}" \ 110 --cyclic-replica-id 2 \ 111 --cyclic-filter-replica-ids 3 \ 112 --cyclic-sync-ddl true 113 114 run_cdc_cli changefeed create --start-ts=$start_ts \ 115 --sink-uri="mysql://root@${UP_TIDB_HOST}:${UP_TIDB_PORT}/?safe-mode=true" \ 116 --pd "https://${TLS_PD_HOST}:${TLS_PD_PORT}" \ 117 --changefeed-id "tls-changefeed" \ 118 --ca=$TLS_DIR/ca.pem \ 119 --cert=$TLS_DIR/client.pem \ 120 --key=$TLS_DIR/client-key.pem \ 121 --cyclic-replica-id 3 \ 122 --cyclic-filter-replica-ids 1 \ 123 --cyclic-sync-ddl false 124 125 for i in $(seq 6 15); do { 126 sqlup="START TRANSACTION;" 127 sqldown="START TRANSACTION;" 128 sqltls="START TRANSACTION;" 129 for j in $(seq 21 24); do { 130 if [ $((j%3)) -eq 0 ]; then # 2 rows for 3 131 sqltls+="INSERT INTO test.simple(id1, id2, source) VALUES (${i}, ${j}, 3);" 132 elif [ $((j%3)) -eq 1 ]; then # 1 row for 1 133 sqlup+="INSERT INTO test.simple(id1, id2, source) VALUES (${i}, ${j}, 1);" 134 else # 1 row for 2 135 sqldown+="INSERT INTO test.simple(id1, id2, source) VALUES (${i}, ${j}, 2);" 136 fi 137 } done; 138 sqlup+="COMMIT;" 139 sqldown+="COMMIT;" 140 sqltls+="COMMIT;" 141 142 echo $sqlup 143 echo $sqldown 144 echo $sqltls 145 run_sql "${sqlup}" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 146 run_sql "${sqldown}" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 147 run_sql "${sqltls}" ${TLS_TIDB_HOST} ${TLS_TIDB_PORT} \ 148 --ssl-ca=$TLS_DIR/ca.pem \ 149 --ssl-cert=$TLS_DIR/server.pem \ 150 --ssl-key=$TLS_DIR/server-key.pem 151 } done; 152 153 # sync-diff creates table which may block cyclic replication. 154 # Sleep a while to make sure all changes has been replicated. 155 sleep 10 156 157 check_sync_diff $WORK_DIR $CUR/conf/diff_config_up_down.toml 158 check_sync_diff $WORK_DIR $CUR/conf/diff_config_down_tls.toml 159 160 # Check cert Common Name. 161 curl --cacert $TLS_DIR/ca.pem \ 162 --cert $TLS_DIR/client.pem \ 163 --key $TLS_DIR/client-key.pem \ 164 https://127.0.0.1:8302/status 165 166 if curl --cacert $TLS_DIR/ca.pem \ 167 --cert $TLS_DIR/server.pem \ 168 --key $TLS_DIR/server-key.pem \ 169 -sf --show-error \ 170 https://127.0.0.1:8302/status ; then 171 echo "must not connect successfully" 172 exit 1 173 fi 174 175 # Check cli TLS 176 run_cdc_cli changefeed list \ 177 --pd "https://${TLS_PD_HOST}:${TLS_PD_PORT}" \ 178 --ca=$TLS_DIR/ca.pem \ 179 --cert=$TLS_DIR/client.pem \ 180 --key=$TLS_DIR/client-key.pem 181 182 run_cdc_cli changefeed query \ 183 --changefeed-id "tls-changefeed" \ 184 --pd "https://${TLS_PD_HOST}:${TLS_PD_PORT}" \ 185 --ca=$TLS_DIR/ca.pem \ 186 --cert=$TLS_DIR/client.pem \ 187 --key=$TLS_DIR/client-key.pem 188 189 cleanup_process $CDC_BINARY 190 } 191 192 trap stop_tidb_cluster EXIT 193 run $* 194 check_logs $WORK_DIR 195 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"