github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/_utils/handle_error_lib.sh (about) 1 #!/bin/bash 2 3 set -eu 4 5 db="handle_error" 6 tb1="tb1" 7 tb2="tb2" 8 tb="tb" 9 ta1="ta1" 10 ta2="ta2" 11 ta="ta" 12 source1="mysql-replica-01" 13 source2="mysql-replica-02" 14 15 function init_database() { 16 run_sql_both_source "drop database if exists ${db};" 17 run_sql_both_source "create database if not exists ${db};" 18 } 19 20 function extract() { 21 str="$1" 22 source=${str:0:1} 23 table=${str:1:1} 24 } 25 26 # set charset explicitly because MySQL 8.0 has different default charsets. 27 function init_table() { 28 for i in $@; do 29 extract $i 30 run_sql_source${source} "create table ${db}.tb${table} (id int primary key) CHARSET=latin1 COLLATE=latin1_bin;" 31 done 32 } 33 34 function clean_table() { 35 run_sql_both_source "drop table if exists ${db}.${tb1};" 36 run_sql_both_source "drop table if exists ${db}.${tb2};" 37 run_sql_both_source "drop table if exists ${db}.${ta1};" 38 run_sql_both_source "drop table if exists ${db}.${ta2};" 39 run_sql_tidb "drop table if exists ${db}.${tb};" 40 run_sql_tidb "drop table if exists ${db}.${ta};" 41 run_sql_tidb "drop table if exists ${db}.${tb1};" 42 run_sql_tidb "drop table if exists ${db}.${tb2};" 43 run_sql_tidb "drop database if exists dm_meta;" 44 } 45 46 function get_start_location() { 47 location=$($PWD/bin/dmctl.test DEVEL --master-addr=$1 \ 48 query-status test -s $2 | 49 grep Location | 50 gawk 'match($0,/startLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\], endLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\]/,a) {printf "%s:%s", a[1], a[2]}') 51 echo ${location} 52 } 53 54 function get_end_location() { 55 location=$($PWD/bin/dmctl.test DEVEL --master-addr=$1 \ 56 query-status test -s $2 | 57 grep Location | 58 gawk 'match($0,/startLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\], endLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\]/,a) {printf "%s:%s", a[4], a[5]}') 59 echo ${location} 60 } 61 62 function get_start_pos() { 63 pos=$($PWD/bin/dmctl.test DEVEL --master-addr=$1 \ 64 query-status test -s $2 | 65 grep Location | 66 gawk 'match($0,/startLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\], endLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\]/,a) {print a[2]}') 67 echo ${pos} 68 } 69 70 function get_start_name() { 71 pos=$($PWD/bin/dmctl.test DEVEL --master-addr=$1 \ 72 query-status test -s $2 | 73 grep Location | 74 gawk 'match($0,/startLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\], endLocation: \[position: \((.*), (.*)\), gtid-set: (.*)\]/,a) {print a[1]}') 75 echo ${pos} 76 } 77 78 # get next ddl position base on $3 79 function get_next_query_pos() { 80 pos=$(mysql -uroot -P$1 -h127.0.0.1 -p$2 -e 'show binlog events' | grep Query | awk '{ if ($2>'"$3"' && $6!="BEGIN") {print $2; exit} }') 81 echo ${pos} 82 }