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:
@@ -18,7 +18,8 @@
|
||||
# source database or the object volume, and no admission barrier is needed.
|
||||
#
|
||||
# Bundle (DIR): MANIFEST, database.dump (pg_dump custom format, schema `evolution`,
|
||||
# no owners or grants: a restore never needs the source's roles or credentials),
|
||||
# no owners; grants are kept for an in-place restore, ADR-0075, and skipped by every
|
||||
# other restore, which therefore never needs the source's roles or credentials),
|
||||
# objects/w<world>/r<region>/<sha256>, SHA256SUMS over every other file. A source
|
||||
# object whose bytes differ from its name fails the backup.
|
||||
set -euo pipefail
|
||||
@@ -71,7 +72,7 @@ SELECT 'rows', (SELECT count(*) FROM evolution.region_commits),
|
||||
(SELECT count(*) FROM evolution.region_outbox),
|
||||
(SELECT count(*) FROM evolution.region_origins);
|
||||
\setenv EVO_BACKUP_SNAPSHOT :snapshot
|
||||
\! pg_dump --no-password --format=custom --schema=evolution --no-owner --no-privileges --snapshot="$EVO_BACKUP_SNAPSHOT" --file="$EVO_BACKUP_DUMP" && echo 'dumped' || echo 'dump-failed'
|
||||
\! pg_dump --no-password --format=custom --schema=evolution --no-owner --snapshot="$EVO_BACKUP_SNAPSHOT" --file="$EVO_BACKUP_DUMP" && echo 'dumped' || echo 'dump-failed'
|
||||
COMMIT;
|
||||
SQL
|
||||
grep -qx 'dumped' "$out/.cut" || { echo "backup failed: pg_dump did not complete" >&2; exit 3; }
|
||||
@@ -95,6 +96,7 @@ done < <(find "$objects" -mindepth 3 -maxdepth 3 -type f ! -name '.tmp-*' -print
|
||||
echo "format aevolution-backup-v1"
|
||||
echo "created $started"
|
||||
echo "label ${label:--}"
|
||||
echo "dump privileges"
|
||||
grep -E '^(database|schema|build|head|rows) ' "$out/.cut"
|
||||
echo "objects $count $bytes"
|
||||
} > "$out/MANIFEST"
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
# M8.8 supersession fence (ADR-0075): makes a database whose world was restored
|
||||
# elsewhere permanently unable to grant authority again.
|
||||
#
|
||||
# tools/backup/fence-database.sh --superseded-by LABEL --confirm
|
||||
#
|
||||
# Connection: PG* environment naming the OLD database, as its owner (migrator).
|
||||
# Run it as soon as the old database is reachable, before any of its hosts can
|
||||
# return (or immediately, when it never went away).
|
||||
#
|
||||
# It uses the upgrade barrier (ADR-0068), which serializes with every acquisition,
|
||||
# lease check and provisioning. It first retains a supersession identity,
|
||||
# SHA-256("AEVOLUTION-SUPERSEDED-v1"), which no image digest can equal, and then
|
||||
# retires every other build. Each retirement fences every lease. So:
|
||||
# - a running host's next lease check or commit fails, and it re-acquires;
|
||||
# - no retained build remains current, so every acquisition is refused and the
|
||||
# host quarantines (evo-server exit 4);
|
||||
# - a commit that names a retired build is refused by the trigger.
|
||||
# History, objects and heads are untouched. The database stays readable for audits
|
||||
# and for comparing what was lost. The heads at the moment of fencing are printed:
|
||||
# they are the old environment's final state, and record what the restore rewound.
|
||||
# Undoing this means deliberately retaining a new build as owner: that is an
|
||||
# unfencing decision, not an operation.
|
||||
set -euo pipefail
|
||||
usage() { echo "usage: $0 --superseded-by LABEL --confirm" >&2; exit 2; }
|
||||
label="" confirm=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--superseded-by) label="${2:-}"; shift 2 ;;
|
||||
--confirm) confirm=1; shift ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
[[ "$label" =~ ^[A-Za-z0-9._:-]+$ ]] && [ "$confirm" = 1 ] || usage
|
||||
if [ -n "${EVO_PGPASS_SOURCE:-}" ]; then
|
||||
umask 077
|
||||
export PGPASSFILE
|
||||
PGPASSFILE="$(mktemp /tmp/evo-pgpass.XXXXXXXX)"
|
||||
trap 'rm -f -- "$PGPASSFILE"' EXIT
|
||||
cat "$EVO_PGPASS_SOURCE" > "$PGPASSFILE"
|
||||
fi
|
||||
psql -X --no-password -q -A -t -F ' ' -v ON_ERROR_STOP=1 -v "label=$label" <<'SQL'
|
||||
BEGIN;
|
||||
INSERT INTO evolution.retained_builds(build_identity)
|
||||
VALUES (sha256(convert_to('AEVOLUTION-SUPERSEDED-v1', 'UTF8')))
|
||||
ON CONFLICT (build_identity) DO NOTHING;
|
||||
SELECT 'retired', encode(b.build_identity, 'hex'), evolution.upgrade_barrier(b.build_identity)
|
||||
FROM evolution.retained_builds b
|
||||
WHERE b.retired_at IS NULL
|
||||
AND b.build_identity <> sha256(convert_to('AEVOLUTION-SUPERSEDED-v1', 'UTF8'))
|
||||
ORDER BY b.build_identity;
|
||||
SELECT 'current', count(*) FROM evolution.retained_builds b
|
||||
WHERE b.retired_at IS NULL
|
||||
AND b.build_identity <> sha256(convert_to('AEVOLUTION-SUPERSEDED-v1', 'UTF8'));
|
||||
SELECT 'held', count(*) FROM evolution.region_leases WHERE holder IS NOT NULL;
|
||||
SELECT 'final', h.world_id, h.region_id, h.commit_sequence, h.end_tick, h.published_epoch
|
||||
FROM evolution.region_heads h ORDER BY 2, 3;
|
||||
SELECT 'superseded-by', :'label';
|
||||
COMMIT;
|
||||
SQL
|
||||
@@ -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