takeip)
nfs_callout "$@" || exit $?
+ if [ -x "${CTDB_HELPER_BINDIR}/statd_callout_helper" ] ; then
+ "${CTDB_HELPER_BINDIR}/statd_callout_helper" takeip "$3"
+ fi
ctdb_service_set_reconfigure
;;
nfs_load_config
- ctdb_get_my_public_addresses |
- while read -r _ _sip _; do
+ find "$state_dir" -name "takeip@${FAKE_CTDB_PNN}@*" |
+ while read -r _f; do
+ _sip="${_f##*@}"
_prefix="mon@${_sip}@"
find "$state_dir" -name "${_prefix}*" |
while read -r _f; do
EOF
rm -f "$_f"
done
- done | {
+ done |
+ sort | {
ok
simple_test_event "notify"
} || exit $?
rm -f "${state_dir}/mon@${_sip}@${1}"
done
;;
+ takeip)
+ cmd="${CTDB_SCRIPTS_TOOLS_HELPER_DIR}/statd_callout_helper"
+ script_test "$cmd" "$event" "$@"
+ touch "${state_dir}/takeip@${FAKE_CTDB_PNN}@${1}"
+ ;;
notify)
cmd="${CTDB_SCRIPTS_TOOLS_HELPER_DIR}/statd_callout_helper"
script_test "$cmd" "$event" "$@"
+ rm -f "${state_dir}/takeip@${FAKE_CTDB_PNN}@"*
;;
*)
cmd="${CTDB_SCRIPTS_TOOLS_HELPER_DIR}/statd_callout_helper"
ok_null
simple_test_event "startup"
+ctdb_get_my_public_addresses |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
simple_test_event "add-client" "192.168.123.45"
simple_test_event "update"
ok_null
simple_test_event "startup"
+ctdb_get_my_public_addresses |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
simple_test_event "add-client" "192.168.123.45"
simple_test_event "update"
ok_null
simple_test_event "startup"
+ctdb_get_my_public_addresses |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
simple_test_event "add-client" "192.168.123.46"
simple_test_event "update"
ok_null
simple_test_event "startup"
+ctdb_get_my_public_addresses |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
simple_test_event "add-client" "192.168.123.45"
simple_test_event "update"
ok_null
simple_test_event "startup"
+ctdb_get_my_public_addresses |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
simple_test_event "add-client" "192.168.123.46"
simple_test_event "update"
--- /dev/null
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+if [ -z "$CTDB_STATD_CALLOUT_SHARED_STORAGE" ]; then
+ CTDB_STATD_CALLOUT_SHARED_STORAGE="persistent_db"
+fi
+mode="$CTDB_STATD_CALLOUT_SHARED_STORAGE"
+
+define_test "${mode} - add-client on different nodes, take 1 IP, notify on both"
+
+setup "$mode"
+
+ok_null
+simple_test_event "startup"
+ctdb_get_1_public_address |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
+simple_test_event "add-client" "192.168.123.45"
+simple_test_event "update"
+
+ctdb_set_pnn 1
+
+ok_null
+simple_test_event "startup"
+ctdb_get_1_public_address |
+ while read -r _ sip _; do
+ simple_test_event "takeip" "$sip"
+ done
+simple_test_event "add-client" "192.168.123.46"
+simple_test_event "update"
+
+ctdb_set_pnn 0
+
+check_statd_callout_smnotify
+
+ctdb_set_pnn 1
+
+check_statd_callout_smnotify
+
+check_shared_storage_statd_state
--- /dev/null
+#!/bin/sh
+
+CTDB_STATD_CALLOUT_SHARED_STORAGE="shared_dir"
+
+_dir=$(dirname "$0")
+. "${_dir}/statd-callout.008.sh"
--- /dev/null
+#!/bin/sh
+
+CTDB_STATD_CALLOUT_SHARED_STORAGE="none"
+
+_dir=$(dirname "$0")
+. "${_dir}/statd-callout.008.sh"
# script_state_dir set by ctdb_setup_state_dir()
# shellcheck disable=SC2154
statd_callout_state_dir="${script_state_dir}/statd_callout"
+statd_new_ips_file="${statd_callout_state_dir}/new_ips.txt"
# Set default value, if necessary
: "${CTDB_STATD_CALLOUT_SHARED_STORAGE:=persistent_db}"
persistent_db_make_grep_filter()
{
+ _ips_file="$1"
while read -r _ip; do
echo "statd-state@${_ip}@"
- done <"$CTDB_MY_PUBLIC_IPS_CACHE" >"$persistent_db_grep_filter"
+ done <"$_ips_file" >"$persistent_db_grep_filter"
}
update_persistent_db()
exit 0
fi
- persistent_db_make_grep_filter
+ persistent_db_make_grep_filter "$CTDB_MY_PUBLIC_IPS_CACHE"
# Use cat instead of direct grep since POSIX grep does not
# have -h
list_records_persistent_db()
{
- persistent_db_make_grep_filter
+ persistent_db_make_grep_filter "$statd_new_ips_file"
+ # Redirect below to /dev/null is because some versions of grep
+ # appear to not drain the input if the file passed to -f is
+ # empty (so it matches nothing). This can cause the first sed
+ # command in the pipeline to exit with EPIPE.
$CTDB catdb "$statd_callout_db" |
- sed -n -e 's|^key([0-9]*) = "\([^"]*\)".*|\1|p' |
+ sed -n -e 's|^key([0-9]*) = "\([^"]*\)".*|\1|p' 2>/dev/null |
grep -F -f "$persistent_db_grep_filter" |
sed -e 's|statd-state@\([^@]*\)@\(.*\)|\1 \2|'
:
}
+save_ip()
+{
+ _ip_addr=$1
+ _f="$statd_new_ips_file"
+ _lock="${_f}.lock"
+ _new="${_f}.new.$$"
+ {
+ flock --timeout 10 9 ||
+ die "statd_callout_helper save_ip: timeout"
+
+ cat "$_f" 2>/dev/null >"$_new"
+ echo "$_ip_addr" >>"$_new"
+ mv "$_new" "$_f"
+ } 9>"$_lock"
+}
+
list_records_shared_dir()
{
while read -r _ip; do
ls "${statd_callout_shared_dir}/statd-state@${_ip}@"*
- done <"$CTDB_MY_PUBLIC_IPS_CACHE" |
+ done <"${statd_new_ips_file}" |
while read -r _f; do
if [ ! -f "$_f" ]; then
continue
mkdir -p "$statd_callout_state_dir"
+ # Create an empty file. Some of the code that processes the
+ # file can't cope with a missing file, which can happen if a
+ # node doesn't take any IPs between takeover runs.
+ : >"${statd_new_ips_file}"
+
"startup_${statd_callout_mode}" "$_config_file"
}
update
;;
+takeip)
+ _ip_addr=$2
+ save_ip "$_ip_addr"
+ ;;
+
notify)
# we must restart the lockmanager (on all nodes) so that we get
# a clusterwide grace period (so other clients don't take out
statd_state="${statd_callout_state_dir}/.statd_state"
list_records >"$statd_state"
+ # Empty the file but don't remove it - see comment in startup()
+ : >"${statd_new_ips_file}"
if [ ! -s "$statd_state" ]; then
rm -f "$statd_state"