github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/cyclic_ab/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 run() {
    12      # kafka is not supported yet.
    13      if [ "$SINK_TYPE" == "kafka" ]; then
    14        return
    15      fi
    16  
    17      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    18  
    19      start_tidb_cluster --workdir $WORK_DIR
    20  
    21      cd $WORK_DIR
    22  
    23  
    24      # create table to upstream.
    25      run_sql "CREATE table test.simple(id1 int, id2 int, source int, primary key (id1, id2));" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    26      # create an ineligible table to make sure cyclic replication works fine even with some ineligible tables.
    27      run_sql "CREATE table test.ineligible(id int, val int);"
    28  
    29      # create table to downsteam.
    30      run_sql "CREATE table test.simple(id1 int, id2 int, source int, primary key (id1, id2));" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    31  
    32      run_cdc_cli changefeed cyclic create-marktables \
    33          --cyclic-upstream-dsn="root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/"
    34  
    35      run_cdc_cli changefeed cyclic create-marktables \
    36          --cyclic-upstream-dsn="root@tcp(${DOWN_TIDB_HOST}:${DOWN_TIDB_PORT})/"
    37  
    38      # make sure create-marktables does not create mark table for mark table.
    39      for c in $(seq 1 10); do {
    40          # must not cause an error table name too long.
    41          run_cdc_cli changefeed cyclic create-marktables \
    42              --cyclic-upstream-dsn="root@tcp(${UP_TIDB_HOST}:${UP_TIDB_PORT})/"
    43      } done
    44  
    45      # record tso after we create tables to not block on waiting mark tables DDLs.
    46      start_ts=$(run_cdc_cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1)
    47  
    48      run_cdc_server \
    49          --workdir $WORK_DIR \
    50          --binary $CDC_BINARY \
    51          --logsuffix "_${TEST_NAME}_upsteam" \
    52          --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}" \
    53          --addr "127.0.0.1:8300"
    54  
    55      run_cdc_server \
    56          --workdir $WORK_DIR \
    57          --binary $CDC_BINARY \
    58          --logsuffix "_${TEST_NAME}_downsteam" \
    59          --pd "http://${DOWN_PD_HOST}:${DOWN_PD_PORT}" \
    60          --addr "127.0.0.1:8301"
    61  
    62      # Echo y to ignore ineligible tables
    63      echo "y" | run_cdc_cli changefeed create --start-ts=$start_ts \
    64          --sink-uri="mysql://root@${DOWN_TIDB_HOST}:${DOWN_TIDB_PORT}/?safe-mode=false" \
    65          --pd "http://${UP_PD_HOST_1}:${UP_PD_PORT_1}" \
    66          --cyclic-replica-id 1 \
    67          --cyclic-filter-replica-ids 2 \
    68          --cyclic-sync-ddl true
    69  
    70      run_cdc_cli changefeed create --start-ts=$start_ts \
    71          --sink-uri="mysql://root@${UP_TIDB_HOST}:${UP_TIDB_PORT}/?safe-mode=false" \
    72          --pd "http://${DOWN_PD_HOST}:${DOWN_PD_PORT}" \
    73          --cyclic-replica-id 2 \
    74          --cyclic-filter-replica-ids 1 \
    75          --cyclic-sync-ddl false \
    76          --config $CUR/conf/only_test_simple.toml
    77  
    78      for i in $(seq 11 20); do {
    79          sqlup="START TRANSACTION;"
    80          sqldown="START TRANSACTION;"
    81          for j in $(seq 21 24); do {
    82              if [ $((j%2)) -eq 0 ]; then
    83                  sqldown+="INSERT INTO test.simple(id1, id2, source) VALUES (${i}, ${j}, 2);"
    84              else
    85                  sqlup+="INSERT INTO test.simple(id1, id2, source) VALUES (${i}, ${j}, 1);"
    86              fi
    87          } done;
    88          sqlup+="COMMIT;"
    89          sqldown+="COMMIT;"
    90  
    91          echo $sqlup
    92          echo $sqldown
    93          run_sql "${sqlup}" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    94          run_sql "${sqldown}" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
    95      } done;
    96  
    97      # sync-diff creates table which may block cyclic replication.
    98      # Sleep a while to make sure all changes has been replicated.
    99      sleep 10
   100  
   101      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   102  
   103      # At the time of writing, tso is at least 18 digits long in decimal format.
   104      # $ pd-ctl tso 418252158551982113
   105      # system:  2020-07-23 19:56:05.57 +0800 CST
   106      # logic:  33
   107      run_sql "SELECT start_timestamp FROM tidb_cdc.repl_mark_test_simple LIMIT 1;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && \
   108      check_contains "start_timestamp: [0-9]{18,}"
   109  
   110      cleanup_process $CDC_BINARY
   111  }
   112  
   113  trap stop_tidb_cluster EXIT
   114  run $*
   115  check_logs $WORK_DIR
   116  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"