From f8e60d72f7eaae03400b50ce5569a13867e30b94 Mon Sep 17 00:00:00 2001 From: xue_meng_en <1836611252@qq.com> Date: Wed, 12 Jun 2024 16:01:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=85=E7=90=86=E7=BA=A7?= =?UTF-8?q?=E8=81=94=E5=A4=87=E5=A4=8D=E5=88=B6=E6=A7=BD=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/ha/standby_env.sh | 9 +- src/test/ha/testcase/cascade/clean_slot.sh | 114 ++++++++++++++------- 2 files changed, 86 insertions(+), 37 deletions(-) diff --git a/src/test/ha/standby_env.sh b/src/test/ha/standby_env.sh index 253370391..b7bc0764d 100644 --- a/src/test/ha/standby_env.sh +++ b/src/test/ha/standby_env.sh @@ -104,11 +104,18 @@ function query_standby2() function query_standby3() { - echo query standby2 + echo query standby3 gs_ctl query -D $data_dir/datanode3_standby } +function query_standby4() +{ + echo query standby4 + gs_ctl query -D $standby4_data_dir + +} + function check_primary_startup() { echo checking primary startup diff --git a/src/test/ha/testcase/cascade/clean_slot.sh b/src/test/ha/testcase/cascade/clean_slot.sh index 1d089266e..793e4dbfc 100644 --- a/src/test/ha/testcase/cascade/clean_slot.sh +++ b/src/test/ha/testcase/cascade/clean_slot.sh @@ -1,52 +1,94 @@ +# This use case is used to test whether the primary can properly clean up the replication slots corresponding to the cascade standby. + #!/bin/sh - source ./util.sh - -function check_select_result() + +standby_mounted_cascade_datadir="" +standby_mounted_cascade_port="" +ports=($dn1_primary_port $standby1_port $standby2_port $standby3_port $standby4_port) +datadirs=($primary_data_dir $standby1_data_dir $standby2_data_dir $standby3_data_dir $standby4_data_dir) + +function query_standby_mounted_cascade() { - if [ $(echo $result | grep "${1}" | wc -l) -eq 1 ]; then - echo "remote read successful" + standby_mounted_cascade_datadir="" + standby_mounted_cascade_port="" + for (( i=0; i<5; i++ )); do + local result=`gsql -tA -d $db -p ${ports[i]} -c "select count(*) from pg_get_replication_slots() where slot_name='dn_s4' and active='t';"` + if [[ X"${result}" = X"1" ]]; then + standby_mounted_cascade_datadir=${datadirs[i]} + standby_mounted_cascade_port=${ports[i]} + break + fi + done +} + +function check_clean_cascade_slot_result() +{ + local port=$1 + local result=`gsql -tA -d $db -p $port -c "select count(*) from pg_get_replication_slots() where slot_name='dn_s4' and active='f';"` + if [[ "${result}" = "0" ]]; then + echo "primary cleaned cascade slot successfully." else - echo "remote read failed $failed_keyword with [$result]" + echo "cascade slot still exists in primary! " + echo "clean cascade slot test failed $failed_keyword with [$result]." + echo "cascade slot info:" + gsql -d $db -p $port -c "select * from pg_get_replication_slots() where slot_name='dn_s4' and active='f';" exit 1 fi } - -function check_select_no_result() -{ - if [ $(echo $result | grep "${1}" | wc -l) -eq 0 ]; then - echo "remote read successful" - else - echo "remote read failed $failed_keyword with [$result]" - exit 1 - fi -} - + function test_cascade_standby_clean_slot_func() { set_default - + + # The initial state of the cluster is 1 primary and 4 standbies. + + # start standby4 as cascade echo "base" - result=`gsql -d $db -p $dn1_primary_port -c "select * from pg_get_replication_slots();"` - check_select_result "dn_s2" - - kill_cascade_cluster - start_cascade_cluster - - - result=`gsql -d $db -p $dn1_primary_port -c "select * from pg_get_replication_slots();"` - check_select_no_result "dn_s2" - - switchover_to_cascade_standby - - result=`gsql -d $db -p $dn1_primary_port -c "select * from pg_get_replication_slots();"` - check_select_no_result "dn_s1" - + gs_ctl build -D $standby4_data_dir -M cascade_standby + sleep 1 + + query_primary + query_multi_standby + + # case 1 + check_clean_cascade_slot_result $dn1_primary_port + echo "case 1 passed" + + # case 2 https://gitee.com/opengaussorg/dashboard?issue_id=I9JWCD + query_standby_mounted_cascade + gs_ctl switchover -D $standby_mounted_cascade_datadir + sleep 3 + check_clean_cascade_slot_result $standby_mounted_cascade_port + sleep 1 + gs_ctl switchover -D $primary_data_dir + sleep 3 + check_clean_cascade_slot_result $dn1_primary_port + echo "case 2 passed" + + # case 3 https://gitee.com/opengaussorg/dashboard?issue_id=I9VA9H&from=project-issue + query_primary + query_multi_standby + query_standby_mounted_cascade + gs_ctl stop -D $standby_mounted_cascade_datadir + sleep 1 + query_standby4 + gs_ctl start -D $standby_mounted_cascade_datadir -M standby + sleep 3 + local result=`gsql -tA -d $db -p $standby_mounted_cascade_port -c "select count(*) from pg_get_replication_slots() where slot_name='dn_s4' and active='f';"` + if [[ "$result" != "1" ]]; then + echo "$failed_keyword with [$result]" + exit 1 + fi + gs_ctl switchover -D $standby_mounted_cascade_datadir + sleep 3 + check_clean_cascade_slot_result $standby_mounted_cascade_port + echo "case 3 passed" } - + function tear_down() { - set_cascade_default + set_default } - + test_cascade_standby_clean_slot_func tear_down \ No newline at end of file