Shadow PostgreSQL promotion database preflight

This commit is contained in:
Lyncoln
2026-09-17 22:54:26 -04:00
parent 64501a927b
commit 4229008216
4 changed files with 97 additions and 2 deletions
@@ -1,5 +1,63 @@
# Sourced by managed-container; uses the shared OCF and parameter environment.
mc_pg_promote_database_shadow()
{
local socket_path resource response rc
socket_path="${MC_PROXY_SOCKET:-/run/user/1000/managed-containerd/managed-containerd.sock}"
resource="${OCF_RESOURCE_INSTANCE:-}"
resource="${resource%%:*}"
# Standalone/resource-agent tests may not have a real resource identity.
[ -n "${resource}" ] || return 0
if response="$(
timeout --kill-after=1s 5s \
python3 \
"${MC_PROXY_CLIENT:-/usr/lib/ocf/resource.d/loxthelion/managed-container.d/proxy_client.py}" \
"${socket_path}" \
"${resource}" \
"promote.database" \
10 \
11
)"; then
rc=0
else
rc=$?
fi
if [ "${rc}" -ne 0 ]; then
ocf_log warn \
"managed-containerd promote.database shadow unavailable rc=${rc}"
return 0
fi
if MC_DAEMON_RESPONSE="${response}" python3 -c '
import json
import os
response = json.loads(os.environ["MC_DAEMON_RESPONSE"])
if (
response.get("ocf_rc") != 0
or response.get("ready") is not True
or response.get("mutation") is not False
):
raise SystemExit(1)
'; then
ocf_log info \
"managed-containerd promote.database shadow: comparison=MATCH response=${response}"
else
ocf_log err \
"managed-containerd promote.database shadow MISMATCH response=${response}"
fi
# Shadow-only milestone: daemon disagreement must not alter the
# authoritative native promotion result yet.
return 0
}
managed_promote()
{
local monitor_rc role i
@@ -58,6 +116,11 @@ managed_promote()
ocf_log info \
"Promoting PostgreSQL standby inside ${CONTAINER_NAME}"
# Independent managed-containerd promotion preflight.
# Shadow-only for now: disagreement is logged but does not block
# the authoritative native PostgreSQL promotion.
mc_pg_promote_database_shadow
if ! pg_command '
BINDIR="$(pg_config --bindir)" || exit 1
exec "$BINDIR/pg_ctl" \