1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-18 06:04:06 +03:00

ctdb-tests: Factor out getting leader and waiting for leader change

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2022-01-14 21:47:52 +11:00 committed by Martin Schwenke
parent 4786982cc8
commit 403db5b528
4 changed files with 63 additions and 32 deletions

View File

@ -75,12 +75,10 @@ else
exit 1 exit 1
fi fi
echo "Find out which node is recmaster" echo
try_command_on_node 0 $CTDB recmaster leader_get 0
recmaster="$out"
# Set RecBufferSizeLimit to 10000 # Set RecBufferSizeLimit to 10000
try_command_on_node $recmaster $CTDB setvar RecBufferSizeLimit 10000 ctdb_onnode "$leader" setvar RecBufferSizeLimit 10000
# Do a recovery # Do a recovery
echo "force recovery" echo "force recovery"

View File

@ -8,22 +8,13 @@ set -e
ctdb_test_init ctdb_test_init
echo "Finding out which node is the recovery master..." leader_get 0
try_command_on_node -v 0 "$CTDB recmaster"
test_node=$out
echo "Stopping node ${test_node} - it is the current recmaster..." # leader set by leader_get()
try_command_on_node 1 $CTDB stop -n $test_node # shellcheck disable=SC2154
echo "Stopping leader ${leader}..."
ctdb_onnode 1 stop -n "$leader"
wait_until_node_has_status $test_node stopped wait_until_node_has_status "$leader" stopped
echo "Checking which node is the recovery master now..." wait_until_leader_has_changed 0
try_command_on_node -v 0 "$CTDB recmaster"
recmaster=$out
if [ "$recmaster" != "$test_node" ] ; then
echo "OK: recmaster moved to node $recmaster"
else
echo "BAD: recmaster did not move"
exit 1
fi

View File

@ -54,11 +54,7 @@ echo "Recovery lock setting is \"${reclock_setting}\""
echo "Recovery lock file is \"${reclock}\"" echo "Recovery lock file is \"${reclock}\""
echo echo
echo "Get current recovery master" leader_get "$test_node"
ctdb_onnode "$test_node" recmaster
recmaster="$out"
echo "Recovery master is node ${recmaster}"
echo
echo "Get initial generation" echo "Get initial generation"
ctdb_onnode "$test_node" status ctdb_onnode "$test_node" status
@ -79,15 +75,17 @@ echo
echo "Generation changed to ${generation_new}" echo "Generation changed to ${generation_new}"
echo echo
echo "Get current recovery master" # shellcheck disable=SC2154
ctdb_onnode "$test_node" recmaster # $leader set by leader_get() above
recmaster_new="$out" leader_old="$leader"
if [ "$recmaster" != "$recmaster_new" ] ; then leader_get "$test_node"
if [ "$leader" != "$leader_old" ] ; then
ctdb_test_fail \ ctdb_test_fail \
"BAD: Recovery master has changed to node ${recmaster_new}" "BAD: Leader has changed to node ${leader}"
fi fi
echo "GOOD: Recovery master is still node ${recmaster_new}" echo "GOOD: Leader is still node ${leader}"
echo echo
cluster_is_healthy cluster_is_healthy

View File

@ -644,6 +644,50 @@ ctdb_base_show ()
####################################### #######################################
# sets: leader
_leader_get ()
{
local node="$1"
ctdb_onnode "$node" recmaster
# shellcheck disable=SC2154
# $out set by ctdb_onnode() above
leader="$out"
}
leader_get ()
{
local node="$1"
echo "Get leader"
_leader_get "$node"
echo "Leader is ${leader}"
echo
}
_leader_has_changed ()
{
local node="$1"
local leader_old="$2"
_leader_get "$node"
[ "$leader" != "$leader_old" ]
}
# uses: leader
wait_until_leader_has_changed ()
{
local node="$1"
echo
echo "Wait until leader changes..."
wait_until 30 _leader_has_changed "$node" "$leader"
echo "Leader changed to ${leader}"
}
#######################################
wait_for_monitor_event () wait_for_monitor_event ()
{ {
local pnn="$1" local pnn="$1"