fix(deploy): 延长数据库副本重同步门限

CNPG 主库在 5 秒内晋升,但跨地域 pg_rewind 需要重传约 1.27GB,原 6 分钟等待不足。将同步副本恢复等待扩展到 30 分钟,并增加退出时清理写入探针的保护。\n\n已通过 bash -n、ShellCheck 和 git diff --check。
This commit is contained in:
2026-07-29 03:46:16 +08:00
parent ea33be5d69
commit 135fb3d5b8
+8 -1
View File
@@ -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"
;;