Fix object reuse durability and refuse unsafe pre-v5 upgrades
Review P1 (object durability): a name installed by a put whose directory fsync failed was later reused as success without syncing again, so a publication could acknowledge an object that might vanish on power loss. Reuse (existing and lost-link-race paths) now fsyncs the verified file and the directory before succeeding, and namespace opens always sync their parent. A test-only ObjectStoreFaults hook injects directory sync failures; tests cover failed sync then retries, namespace creation syncs, and publication refusing to proceed until durability holds. Review P1 (pre-v5 history): v5 recovery requires one durable decision per terminal actor, but v3/v4 published checkpoints carry none, so an accepted upgrade could make regions unrecoverable. pre_v5_guard.sql now runs before 0005 in every upgrade path and refuses (EVL10) when any published pre-v5 checkpoint exists; genesis-only regions pass. 0005 is unchanged. CI publishes a real v4 checkpoint and proves the upgrade is refused with nothing changed; a committed death without a decision is shown to recover as quarantined history. Validated: PostgreSQL suites Release x3, clang-tidy, ASan/UBSan x2; reverting each fix is caught by its test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,18 +27,22 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
|| ',5:' || :'migration_sha_5' AS at_v5 \gset
|
||||
\if :at_v5
|
||||
\elif :at_v4
|
||||
\ir pre_v5_guard.sql
|
||||
\ir 0005_batch_decisions.sql
|
||||
\elif :at_v3
|
||||
\ir 0004_lineage_profile.sql
|
||||
\ir pre_v5_guard.sql
|
||||
\ir 0005_batch_decisions.sql
|
||||
\elif :at_v2
|
||||
\ir 0003_region_checkpoints.sql
|
||||
\ir 0004_lineage_profile.sql
|
||||
\ir pre_v5_guard.sql
|
||||
\ir 0005_batch_decisions.sql
|
||||
\elif :at_v1
|
||||
\ir 0002_region_fencing.sql
|
||||
\ir 0003_region_checkpoints.sql
|
||||
\ir 0004_lineage_profile.sql
|
||||
\ir pre_v5_guard.sql
|
||||
\ir 0005_batch_decisions.sql
|
||||
\else
|
||||
\echo 'Unknown or changed migration history'
|
||||
@@ -49,6 +53,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0002_region_fencing.sql
|
||||
\ir 0003_region_checkpoints.sql
|
||||
\ir 0004_lineage_profile.sql
|
||||
\ir pre_v5_guard.sql
|
||||
\ir 0005_batch_decisions.sql
|
||||
\endif
|
||||
-- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
-- Runs inside apply.sql's transaction immediately before 0005 (ADR-0063). Not a
|
||||
-- migration and not recorded in history; it only refuses an unsafe upgrade.
|
||||
--
|
||||
-- Pre-v5 published checkpoints (sequence > 0) may hold organisms that died with no
|
||||
-- durable decision row, because decisions did not exist before v5. The database
|
||||
-- cannot inspect payloads to prove otherwise, and v5 recovery requires one
|
||||
-- decision per terminal actor, so accepting them would make those regions
|
||||
-- unrecoverable (RecoveryError::history). Genesis-only regions are safe: a tick-0
|
||||
-- state has no terminal organisms. Until an explicit, verified legacy-history
|
||||
-- conversion exists, refuse and change nothing.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM evolution.region_commits WHERE commit_sequence > 0) THEN
|
||||
RAISE EXCEPTION 'pre-v5 published checkpoints lack durable decisions; convert or re-provision before v5'
|
||||
USING ERRCODE = 'EVL10';
|
||||
END IF;
|
||||
END $$;
|
||||
Reference in New Issue
Block a user