From 135fb3d5b8d63cfc1145cafc4f1870719c9d0a1e Mon Sep 17 00:00:00 2001 From: wangbo Date: Wed, 29 Jul 2026 03:46:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E5=BB=B6=E9=95=BF=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=89=AF=E6=9C=AC=E9=87=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=97=A8=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CNPG 主库在 5 秒内晋升,但跨地域 pg_rewind 需要重传约 1.27GB,原 6 分钟等待不足。将同步副本恢复等待扩展到 30 分钟,并增加退出时清理写入探针的保护。\n\n已通过 bash -n、ShellCheck 和 git diff --check。 --- scripts/cluster/failure-drill.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/cluster/failure-drill.sh b/scripts/cluster/failure-drill.sh index 88bf7e5..edb2a27 100755 --- a/scripts/cluster/failure-drill.sh +++ b/scripts/cluster/failure-drill.sh @@ -51,10 +51,16 @@ case $drill in cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- "$new_primary" <<'REMOTE' set -euo pipefail primary=$1 +cleanup_probe() { + k3s kubectl exec -n easyai "$primary" -c postgres -- \ + psql -X -U postgres -d easyai_ai_gateway -c \ + "DELETE FROM system_settings WHERE setting_key='ha_acceptance_probe';" >/dev/null 2>&1 || true +} +trap cleanup_probe EXIT HUP INT TERM k3s kubectl exec -n easyai "$primary" -c postgres -- \ psql -X -v ON_ERROR_STOP=1 -U postgres -d easyai_ai_gateway -c \ "INSERT INTO system_settings(setting_key,value) VALUES('ha_acceptance_probe',jsonb_build_object('at',now())) ON CONFLICT(setting_key) DO UPDATE SET value=excluded.value,updated_at=now();" >/dev/null -for _ in $(seq 1 180); do +for _ in $(seq 1 900); do if [[ $(k3s kubectl get cluster easyai-postgres -n easyai -o jsonpath='{.status.readyInstances}') == 2 ]]; then replication=$(k3s kubectl exec -n easyai "$primary" -c postgres -- \ psql -X -U postgres -d easyai_ai_gateway -At -c \ @@ -67,6 +73,7 @@ done k3s kubectl exec -n easyai "$primary" -c postgres -- \ psql -X -v ON_ERROR_STOP=1 -U postgres -d easyai_ai_gateway -c \ "DELETE FROM system_settings WHERE setting_key='ha_acceptance_probe';" >/dev/null +trap - EXIT HUP INT TERM REMOTE echo "database_failure_drill=PASS promotion_seconds=$elapsed old_primary=$old_primary new_primary=$new_primary" ;;