diff --git a/addons/mariadb/scripts-ut-spec/galera_memberleave_removed_spec.sh b/addons/mariadb/scripts-ut-spec/galera_memberleave_removed_spec.sh new file mode 100644 index 0000000000..0313ee2cab --- /dev/null +++ b/addons/mariadb/scripts-ut-spec/galera_memberleave_removed_spec.sh @@ -0,0 +1,52 @@ +# shellcheck shell=sh +# +# H10: the galera memberLeave action was a silent no-op — it ran in the +# kbagent execution face (no mariadb client), all SQL guarded with +# `2>/dev/null || true`, so its claimed FLUSH TABLES / wsrep_desync=ON never +# executed. Galera evicts a departed node natively (keepalive timeout) and +# the shutdown-time graceful leave (final seqno + safe_to_bootstrap, clean +# InnoDB flush) is handled by the mariadb container preStop, which runs +# in-container against 127.0.0.1. The broken action + its script were removed. + +Describe "galera memberLeave removal (H10)" + CMPD_GALERA="${SHELLSPEC_CWD:?}/addons/mariadb/templates/cmpd-galera.yaml" + CFGMAP_GALERA="${SHELLSPEC_CWD:?}/addons/mariadb/templates/configmap-scripts-galera.yaml" + SCRIPTS_DIR="${SHELLSPEC_CWD:?}/addons/mariadb/scripts" + + It "cmpd-galera declares no memberLeave lifecycle action" + When run sh -c "grep -E '^[[:space:]]*memberLeave:' '${CMPD_GALERA}' || true" + The status should be success + The output should equal "" + End + + It "cmpd-galera does not reference the removed galera-member-leave.sh" + When run sh -c "grep -F 'galera-member-leave.sh' '${CMPD_GALERA}' || true" + The status should be success + The output should equal "" + End + + It "galera scripts ConfigMap does not mount galera-member-leave.sh" + When run sh -c "grep -F 'galera-member-leave.sh' '${CFGMAP_GALERA}' || true" + The status should be success + The output should equal "" + End + + It "the galera-member-leave.sh script file is gone" + When run sh -c "test ! -e '${SCRIPTS_DIR}/galera-member-leave.sh' && echo GONE" + The status should be success + The output should equal "GONE" + End + + It "graceful-leave intent is still covered by the galera preStop (in-container)" + # The shutdown-time graceful leave lives in the mariadb container preStop. + When run sh -c "grep -c 'preStop:' '${CMPD_GALERA}'" + The status should be success + The output should equal "1" + End + + It "preStop performs the in-container graceful shutdown SQL" + When run sh -c "grep -F 'SET GLOBAL wsrep_on=OFF' '${CMPD_GALERA}'" + The status should be success + The output should include "wsrep_on=OFF" + End +End diff --git a/addons/mariadb/scripts/galera-member-leave.sh b/addons/mariadb/scripts/galera-member-leave.sh deleted file mode 100644 index c313e53aaa..0000000000 --- a/addons/mariadb/scripts/galera-member-leave.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# Called by KubeBlocks before a Galera node is removed. -# Perform a graceful eviction: flush tables and let the cluster -# detect the node's departure via keepalive timeout. - -set -e - -mariadb_cmd() { mariadb "-u${MARIADB_ROOT_USER}" "-p${MARIADB_ROOT_PASSWORD}" -P3306 -h127.0.0.1 -s "$@"; } - -echo "Gracefully evicting ${POD_NAME:-this node} from Galera cluster..." - -# Flush tables to ensure a clean state before shutdown -mariadb_cmd -e "FLUSH TABLES;" 2>/dev/null || true - -# Set wsrep_desync=ON to avoid being selected as a SST donor during shutdown -mariadb_cmd -e "SET GLOBAL wsrep_desync=ON;" 2>/dev/null || true - -echo "Member leave preparation complete. Node will be evicted on shutdown." -exit 0 diff --git a/addons/mariadb/templates/cmpd-galera.yaml b/addons/mariadb/templates/cmpd-galera.yaml index 199f0339d9..3cf776f038 100644 --- a/addons/mariadb/templates/cmpd-galera.yaml +++ b/addons/mariadb/templates/cmpd-galera.yaml @@ -135,12 +135,14 @@ spec: command: - /bin/sh - /scripts/galera-member-join.sh - memberLeave: - exec: - container: mariadb - command: - - /bin/sh - - /scripts/galera-member-leave.sh + # No memberLeave action: Galera evicts a departed node natively via + # keepalive timeout (down-after group-communication), so no database- + # internal removal step is required. The previous memberLeave ran in the + # kbagent execution face (no mariadb client, all SQL `2>/dev/null || true`), + # so its claimed FLUSH TABLES / wsrep_desync=ON never executed — a silent + # no-op. The graceful-leave that does matter at shutdown (final seqno + + # safe_to_bootstrap, clean InnoDB flush) is handled by the mariadb + # container preStop below, which runs in-container against 127.0.0.1. runtime: # Allow enough time for Galera to write grastate.dat on clean shutdown. # 30s (default) is insufficient when InnoDB has dirty pages to flush. diff --git a/addons/mariadb/templates/configmap-scripts-galera.yaml b/addons/mariadb/templates/configmap-scripts-galera.yaml index cf894b3771..915cef6dfa 100644 --- a/addons/mariadb/templates/configmap-scripts-galera.yaml +++ b/addons/mariadb/templates/configmap-scripts-galera.yaml @@ -11,5 +11,3 @@ data: {{- .Files.Get "scripts/galera-roleprobe.sh" | nindent 4 }} galera-member-join.sh: |- {{- .Files.Get "scripts/galera-member-join.sh" | nindent 4 }} - galera-member-leave.sh: |- - {{- .Files.Get "scripts/galera-member-leave.sh" | nindent 4 }}