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:
@@ -66,6 +66,40 @@ PGDATABASE=v3_commits psql -X -v ON_ERROR_STOP=1 \
|
||||
PGDATABASE=v3_commits bash "$root/tools/migrate-postgres.sh"
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 5:1,2,3,4,5
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) FROM evolution.region_commits")" = 1
|
||||
# Review P1: a v4 database holding a published (possibly terminal) checkpoint has
|
||||
# no durable decisions for it. The v5 upgrade must refuse before changing anything.
|
||||
v4_sha="$(sha256sum "$root/migrations/0004_lineage_profile.sql")"
|
||||
v4_sha="${v4_sha%% *}"
|
||||
createdb v4_published
|
||||
PGDATABASE=v4_published psql -X -v ON_ERROR_STOP=1 -1 -v "migration_sha=$v1_sha" \
|
||||
-v "migration_sha_2=$v2_sha" -v "migration_sha_3=$v3_sha" -v "migration_sha_4=$v4_sha" \
|
||||
-v runtime_role=evo_runtime_test \
|
||||
-f "$root/migrations/0001_region_bootstrap.sql" -f "$root/migrations/0002_region_fencing.sql" \
|
||||
-f "$root/migrations/0003_region_checkpoints.sql" -f "$root/migrations/0004_lineage_profile.sql" > /dev/null
|
||||
PGDATABASE=v4_published psql -X -v ON_ERROR_STOP=1 > /dev/null <<'SQL'
|
||||
INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'));
|
||||
SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '01000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32), 'hex'));
|
||||
SELECT lease_holder, lease_epoch FROM evolution.acquire_region_lease(1, 1, 20000) \gset
|
||||
-- A real v4 publication of ticks 0..20 through the v4 fenced function.
|
||||
SELECT p.* FROM evolution.region_commits c, LATERAL evolution.publish_region_checkpoint(
|
||||
overlay(overlay(overlay(overlay(overlay(overlay(overlay(c.manifest
|
||||
placing decode(repeat('22', 16), 'hex') from 41)
|
||||
placing decode('0100000000000000', 'hex') from 57)
|
||||
placing decode(repeat('11', 16), 'hex') from 65)
|
||||
placing c.commit_digest from 81)
|
||||
placing decode('1400000000000000', 'hex') from 121)
|
||||
placing decode(replace(:'lease_holder', '-', ''), 'hex') from 129)
|
||||
placing decode('0100000000000000', 'hex') from 145)) p
|
||||
WHERE c.commit_sequence = 0;
|
||||
SQL
|
||||
test "$(PGDATABASE=v4_published psql -XAtc "SELECT count(*) FROM evolution.region_commits")" = 2
|
||||
if PGDATABASE=v4_published bash "$root/tools/migrate-postgres.sh" 2> "$test_dir/v4_published.err"; then
|
||||
echo 'Expected pre-v5 published checkpoints to block v5' >&2; exit 1
|
||||
fi
|
||||
grep -q 'pre-v5 published checkpoints lack durable decisions' "$test_dir/v4_published.err"
|
||||
test "$(PGDATABASE=v4_published psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4
|
||||
test "$(PGDATABASE=v4_published psql -XAtc "SELECT count(*) || ':' || max(end_tick) FROM evolution.region_commits")" = 2:20
|
||||
test "$(PGDATABASE=v4_published psql -XAtc "SELECT count(*) FROM pg_tables WHERE schemaname = 'evolution' AND tablename = 'region_decisions'")" = 0
|
||||
test "$(PGDATABASE=v2_heads psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2
|
||||
# Inherited privileges bypass fencing, so every migrate run audits effective rights.
|
||||
psql -X -v ON_ERROR_STOP=1 -c 'CREATE ROLE evo_bad_runtime NOLOGIN IN ROLE pg_write_all_data'
|
||||
|
||||
Reference in New Issue
Block a user