github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/sync_collation/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=$TEST_DIR/$TEST_NAME
     8  TASK_NAME="sync_collation"
     9  db="sync_collation"
    10  db_increment="sync_collation_increment"
    11  db_server_collation="sync_collation_server"
    12  db2="sync_collation2"
    13  db_increment2="sync_collation_increment2"
    14  db_server_collation2="sync_collation_server2"
    15  tb="t1"
    16  tb2="t2"
    17  tb_check="t_check"
    18  
    19  function run() {
    20  	run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml
    21  	check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT
    22  	run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
    23  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
    24  	run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml
    25  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT
    26  
    27  	# operate mysql config to worker
    28  	cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml
    29  	cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml
    30  	dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1
    31  	dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2
    32  
    33  	echo "prepare data"
    34  	run_sql_file $cur/data/clean_data.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    35  	run_sql_file $cur/data/clean_data.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    36  	run_sql_file $cur/data/clean_data.sql $TIDB_HOST $TIDB_PORT $TIDB_PASSWORD
    37  	run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    38  	run_sql_file $cur/data/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    39  
    40  	echo "start task"
    41  	cat $cur/conf/dm-task.yaml >$WORK_DIR/dm-task.yaml
    42  	dmctl_start_task $WORK_DIR/dm-task.yaml "--remove-meta"
    43  
    44  	echo "check full phase"
    45  	# wait
    46  	run_sql_tidb_with_retry " select count(1) from information_schema.tables where TABLE_SCHEMA='${db}' and TABLE_NAME = '${tb}';" "count(1): 1"
    47  	run_sql_tidb_with_retry " select count(1) from information_schema.tables where TABLE_SCHEMA='${db2}' and TABLE_NAME = '${tb}';" "count(1): 1"
    48  
    49  	# check table
    50  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb} where name = 'aa';" "count(1): 2"
    51  	run_sql_tidb_with_retry "select count(1) from ${db2}.${tb} where name = 'aa';" "count(1): 2"
    52  
    53  	# check column
    54  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb2} where name = 'aa';" "count(1): 2"
    55  	run_sql_tidb_with_retry "select count(1) from ${db2}.${tb2} where name = 'aa';" "count(1): 2"
    56  
    57  	# check database by create table
    58  	run_sql_file $cur/data/tidb.checktable.prepare.sql $TIDB_HOST $TIDB_PORT $TIDB_PASSWORD
    59  	run_sql_tidb_with_retry "select count(1) from ${db}.${tb_check} where name = 'aa';" "count(1): 2"
    60  	run_sql_tidb_with_retry "select count(1) from ${db2}.${tb_check} where name = 'aa';" "count(1): 2"
    61  
    62  	echo "prepare incremental data"
    63  	run_sql_file $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    64  	run_sql_file $cur/data/db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    65  
    66  	echo "check incremental phase"
    67  	# wait
    68  	run_sql_tidb_with_retry " select count(1) from information_schema.tables where TABLE_SCHEMA='${db_increment}' and TABLE_NAME = '${tb}';" "count(1): 1"
    69  	run_sql_tidb_with_retry " select count(1) from information_schema.tables where TABLE_SCHEMA='${db_increment2}' and TABLE_NAME = '${tb}';" "count(1): 1"
    70  
    71  	# check table
    72  	run_sql_tidb_with_retry "select count(1) from ${db_increment}.${tb} where name = 'aa';" "count(1): 2"
    73  	run_sql_tidb_with_retry "select count(1) from ${db_increment2}.${tb} where name = 'aa';" "count(1): 2"
    74  
    75  	# check column
    76  	run_sql_tidb_with_retry "select count(1) from ${db_increment}.${tb2} where name = 'aa';" "count(1): 2"
    77  	run_sql_tidb_with_retry "select count(1) from ${db_increment2}.${tb2} where name = 'aa';" "count(1): 2"
    78  
    79  	# check database by create table
    80  	run_sql_file $cur/data/tidb.checktable.increment.prepare.sql $TIDB_HOST $TIDB_PORT $TIDB_PASSWORD
    81  	run_sql_tidb_with_retry "select count(1) from ${db_increment}.${tb_check} where name = 'aa';" "count(1): 2"
    82  	run_sql_tidb_with_retry "select count(1) from ${db_increment2}.${tb_check} where name = 'aa';" "count(1): 2"
    83  
    84  	# check set server collation
    85  	run_sql_tidb_with_retry "select count(1) from ${db_server_collation}.${tb} where name = 'aa';" "count(1): 2"
    86  	run_sql_tidb_with_retry "select count(1) from ${db_server_collation2}.${tb} where name = 'aa';" "count(1): 2"
    87  
    88  	dmctl_stop_task $TASK_NAME $MASTER_PORT
    89  
    90  	echo "prepare data for full phase error test"
    91  	run_sql_file $cur/data/clean_data.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    92  	run_sql_file $cur/data/clean_data.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    93  	run_sql_file $cur/data/clean_data.sql $TIDB_HOST $TIDB_PORT $TIDB_PASSWORD
    94  	run_sql_file $cur/data/db1.prepare_err.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    95  	run_sql_file $cur/data/db2.prepare_err.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    96  
    97  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    98  		"start-task $WORK_DIR/dm-task.yaml --remove-meta"
    99  
   100  	echo "check full phase error"
   101  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   102  		"query-status ${TASK_NAME}" \
   103  		"Error 1273 (HY000): Unsupported collation when new collation is enabled: 'latin1_swedish_ci'" 1
   104  
   105  	dmctl_stop_task $TASK_NAME $MASTER_PORT
   106  
   107  	echo "prepare data for incremental phase error test"
   108  	run_sql_file $cur/data/clean_data.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
   109  	run_sql_file $cur/data/clean_data.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
   110  	run_sql_file $cur/data/clean_data.sql $TIDB_HOST $TIDB_PORT $TIDB_PASSWORD
   111  
   112  	dmctl_start_task $WORK_DIR/dm-task.yaml "--remove-meta"
   113  
   114  	run_sql_file $cur/data/db1.increment_err.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
   115  	run_sql_file $cur/data/db2.increment_err.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
   116  
   117  	echo "check incremental phase error"
   118  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
   119  		"query-status ${TASK_NAME}" \
   120  		"Error 1273 (HY000): Unsupported collation when new collation is enabled: 'latin1_swedish_ci'" 1
   121  }
   122  
   123  cleanup_data $TEST_NAME
   124  # also cleanup dm processes in case of last run failed
   125  cleanup_process $*
   126  run $*
   127  cleanup_process $*
   128  
   129  echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"