github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/sequence_sharding/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  
     9  function run() {
    10  	run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    11  	run_sql_file $cur/data/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    12  
    13  	run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml
    14  	check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT
    15  	run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
    16  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT
    17  	run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml
    18  	check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT
    19  	# operate mysql config to worker
    20  	cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml
    21  	cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml
    22  	sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml
    23  	sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml
    24  	dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1
    25  	dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2
    26  
    27  	# start DM task only
    28  	dmctl_start_task
    29  
    30  	# use sync_diff_inspector to check full dump loader
    31  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    32  
    33  	run_sql_file $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    34  	run_sql_file $cur/data/db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    35  
    36  	sleep 3
    37  	# use sync_diff_inspector to check data now!
    38  	check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
    39  
    40  	run_sql_file $cur/data/db1.increment2.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
    41  	run_sql_file $cur/data/db2.increment2.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
    42  
    43  	# the first ddl success while the second is conflict
    44  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    45  		"query-status sequence_sharding" \
    46  		"detect inconsistent DDL sequence" 2
    47  
    48  	# check no auto resume, DefaultCheckInterval is 5s, so here doubles
    49  	sleep 11
    50  	check_log_contains $WORK_DIR/worker1/log/dm-worker.log "task can't auto resume"
    51  
    52  	# resume manually
    53  	# this operation may not return 3 `"result": true`, because worker may
    54  	# - response too slowly to resume, so resume still see old error and waitOperationOk will return early
    55  	# - response too quickly, so resume see error of "still conflict" in next lines
    56  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    57  		"resume-task sequence_sharding"
    58  
    59  	# still conflict
    60  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    61  		"query-status sequence_sharding" \
    62  		"detect inconsistent DDL sequence" 2
    63  
    64  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    65  		"stop-task sequence_sharding" \
    66  		"\"result\": true" 3
    67  
    68  	# now upstream schema is conflict, ignore it and restart task
    69  	cp $cur/conf/dm-task.yaml $WORK_DIR/task.yaml
    70  	echo "ignore-checking-items: [\"all\"]" >>$WORK_DIR/task.yaml
    71  	run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    72  		"start-task $WORK_DIR/task.yaml"
    73  
    74  	# still conflict
    75  	run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
    76  		"query-status sequence_sharding" \
    77  		"detect inconsistent DDL sequence" 2
    78  }
    79  
    80  cleanup_data sharding_target2
    81  # also cleanup dm processes in case of last run failed
    82  cleanup_process $*
    83  run $*
    84  cleanup_process $*
    85  
    86  echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>"