github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/mariadb_master_down_and_up/lib.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 export TEST_DIR=/tmp/dm_test 6 export TEST_NAME="mariadb_master_down_and_up" 7 export DM_MASTER_EXTRA_ARG="" 8 9 WORK_DIR=$TEST_DIR/$TEST_NAME 10 rm -rf $WORK_DIR 11 mkdir -p $WORK_DIR 12 13 db="db_pessimistic" 14 tb="tb" 15 16 master_port="3306" 17 slave_port="3307" 18 tidb_port="4000" 19 MASTER_PORT=8261 20 WORKER1_PORT=8262 21 22 function exec_sql() { 23 echo $2 | MYSQL_PWD=123456 mysql -uroot -h127.0.0.1 -P$1 24 } 25 26 function exec_tidb() { 27 echo $2 | mysql -uroot -h127.0.0.1 -P$1 28 } 29 30 function install_sync_diff() { 31 curl https://download.pingcap.org/tidb-enterprise-tools-nightly-linux-amd64.tar.gz | tar xz 32 mkdir -p bin 33 mv tidb-enterprise-tools-nightly-linux-amd64/bin/sync_diff_inspector bin/ 34 } 35 36 function get_master_status() { 37 arr=$(echo "show master status;" | MYSQL_PWD=123456 mysql -uroot -h127.0.0.1 -P3306 | awk 'NR==2') 38 echo $arr 39 } 40 41 function change_master_to_gtid() { 42 exec_sql $1 "stop slave;" 43 exec_sql $1 "change master to master_host='mariadb_master',master_port=$2,master_user='root',master_password='123456',master_use_gtid=slave_pos;" 44 exec_sql $1 "start slave;" 45 } 46 47 function wait_mysql() { 48 echo "-------wait_mysql--------" 49 50 i=0 51 while ! mysqladmin -h127.0.0.1 -P$1 -uroot ping --connect-timeout=1 >/dev/null 2>&1; do 52 echo "wait mysql" 53 i=$((i + 1)) 54 if [ "$i" -gt 20 ]; then 55 echo "wait for mysql $1:3306 timeout" 56 exit 1 57 fi 58 sleep 1 59 done 60 i=0 61 62 server_id=$(echo "show variables like 'server_id';" | MYSQL_PWD=123456 mysql -uroot -h127.0.0.1 -P$1 | awk 'NR==2' | awk '{print $2}') 63 while [ "$server_id" != $2 ]; do 64 echo "wait server_id" 65 i=$((i + 1)) 66 if [ "$i" -gt 20 ]; then 67 echo "different server_id: $server_id, expect: $2, host: $1" 68 exit 1 69 fi 70 sleep 1 71 server_id=$(echo "show variables like 'server_id';" | MYSQL_PWD=123456 mysql -uroot -h127.0.0.1 -P$1 | awk 'NR==2' | awk '{print $2}') 72 done 73 }