feat(ops): M8.8 World0 acknowledgment gate and host-loss recovery (ADR-0075)
Ratifies dev/stage RPO/RTO from measurements and keeps World0 launch blocked (policy-enforced) until acknowledged outcomes survive host loss in an independent failure domain. Adds in-place restore with an explicit rewind, barrier-based fencing of a superseded database, and promotion of stage-pinned digests only. dr-check.sh rehearses host loss in every PostgreSQL build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
# M8.7 verified restore of a backup bundle (ADR-0074) onto independent storage.
|
||||
#
|
||||
# tools/backup/restore-world.sh --bundle DIR --objects DIR
|
||||
# [--in-place --runtime-role ROLE --accept-rewind]
|
||||
#
|
||||
# Target connection: PG* environment naming an EMPTY database that the login owns
|
||||
# (PGHOST/PGPORT/PGDATABASE/PGUSER, or PGSERVICE with PGSERVICEFILE/PGPASSFILE).
|
||||
# The restore needs no source role, credential or key: the dump carries no owners
|
||||
# or grants, so the target login owns everything restored. --objects must not
|
||||
# The restore needs no source role, credential or key: owners and grants are not
|
||||
# restored, so the target login owns everything restored. --objects must not
|
||||
# exist yet (it is created 0700). evo-world-clone comes from EVO_WORLD_CLONE_BIN or
|
||||
# PATH.
|
||||
#
|
||||
@@ -22,18 +23,42 @@
|
||||
# so an unverified restore can never be mistaken for a world. The result is a
|
||||
# verbatim, owner-only copy with the source's world identities: it has no runtime
|
||||
# grants and is never served. To run it, clone it into an isolated world
|
||||
# (tools/backup/verify-backup.sh --isolate); host-loss recovery in place is M8.8.
|
||||
# (tools/backup/verify-backup.sh --isolate).
|
||||
#
|
||||
# --in-place (M8.8 host-loss recovery for dev/stage, ADR-0075) restores the world
|
||||
# under its own identity so its hosts can serve it again: the dump's grants are
|
||||
# restored (the environment's roles must already exist in the target cluster), every
|
||||
# restored lease is fenced so a new owner acquires under a newer epoch, and
|
||||
# migrate-postgres.sh audits the runtime role's effective rights. Every acknowledgement
|
||||
# after the bundle's cut is undone: deaths may reverse and resources may reappear.
|
||||
# --accept-rewind states that this is acceptable, which it is for dev and stage only;
|
||||
# World0 launch stays blocked until acknowledgements survive host loss (ADR-0075).
|
||||
# Fence the old database with fence-database.sh before any of its hosts can return.
|
||||
set -euo pipefail
|
||||
usage() { echo "usage: $0 --bundle DIR --objects DIR" >&2; exit 2; }
|
||||
bundle="" objects=""
|
||||
usage() {
|
||||
echo "usage: $0 --bundle DIR --objects DIR [--in-place --runtime-role ROLE --accept-rewind]" >&2
|
||||
exit 2
|
||||
}
|
||||
bundle="" objects="" in_place=0 runtime_role="" accept_rewind=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--bundle) bundle="${2:-}"; shift 2 ;;
|
||||
--objects) objects="${2:-}"; shift 2 ;;
|
||||
--in-place) in_place=1; shift ;;
|
||||
--runtime-role) runtime_role="${2:-}"; shift 2 ;;
|
||||
--accept-rewind) accept_rewind=1; shift ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
[ -n "$bundle" ] && [ -n "$objects" ] || usage
|
||||
if [ "$in_place" = 1 ]; then
|
||||
[ -n "$runtime_role" ] || { echo "--in-place needs --runtime-role" >&2; exit 2; }
|
||||
[ "$accept_rewind" = 1 ] ||
|
||||
{ echo "--in-place undoes every acknowledgement after the backup; pass --accept-rewind (dev/stage only)" >&2; exit 2; }
|
||||
elif [ -n "$runtime_role" ] || [ "$accept_rewind" = 1 ]; then
|
||||
usage
|
||||
fi
|
||||
root="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
bundle="$(realpath -- "$bundle")" objects="$(realpath -m -- "$objects")"
|
||||
clone_bin="${EVO_WORLD_CLONE_BIN:-evo-world-clone}"
|
||||
umask 077
|
||||
@@ -58,6 +83,11 @@ done <<< "$present"
|
||||
grep -qx 'format aevolution-backup-v1' "$bundle/MANIFEST" || refuse "unknown bundle format"
|
||||
expected_heads="$(grep '^head ' "$bundle/MANIFEST" | cut -d' ' -f2- | sort)"
|
||||
[ -n "$expected_heads" ] || refuse "manifest names no region"
|
||||
privileges=(--no-privileges)
|
||||
if [ "$in_place" = 1 ]; then
|
||||
grep -qx 'dump privileges' "$bundle/MANIFEST" || refuse "bundle predates in-place restore (no grants in its dump)"
|
||||
privileges=()
|
||||
fi
|
||||
|
||||
# 2. Target: empty, same server version.
|
||||
[ ! -e "$objects" ] || refuse "objects target already exists: $objects"
|
||||
@@ -79,7 +109,7 @@ trap cleanup EXIT
|
||||
target="${PGDATABASE:-}"
|
||||
[ -n "${PGSERVICE:-}" ] && target="service=$PGSERVICE"
|
||||
[ -n "$target" ] || { echo "set PGDATABASE or PGSERVICE for the target" >&2; exit 2; }
|
||||
pg_restore --no-password --exit-on-error --single-transaction --no-owner --no-privileges \
|
||||
pg_restore --no-password --exit-on-error --single-transaction --no-owner "${privileges[@]}" \
|
||||
--dbname="$target" "$bundle/database.dump"
|
||||
mkdir -m 700 -- "$objects"
|
||||
(cd "$bundle/objects" && find . -mindepth 2 -maxdepth 2 -type d -printf '%P\0' |
|
||||
@@ -117,5 +147,18 @@ while read -r world region _ _ tick _; do
|
||||
commits=$((commits + BASH_REMATCH[1]))
|
||||
echo "region $world/$region $line"
|
||||
done <<< "$expected_heads"
|
||||
if [ "$in_place" = 1 ]; then
|
||||
# No lease from before the loss survives: the next owner acquires a newer epoch.
|
||||
psql -X --no-password -q -v ON_ERROR_STOP=1 -c \
|
||||
'UPDATE evolution.region_leases SET holder = NULL, expires_at = NULL WHERE holder IS NOT NULL' > /dev/null
|
||||
EVO_PG_RUNTIME_ROLE="$runtime_role" bash "$root/tools/migrate-postgres.sh" > /dev/null ||
|
||||
{ echo "runtime role $runtime_role failed the rights audit" >&2; exit 3; }
|
||||
created="$(sed -n 's/^created //p' "$bundle/MANIFEST")"
|
||||
while read -r world region _ _ tick _; do
|
||||
echo "REWIND region $world/$region restored at tick $tick (backup $created): every acknowledgement after this tick is undone"
|
||||
done <<< "$expected_heads"
|
||||
fi
|
||||
restored=1
|
||||
echo "RESTORE VERIFIED regions=$(wc -l <<< "$expected_heads") commits=$commits duration_ms=$(( $(date +%s%3N) - begin_ms ))"
|
||||
what="RESTORE VERIFIED"
|
||||
[ "$in_place" = 1 ] && what="RESTORE IN PLACE VERIFIED"
|
||||
echo "$what regions=$(wc -l <<< "$expected_heads") commits=$commits duration_ms=$(( $(date +%s%3N) - begin_ms ))"
|
||||
|
||||
Reference in New Issue
Block a user