github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/region_merge/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  
    11  function split_and_random_merge() {
    12      pd_addr=$1
    13      scale=$2
    14      echo "split_and_random_merge scale: $scale"
    15      run_sql "SPLIT TABLE region_merge.t1 BETWEEN (-9223372036854775808) AND (9223372036854775807) REGIONS $scale;" ${UP_TIDB_HOST} ${UP_TIDB_PORT} || true
    16      run_sql "SELECT count(distinct region_id) from information_schema.tikv_region_status where db_name = 'region_merge' and table_name = 't1';" \
    17          && cat $OUT_DIR/sql_res.region_merge.txt
    18      run_sql "insert into region_merge.t1 values (-9223372036854775808),(0),(1),(9223372036854775807);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    19      run_sql "delete from region_merge.t1;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    20      # sleep 5s to wait some region merge
    21      sleep 5
    22  }
    23  
    24  large_scale=(100 200 400 800 1600 3200 6400 12800 25600 51200)
    25  small_scale=(20 40 80)
    26  # in CI, we use the small data set
    27  test_scale=( "${small_scale[@]}" )
    28  
    29  function run() {
    30      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    31  
    32      start_tidb_cluster --workdir $WORK_DIR --multiple-upstream-pd true --pd-config $CUR/conf/pd_config.toml
    33  
    34      cd $WORK_DIR
    35  
    36      pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    37      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY
    38      TOPIC_NAME="ticdc-region-merge-test-$RANDOM"
    39      case $SINK_TYPE in
    40          kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-version=${KAFKA_VERSION}";;
    41          *) SINK_URI="mysql://normal:123456@127.0.0.1:3306/";;
    42      esac
    43      run_cdc_cli changefeed create --sink-uri="$SINK_URI"
    44      if [ "$SINK_TYPE" == "kafka" ]; then
    45        run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}"
    46      fi
    47  
    48      # set max_execution_time to 30s, because split region could block even region has been split.
    49      run_sql "SET @@global.MAX_EXECUTION_TIME = 30000;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    50      run_sql "CREATE DATABASE region_merge;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    51      run_sql "CREATE TABLE region_merge.t1 (id bigint primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    52  
    53      for scale in "${test_scale[@]}"; do
    54          split_and_random_merge $pd_addr $scale
    55      done
    56  
    57      run_sql "insert into region_merge.t1 values (-9223372036854775808),(0),(1),(9223372036854775807);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    58      check_table_exists region_merge.t1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    59      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    60  
    61      cleanup_process $CDC_BINARY
    62  }
    63  
    64  trap stop_tidb_cluster EXIT
    65  run $*
    66  check_logs $WORK_DIR
    67  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"