github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/tiup/upgrade-from-v2.sh (about)

     1  #!/bin/bash
     2  
     3  set -eux
     4  
     5  CLUSTER_NAME="dm-v2"
     6  
     7  PRE_VER=$1
     8  CUR_VER=$2
     9  
    10  CUR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
    11  PATH=$CUR/../_utils:$PATH # for sync_diff_inspector
    12  tiup_dm_operation_log=/tmp/tiup-dm-operation.log
    13  
    14  source $CUR/lib.sh
    15  
    16  function deploy_previous_v2() {
    17  	# install TiUP-DM
    18  	curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
    19  	source /root/.profile
    20  	tiup install dm >>$tiup_dm_operation_log
    21  
    22  	tiup install dmctl:$PRE_VER >>$tiup_dm_operation_log
    23  
    24  	tiup dm deploy --yes $CLUSTER_NAME $PRE_VER $CUR/conf/topo.yaml >>$tiup_dm_operation_log
    25  	tiup dm start --yes $CLUSTER_NAME >>$tiup_dm_operation_log
    26  }
    27  
    28  function migrate_in_previous_v2() {
    29  	exec_full_stage
    30  
    31  	# v2.0.0 doesn't implement relay log.
    32  	# v2.0.1 downgrading has a problem, we use config import which create sources and then create tasks, so for a cluster
    33  	#   1. source is created and bound to a worker.
    34  	#   2. worker starts relay when see the bound and config of the source (after v2.0.2 a manual `start-relay` is needed)
    35  	#      and currently no task created, so it pulls relay log from GTID of SHOW MASTER STATUS, which is later than
    36  	#      expected task checkpoint position. And also v2.0.1 didn't reset to the starting GTID of a binlog file.
    37  	#   3. create task, now the events between checkpoint and SHOW MASTER STATUS in step2 are lost.
    38  	if [[ "$PRE_VER" == "v2.0.0" ]] || [[ "$PRE_VER" == "v2.0.1" ]]; then
    39  		sed -i "s/enable-relay: true/enable-relay: false/g" $CUR/conf/source1.yaml
    40  	fi
    41  
    42  	sed -i "s/enable-heartbeat: true/enable-heartbeat: false/g" $CUR/conf/task.yaml
    43  	sed -i "s/enable-heartbeat: true/enable-heartbeat: false/g" $CUR/conf/task_pessimistic.yaml
    44  	sed -i "s/enable-heartbeat: true/enable-heartbeat: false/g" $CUR/conf/task_optimistic.yaml
    45  
    46  	tiup dmctl:$PRE_VER --master-addr=master1:8261 operate-source create $CUR/conf/source1.yaml
    47  	tiup dmctl:$PRE_VER --master-addr=master1:8261 operate-source create $CUR/conf/source2.yaml
    48  
    49  	tiup dmctl:$PRE_VER --master-addr=master1:8261 start-task $CUR/conf/task.yaml
    50  	tiup dmctl:$PRE_VER --master-addr=master1:8261 start-task $CUR/conf/task_optimistic.yaml
    51  	tiup dmctl:$PRE_VER --master-addr=master1:8261 start-task $CUR/conf/task_pessimistic.yaml
    52  
    53  	ensure_start_relay
    54  
    55  	exec_incremental_stage1
    56  
    57  	# drop table will be skipped
    58  	if [[ "$PRE_VER" != "v2.0.0" ]]; then
    59  		run_sql_tidb_with_retry "select count(*) from opt_db_target.t_target where c1=1000;" "1"
    60  		exec_sql tidb 4000 "delete from opt_db_target.t_target where c1=1000;"
    61  	fi
    62  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    63  
    64  	tiup dmctl:$PRE_VER --master-addr=master1:8261 pause-task $TASK_NAME
    65  
    66  	run_dmctl_with_retry $PRE_VER "query-status" "Running" 2 "Paused" 1
    67  }
    68  
    69  function upgrade_to_current_v2() {
    70  	tiup uninstall dmctl --all
    71  
    72  	tiup install dmctl:v7.5.0 >>$tiup_dm_operation_log
    73  	# config export in PRE_VER
    74  	# on version >= 8.0.0, the `config export` command will connect to the master
    75  	# and fetch the config which previous version doesn't support, so we fix the version to 7.5.0
    76  	tiup dmctl:v7.5.0 --master-addr=master1:8261 config export -d old_configs
    77  
    78  	if [[ "$CUR_VER" == "nightly" && ("$ref" == "refs/pull"* || "$id" != "") ]]; then
    79  		patch_nightly_with_tiup_mirror $PRE_VER
    80  	fi
    81  
    82  	# uninstall previous dmctl, otherwise dmctl:nightly still use PRE_VER.
    83  	# FIXME: It may be a bug in tiup mirror.
    84  
    85  	tiup dm upgrade --yes $CLUSTER_NAME $CUR_VER >>$tiup_dm_operation_log
    86  
    87  	restart_relay
    88  }
    89  
    90  function migrate_in_v2() {
    91  	run_dmctl_with_retry $CUR_VER "query-status" "Running" 2 "Paused" 1
    92  	run_dmctl_with_retry $CUR_VER "shard-ddl-lock" "\"result\": true" 1 "\"task\": \"$TASK_PESS_NAME\"" 1 "\"task\": \"$TASK_OPTI_NAME\"" 1
    93  
    94  	tiup dmctl:$CUR_VER --master-addr=master1:8261 resume-task $TASK_NAME
    95  
    96  	run_dmctl_with_retry $CUR_VER "query-status" "Running" 3
    97  
    98  	exec_incremental_stage2
    99  
   100  	echo "check sources"
   101  	run_dmctl_with_retry $CUR_VER "operate-source show" "mysql-replica-01" 1 "mariadb-replica-02" 1
   102  	echo "check workers"
   103  	run_dmctl_with_retry $CUR_VER "list-member --worker" "\"stage\": \"bound\"" 2
   104  
   105  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   106  	check_sync_diff $WORK_DIR $CUR/conf/diff_config_optimistic.toml
   107  	check_sync_diff $WORK_DIR $CUR/conf/diff_config_pessimistic.toml
   108  
   109  	echo "check locks"
   110  	run_dmctl_with_retry $CUR_VER "shard-ddl-lock" "no DDL lock exists" 1
   111  
   112  	# config export in CUR_VER
   113  	tiup install dmctl:$CUR_VER
   114  	tiup dmctl:$CUR_VER --master-addr=master1:8261 config export -d new_configs
   115  }
   116  
   117  function diff_configs() {
   118  	echo "diff configs between different version"
   119  
   120  	sed '/password/d' old_configs/tasks/upgrade_via_tiup.yaml >/tmp/old_task.yaml
   121  	sed '/password/d' old_configs/tasks/upgrade_via_tiup_pessimistic.yaml >/tmp/old_task_pessimistic.yaml
   122  	sed '/password/d' old_configs/tasks/upgrade_via_tiup_optimistic.yaml >/tmp/old_task_optimistic.yaml
   123  	sed '/password/d' new_configs/tasks/upgrade_via_tiup.yaml >/tmp/new_task.yaml
   124  	sed '/password/d' new_configs/tasks/upgrade_via_tiup_pessimistic.yaml >/tmp/new_task_pessimistic.yaml
   125  	sed '/password/d' new_configs/tasks/upgrade_via_tiup_optimistic.yaml >/tmp/new_task_optimistic.yaml
   126  
   127  	sed '/password/d' old_configs/sources/mysql-replica-01.yaml >/tmp/old_source1.yaml
   128  	sed '/password/d' old_configs/sources/mariadb-replica-02.yaml >/tmp/old_source2.yaml
   129  	sed '/password/d' new_configs/sources/mysql-replica-01.yaml >/tmp/new_source1.yaml
   130  	sed '/password/d' new_configs/sources/mariadb-replica-02.yaml >/tmp/new_source2.yaml
   131  
   132  	diff /tmp/old_task.yaml /tmp/new_task.yaml || exit 1
   133  	diff /tmp/old_task_pessimistic.yaml /tmp/new_task_pessimistic.yaml || exit 1
   134  	diff /tmp/old_task_optimistic.yaml /tmp/new_task_optimistic.yaml || exit 1
   135  	diff /tmp/old_source1.yaml /tmp/new_source1.yaml || exit 1
   136  	diff /tmp/old_source2.yaml /tmp/new_source2.yaml || exit 1
   137  }
   138  
   139  function downgrade_to_previous_v2() {
   140  	echo "downgrade to previous version $PRE_VER"
   141  
   142  	# destory current cluster
   143  	tiup dm destroy --yes $CLUSTER_NAME >>$tiup_dm_operation_log
   144  
   145  	exec_incremental_stage3
   146  
   147  	# deploy previous cluster
   148  	tiup dm deploy --yes $CLUSTER_NAME $PRE_VER $CUR/conf/topo.yaml >>$tiup_dm_operation_log
   149  	tiup dm start --yes $CLUSTER_NAME >>$tiup_dm_operation_log
   150  
   151  	# config import
   152  	tiup dmctl:$CUR_VER --master-addr=master1:8261 config import -d new_configs
   153  
   154  	ensure_start_relay
   155  
   156  	exec_incremental_stage4
   157  
   158  	run_dmctl_with_retry $CUR_VER "operate-source show" "mysql-replica-01" 1 "mariadb-replica-02" 1
   159  	run_dmctl_with_retry $CUR_VER "list-member --worker" "\"stage\": \"bound\"" 2
   160  
   161  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   162  	check_sync_diff $WORK_DIR $CUR/conf/diff_config_optimistic.toml
   163  	check_sync_diff $WORK_DIR $CUR/conf/diff_config_pessimistic.toml
   164  }
   165  
   166  function destroy_v2_by_tiup() {
   167  	export DM_MASTER_ADDR="master1:8261"
   168  	tiup dmctl:$CUR_VER stop-task $TASK_NAME
   169  	tiup dm destroy --yes $CLUSTER_NAME >>$tiup_dm_operation_log
   170  }
   171  
   172  function test() {
   173  	install_sync_diff
   174  
   175  	deploy_previous_v2
   176  
   177  	migrate_in_previous_v2
   178  
   179  	upgrade_to_current_v2
   180  
   181  	migrate_in_v2
   182  
   183  	diff_configs
   184  
   185  	downgrade_to_previous_v2
   186  
   187  	destroy_v2_by_tiup
   188  }
   189  
   190  test