github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/kafka_messages/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=$OUT_DIR/$TEST_NAME
     8  CDC_BINARY=cdc.test
     9  SINK_TYPE=$1
    10  
    11  CDC_COUNT=3
    12  DB_COUNT=4
    13  
    14  function run_length_limit() {
    15  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    16  
    17  	start_tidb_cluster --workdir $WORK_DIR
    18  
    19  	cd $WORK_DIR
    20  
    21  	run_sql "DROP DATABASE if exists kafka_message;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    22  
    23  	start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1})
    24  	run_sql "CREATE DATABASE kafka_message;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    25  	go-ycsb load mysql -P $CUR/conf/workload -p mysql.host=${UP_TIDB_HOST} -p mysql.port=${UP_TIDB_PORT} -p mysql.user=root -p mysql.db=kafka_message
    26  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --loglevel "info"
    27  
    28  	TOPIC_NAME="ticdc-kafka-message-test-$RANDOM"
    29  	# Use a max-message-bytes parameter that is larger than the kafka broker max message bytes.
    30  	# Test if TiCDC automatically uses the max-message-bytes of the broker.
    31  	# See: https://github.com/PingCAP-QE/ci/blob/ddde195ebf4364a0028d53405d1194aa37a4d853/jenkins/pipelines/ci/ticdc/cdc_ghpr_kafka_integration_test.groovy#L178
    32  	SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&kafka-version=${KAFKA_VERSION}&max-message-bytes=12582912"
    33  	run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI"
    34  	if [ "$SINK_TYPE" == "kafka" ]; then
    35  		run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&version=${KAFKA_VERSION}"
    36  	fi
    37  
    38  	# Add a check table to reduce check time, or if we check data with sync diff
    39  	# directly, there maybe a lot of diff data at first because of the incremental scan
    40  	run_sql "CREATE table kafka_message.check1(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    41  	check_table_exists "kafka_message.usertable" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    42  	check_table_exists "kafka_message.check1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    43  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    44  
    45  	run_sql "truncate table kafka_message.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    46  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    47  	run_sql "CREATE table kafka_message.check2(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    48  	check_table_exists "kafka_message.check2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    49  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    50  
    51  	go-ycsb load mysql -P $CUR/conf/workload -p mysql.host=${UP_TIDB_HOST} -p mysql.port=${UP_TIDB_PORT} -p mysql.user=root -p mysql.db=kafka_message
    52  	run_sql "CREATE table kafka_message.check3(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    53  	check_table_exists "kafka_message.check3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    54  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    55  
    56  	run_sql "create table kafka_message.usertable2 like kafka_message.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    57  	run_sql "insert into kafka_message.usertable2 select * from kafka_message.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    58  	run_sql "create table kafka_message.check4(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    59  	check_table_exists "kafka_message.usertable2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    60  	check_table_exists "kafka_message.check4" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    61  
    62  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    63  
    64  	cleanup_process $CDC_BINARY
    65  	stop_tidb_cluster
    66  }
    67  
    68  function run_batch_size_limit() {
    69  	rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    70  
    71  	start_tidb_cluster --workdir $WORK_DIR
    72  
    73  	cd $WORK_DIR
    74  
    75  	run_sql "DROP DATABASE if exists kafka_message;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    76  
    77  	start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1})
    78  	run_sql "CREATE DATABASE kafka_message;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    79  	go-ycsb load mysql -P $CUR/conf/workload -p mysql.host=${UP_TIDB_HOST} -p mysql.port=${UP_TIDB_PORT} -p mysql.user=root -p mysql.db=kafka_message
    80  	run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --loglevel "info"
    81  
    82  	TOPIC_NAME="ticdc-kafka-message-test-$RANDOM"
    83  	SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&max-batch-size=3&kafka-version=${KAFKA_VERSION}&max-message-bytes=10485760"
    84  	run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI"
    85  	if [ "$SINK_TYPE" == "kafka" ]; then
    86  		run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&version=${KAFKA_VERSION}&max-message-bytes=10485760&max-batch-size=3"
    87  	fi
    88  
    89  	# Add a check table to reduce check time, or if we check data with sync diff
    90  	# directly, there maybe a lot of diff data at first because of the incremental scan
    91  	run_sql "CREATE table kafka_message.check1(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    92  	check_table_exists "kafka_message.usertable" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    93  	check_table_exists "kafka_message.check1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
    94  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    95  
    96  	run_sql "truncate table kafka_message.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    97  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    98  	run_sql "CREATE table kafka_message.check2(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    99  	check_table_exists "kafka_message.check2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
   100  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   101  
   102  	go-ycsb load mysql -P $CUR/conf/workload -p mysql.host=${UP_TIDB_HOST} -p mysql.port=${UP_TIDB_PORT} -p mysql.user=root -p mysql.db=kafka_message
   103  	run_sql "CREATE table kafka_message.check3(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
   104  	check_table_exists "kafka_message.check3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
   105  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   106  
   107  	run_sql "create table kafka_message.usertable2 like kafka_message.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
   108  	run_sql "insert into kafka_message.usertable2 select * from kafka_message.usertable" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
   109  	run_sql "create table kafka_message.check4(id int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
   110  	check_table_exists "kafka_message.usertable2" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
   111  	check_table_exists "kafka_message.check4" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 90
   112  
   113  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   114  
   115  	cleanup_process $CDC_BINARY
   116  	stop_tidb_cluster
   117  }
   118  
   119  function run() {
   120  	# test kafka sink only in this case
   121  	if [ "$SINK_TYPE" != "kafka" ]; then
   122  		return
   123  	fi
   124  
   125  	run_length_limit $*
   126  	run_batch_size_limit $*
   127  }
   128  
   129  trap stop_tidb_cluster EXIT
   130  check_logs $WORK_DIR
   131  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"