ADR-0060 and schema v2 add database-time region leases and a fenced head advance. Acquire/renew/release/advance lock the lease row, check holder, epoch and expiry with clock_timestamp() after the lock wait, and the advance compares the exact predecessor. Holders are DB-generated tokens; epochs never wrap or repeat. The runtime group role gets EXECUTE on five SECURITY DEFINER functions only - no table, provisioning or CREATE rights. Migration history admits clean->v2, v1->v2 and a v2 no-op, and refuses privileged runtime roles. Host side: portable LeaseAuthority fences from send-time deadlines on CLOCK_BOOTTIME, keeps the earlier deadline on unknown renewal and stays fenced until a newer epoch. Selected timings: 20s lease, 5s renew, 2s margin, 2s renew and 5s commit deadlines. Linux evo::postgres wraps the functions with typed LeaseStoreError results. Validated: Windows CTest 55/55; WSL Release, clang-tidy and ASan/UBSan private-PostgreSQL suites (contenders, expiry, paused/queued stale writers, unknown renewal, exhaustion, bypass denial, upgrade path). Three SQL mutations were each caught. Docker/Gitea CI, remote TLS and cluster runs were not executed. No director, host or deployment added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.2 KiB
PL/PgSQL
33 lines
1.2 KiB
PL/PgSQL
\set ON_ERROR_STOP on
|
|
BEGIN;
|
|
SET LOCAL search_path = pg_catalog;
|
|
SET LOCAL statement_timeout = '10s';
|
|
SET LOCAL lock_timeout = '5s';
|
|
SELECT pg_catalog.pg_advisory_xact_lock(71420001);
|
|
SELECT current_setting('server_version_num')::int = 180006 AS supported \gset
|
|
\if :supported
|
|
\else
|
|
\echo 'Unsupported PostgreSQL version; expected 18.6'
|
|
DO $$ BEGIN RAISE EXCEPTION 'unsupported PostgreSQL version'; END $$;
|
|
\endif
|
|
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution') AS exists \gset
|
|
\if :exists
|
|
-- Only an exact prefix of the checked-in history is admitted. Unknown or
|
|
-- partial/foreign schemas fail closed; no IF NOT EXISTS repair of foreign data.
|
|
SELECT coalesce(string_agg(version || ':' || sha256, ',' ORDER BY version), '')
|
|
AS history FROM evolution.schema_migrations \gset
|
|
SELECT :'history' = '1:' || :'migration_sha' AS at_v1,
|
|
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' AS at_v2 \gset
|
|
\if :at_v2
|
|
\elif :at_v1
|
|
\ir 0002_region_fencing.sql
|
|
\else
|
|
\echo 'Unknown or changed migration history'
|
|
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
|
\endif
|
|
\else
|
|
\ir 0001_region_bootstrap.sql
|
|
\ir 0002_region_fencing.sql
|
|
\endif
|
|
COMMIT;
|