Publish cellular births with durable control
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 43s
Foundation / checks (ecs) (push) Successful in 1m52s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 32s
Foundation / checks (network) (push) Failing after 3m4s
Foundation / checks (client) (push) Failing after 4m24s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 43s
Foundation / checks (ecs) (push) Successful in 1m52s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 32s
Foundation / checks (network) (push) Failing after 3m4s
Foundation / checks (client) (push) Failing after 4m24s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -86,6 +86,13 @@ ordinary player entry path into the cellular owner. It requires an extended
|
||||
canonical birth trace, atomic life-binding publication, server admission
|
||||
wiring, and concurrent/restart tests before the 11.3e probe can run.
|
||||
|
||||
The profile-4 publisher now carries the canonical trace to PostgreSQL. Its
|
||||
birth rows must match the current control generation and reserved identity;
|
||||
the account/life binding is inserted in the same transaction as the checkpoint.
|
||||
Recovery compares those bindings to the tail trace. The previous action-only
|
||||
profile-4 SQL entry point is revoked from the runtime role, so deployments must
|
||||
run a publisher version that supplies the trace before cellular commits resume.
|
||||
|
||||
## Consequences
|
||||
|
||||
`evo-world-clone` creates empty profile-4 genesis only. The M11.3e gate remains
|
||||
|
||||
@@ -318,6 +318,15 @@ scoped change before starting the next segment.
|
||||
validation and migration 22 raise the profile-4 trace ceiling; PostgreSQL and
|
||||
end-to-end birth publication tests are still pending, so this is not yet a
|
||||
durable birth path or a playable 11.3e slice.
|
||||
- 11.3d-7i: migration 23 adds the cellular birth-trace parser and requires the
|
||||
current account-control generation plus exact profile-4 life reservation
|
||||
before the checkpoint can publish. Reservation bindings and the checkpoint
|
||||
commit are one transaction; exact retries compare those bindings against the
|
||||
trace. Recovery loads the commit's birth bindings and matches account,
|
||||
request, identity and born tick before accepting replay. A PostgreSQL
|
||||
integration test covers empty-genesis birth, durable request outcome and
|
||||
restart recovery. CI/PostgreSQL execution remains pending, and the live v5
|
||||
request scheduler still has to feed these records before 11.3e is playable.
|
||||
|
||||
## Exit boundary
|
||||
|
||||
|
||||
@@ -6417,3 +6417,23 @@ not run for this segment. The Windows `bash.exe` shim is access-denied, and the
|
||||
migration test translation unit cannot compile here because its process fixture
|
||||
requires POSIX `poll.h`. The previously noted unrelated initializer warning in
|
||||
`cellular_region_step.cpp:29` is demoted only for the manual focused test build.
|
||||
|
||||
## 2026-10-11 — M11.3d-7i cellular birth publication (database pending)
|
||||
|
||||
Migration 23 parses the format-2 birth records, checks their trace/manifest
|
||||
binding, and routes publication through current account control and the exact
|
||||
allocator reservation. It records the account-to-life binding in the same
|
||||
transaction as the cellular checkpoint. The cellular publisher's runtime API
|
||||
now requires the trace bytes, and recovery compares durable birth bindings with
|
||||
the decoded tail trace before accepting the replay. A PostgreSQL integration
|
||||
case covers a first birth from empty genesis, the v5 request outcome, and a
|
||||
new-host recovery.
|
||||
|
||||
Strict GCC 13.2 syntax checks pass for the persistence adapter, cellular host,
|
||||
and affected unit/integration test sources; the focused codec/lifecycle test
|
||||
passes in debug and `-DNDEBUG`, and `git diff --check` passes. PostgreSQL
|
||||
migration and integration execution remain pending CI because this Windows
|
||||
environment lacks `psql`. The Windows `bash.exe` shim is access-denied, so the
|
||||
migration scripts could not be syntax-checked here. CTest, sanitizer checks,
|
||||
and CI have not run for this segment. The migration-test source itself cannot
|
||||
compile locally because its fixture requires POSIX `poll.h`.
|
||||
|
||||
@@ -82,6 +82,7 @@ publish_region_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
publish_cellular_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace,
|
||||
std::chrono::milliseconds timeout);
|
||||
|
||||
enum class Resolution : std::uint8_t {
|
||||
@@ -111,6 +112,7 @@ resolve_cellular_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace,
|
||||
std::chrono::milliseconds timeout);
|
||||
|
||||
// Load the immutable action block for a committed profile-4 link under the current lease.
|
||||
@@ -119,6 +121,14 @@ resolve_cellular_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
[[nodiscard]] std::expected<std::optional<std::vector<std::uint8_t>>, LeaseStoreFailure>
|
||||
load_cellular_publication_actions(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const Uuid& commit, std::chrono::milliseconds timeout);
|
||||
struct CellularBirthBinding {
|
||||
Uuid account{}, commit{};
|
||||
std::uint64_t request{}, identity{}, born{}, commit_sequence{};
|
||||
friend bool operator==(const CellularBirthBinding&, const CellularBirthBinding&) = default;
|
||||
};
|
||||
[[nodiscard]] std::expected<std::vector<CellularBirthBinding>, LeaseStoreFailure>
|
||||
load_cellular_publication_births(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const Uuid& commit, std::chrono::milliseconds timeout);
|
||||
// The committed record of an account's action in the lease's world (schema v11), under the
|
||||
// caller's exact lease. Nothing when the action was never committed.
|
||||
struct CommittedAction {
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
-- M11.3d-7i, ADR-0114: bind cellular birth trace rows and life outcomes atomically.
|
||||
CREATE FUNCTION evolution.cellular_births(p_trace bytea, p_manifest bytea)
|
||||
RETURNS TABLE(account_id uuid, request_id evolution.u64, generation evolution.u64,
|
||||
identity evolution.u64, born evolution.u64)
|
||||
LANGUAGE plpgsql IMMUTABLE SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
||||
ticks numeric;
|
||||
tick_index integer;
|
||||
intent_count numeric;
|
||||
birth_count numeric;
|
||||
off integer := 112;
|
||||
account bytea;
|
||||
previous_account bytea;
|
||||
previous_request numeric;
|
||||
BEGIN
|
||||
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_trace IS NULL
|
||||
OR octet_length(p_trace) <> c.trace_bytes OR sha256(p_trace) <> c.trace_sha256
|
||||
OR substring(p_trace FROM 1 FOR 8) <> '\x45564c4342543031'
|
||||
OR evolution.manifest_uint(p_trace, 8, 4) <> 2
|
||||
OR evolution.manifest_uint(p_trace, 12, 4) <> 4
|
||||
OR evolution.manifest_uint(p_trace, 16, 8) <> c.world_id
|
||||
OR evolution.manifest_uint(p_trace, 24, 8) <> c.region_id
|
||||
OR evolution.manifest_uint(p_trace, 32, 8) <> c.frame_id
|
||||
OR encode(substring(p_trace FROM 41 FOR 16), 'hex')::uuid <> c.predecessor_commit
|
||||
OR substring(p_trace FROM 57 FOR 32) <> c.predecessor_digest
|
||||
OR evolution.manifest_uint(p_trace, 88, 8) <> c.begin_tick
|
||||
OR evolution.manifest_uint(p_trace, 96, 8) <> c.end_tick THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace binding' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
ticks := c.end_tick - c.begin_tick;
|
||||
IF ticks < 1 OR ticks > 64 OR evolution.manifest_uint(p_trace, 104, 4) <> ticks
|
||||
OR evolution.manifest_uint(p_trace, 108, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace range' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
FOR tick_index IN 0 .. ticks::integer - 1 LOOP
|
||||
IF off + 8 > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'truncated cellular tick header' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
intent_count := evolution.manifest_uint(p_trace, off, 4);
|
||||
birth_count := evolution.manifest_uint(p_trace, off + 4, 4);
|
||||
IF intent_count > 256 OR birth_count > 256
|
||||
OR off + 8 + intent_count * 24 + birth_count * 40 > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick counts' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
off := off + 8 + intent_count::integer * 24;
|
||||
previous_account := ''::bytea;
|
||||
previous_request := -1;
|
||||
FOR birth_index IN 0 .. birth_count::integer - 1 LOOP
|
||||
account := substring(p_trace FROM off + 1 FOR 16);
|
||||
account_id := encode(account, 'hex')::uuid;
|
||||
request_id := evolution.manifest_uint(p_trace, off + 16, 8);
|
||||
generation := evolution.manifest_uint(p_trace, off + 24, 8);
|
||||
identity := evolution.manifest_uint(p_trace, off + 32, 8);
|
||||
born := c.begin_tick + tick_index + 1;
|
||||
IF account_id = '00000000-0000-0000-0000-000000000000' OR request_id = 0
|
||||
OR generation = 0 OR identity = 0
|
||||
OR (account, request_id) <= (previous_account, previous_request) THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth record' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
previous_account := account;
|
||||
previous_request := request_id;
|
||||
off := off + 40;
|
||||
RETURN NEXT;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
IF off <> octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'trailing cellular trace bytes' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
CREATE FUNCTION evolution.cellular_birth_bindings_match(p_world evolution.u64,
|
||||
p_commit uuid, p_trace bytea, p_manifest bytea)
|
||||
RETURNS boolean LANGUAGE sql STABLE SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
||||
SELECT NOT EXISTS (
|
||||
SELECT 1 FROM evolution.cellular_births(p_trace, p_manifest) b
|
||||
LEFT JOIN evolution.life_reservations r ON r.world_id = p_world
|
||||
AND r.account_id = b.account_id AND r.request_id = b.request_id
|
||||
LEFT JOIN evolution.primitive_life_bindings x ON x.world_id = p_world
|
||||
AND x.account_id = b.account_id AND x.request_id = b.request_id
|
||||
WHERE r.identity IS DISTINCT FROM b.identity OR r.region_id IS DISTINCT FROM
|
||||
evolution.manifest_uint(p_manifest, 24, 8)
|
||||
OR x.commit_id IS DISTINCT FROM p_commit OR x.born IS DISTINCT FROM b.born)
|
||||
AND (SELECT count(*) FROM evolution.primitive_life_bindings x
|
||||
WHERE x.world_id = p_world AND x.commit_id = p_commit) =
|
||||
(SELECT count(*) FROM evolution.cellular_births(p_trace, p_manifest));
|
||||
$$;
|
||||
|
||||
-- The original three-argument function remains an internal action-only core.
|
||||
-- Runtime callers must provide the exact format-2 trace as birth evidence.
|
||||
REVOKE ALL ON FUNCTION evolution.publish_cellular_checkpoint(bytea,bytea,bytea),
|
||||
evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)
|
||||
FROM PUBLIC, :"runtime_role";
|
||||
|
||||
CREATE FUNCTION evolution.publish_cellular_checkpoint(p_manifest bytea,
|
||||
p_decisions bytea, p_actions bytea, p_trace bytea)
|
||||
RETURNS TABLE(region_frame evolution.u64, head_sequence evolution.u64, head_commit uuid,
|
||||
head_digest text, head_tick evolution.u64)
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
||||
b record;
|
||||
r evolution.life_reservations%ROWTYPE;
|
||||
BEGIN
|
||||
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_actions IS NULL THEN
|
||||
RAISE EXCEPTION 'invalid cellular publication' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
PERFORM evolution.check_cellular_action_block(p_actions, c.begin_tick, c.end_tick);
|
||||
PERFORM * FROM evolution.cellular_births(p_trace, p_manifest);
|
||||
IF EXISTS (SELECT b.account_id FROM evolution.cellular_births(p_trace, p_manifest) b
|
||||
GROUP BY b.account_id HAVING count(*) > 1)
|
||||
OR EXISTS (SELECT b.identity FROM evolution.cellular_births(p_trace, p_manifest) b
|
||||
GROUP BY b.identity HAVING count(*) > 1) THEN
|
||||
RAISE EXCEPTION 'duplicate cellular birth identity' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
PERFORM evolution.check_region_lease(c.world_id, c.region_id, c.holder, c.epoch);
|
||||
-- The lease lock fences competing commits. Exact retries are accepted only
|
||||
-- when the immutable binding rows agree with every birth in the trace.
|
||||
IF EXISTS (SELECT 1 FROM evolution.region_commits x WHERE x.commit_id = c.commit_id) THEN
|
||||
IF NOT evolution.cellular_birth_bindings_match(c.world_id, c.commit_id, p_trace, p_manifest) THEN
|
||||
RAISE EXCEPTION 'cellular birth evidence differs on retry' USING ERRCODE = 'EVL07';
|
||||
END IF;
|
||||
RETURN QUERY SELECT * FROM evolution.publish_cellular_checkpoint(
|
||||
p_manifest, p_decisions, p_actions);
|
||||
RETURN;
|
||||
END IF;
|
||||
-- Lock accounts in stable order and require the exact current control generation
|
||||
-- and previously allocated request identity before inserting any binding.
|
||||
FOR b IN SELECT * FROM evolution.cellular_births(p_trace, p_manifest) ORDER BY account_id LOOP
|
||||
PERFORM evolution.check_life_control(c.world_id, c.region_id, c.holder, c.epoch,
|
||||
b.account_id, b.generation);
|
||||
SELECT * INTO r FROM evolution.life_reservations x WHERE x.world_id = c.world_id
|
||||
AND x.account_id = b.account_id AND x.request_id = b.request_id FOR UPDATE;
|
||||
IF NOT FOUND OR r.region_id <> c.region_id OR r.identity <> b.identity
|
||||
OR r.rejection <> 0 OR r.rules <> 1
|
||||
OR EXISTS (SELECT 1 FROM evolution.primitive_life_bindings x
|
||||
WHERE x.world_id = c.world_id AND x.account_id = b.account_id) THEN
|
||||
RAISE EXCEPTION 'cellular birth reservation conflicts' USING ERRCODE = 'EVL16';
|
||||
END IF;
|
||||
END LOOP;
|
||||
FOR b IN SELECT * FROM evolution.cellular_births(p_trace, p_manifest) ORDER BY account_id LOOP
|
||||
PERFORM evolution.check_life_control(c.world_id, c.region_id, c.holder, c.epoch,
|
||||
b.account_id, b.generation);
|
||||
END LOOP;
|
||||
INSERT INTO evolution.primitive_life_bindings(world_id, account_id, request_id, born, commit_id)
|
||||
SELECT c.world_id, b.account_id, b.request_id, b.born, c.commit_id
|
||||
FROM evolution.cellular_births(p_trace, p_manifest) b;
|
||||
RETURN QUERY SELECT * FROM evolution.publish_cellular_checkpoint(
|
||||
p_manifest, p_decisions, p_actions);
|
||||
END $$;
|
||||
|
||||
CREATE FUNCTION evolution.resolve_cellular_region_commit(p_world evolution.u64,
|
||||
p_region evolution.u64, p_commit uuid, p_manifest bytea, p_decisions bytea,
|
||||
p_actions bytea, p_trace bytea)
|
||||
RETURNS TABLE(status text, region_frame evolution.u64, head_sequence evolution.u64,
|
||||
head_commit uuid, head_digest text, head_tick evolution.u64)
|
||||
LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
||||
BEGIN
|
||||
IF c.world_id <> p_world OR c.region_id <> p_region OR c.commit_id <> p_commit
|
||||
OR p_actions IS NULL THEN
|
||||
RAISE EXCEPTION 'invalid cellular resolution request' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
PERFORM evolution.check_cellular_action_block(p_actions, c.begin_tick, c.end_tick);
|
||||
PERFORM * FROM evolution.cellular_births(p_trace, p_manifest);
|
||||
IF EXISTS (SELECT 1 FROM evolution.region_commits x WHERE x.commit_id = p_commit)
|
||||
AND NOT evolution.cellular_birth_bindings_match(p_world, p_commit, p_trace, p_manifest) THEN
|
||||
RETURN QUERY SELECT 'conflict'::text, NULL::evolution.u64, NULL::evolution.u64,
|
||||
NULL::uuid, NULL::text, NULL::evolution.u64;
|
||||
RETURN;
|
||||
END IF;
|
||||
RETURN QUERY SELECT * FROM evolution.resolve_cellular_region_commit(
|
||||
p_world, p_region, p_commit, p_manifest, p_decisions, p_actions);
|
||||
END $$;
|
||||
|
||||
CREATE FUNCTION evolution.load_cellular_publication_births(p_world evolution.u64,
|
||||
p_region evolution.u64, p_holder uuid, p_epoch evolution.u64, p_commit uuid)
|
||||
RETURNS TABLE(account_id uuid, request_id evolution.u64, identity evolution.u64,
|
||||
born evolution.u64, commit_sequence evolution.u64)
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
||||
BEGIN
|
||||
PERFORM evolution.check_region_lease(p_world, p_region, p_holder, p_epoch);
|
||||
IF NOT EXISTS (SELECT 1 FROM evolution.region_commits c
|
||||
JOIN evolution.cellular_publications p USING (commit_id)
|
||||
WHERE c.world_id = p_world AND c.region_id = p_region AND c.commit_id = p_commit
|
||||
AND c.commit_sequence > 0 AND evolution.manifest_uint(c.manifest, 12, 4) = 4) THEN
|
||||
RAISE EXCEPTION 'cellular publication evidence missing' USING ERRCODE = 'EVL06';
|
||||
END IF;
|
||||
RETURN QUERY SELECT b.account_id, b.request_id, r.identity, b.born, c.commit_sequence
|
||||
FROM evolution.primitive_life_bindings b
|
||||
JOIN evolution.life_reservations r USING (world_id, account_id, request_id)
|
||||
JOIN evolution.region_commits c ON c.commit_id = b.commit_id
|
||||
WHERE b.world_id = p_world AND r.region_id = p_region AND b.commit_id = p_commit
|
||||
ORDER BY b.born, b.account_id, b.request_id;
|
||||
END $$;
|
||||
|
||||
REVOKE ALL ON FUNCTION evolution.cellular_births(bytea,bytea),
|
||||
evolution.cellular_birth_bindings_match(evolution.u64,uuid,bytea,bytea),
|
||||
evolution.publish_cellular_checkpoint(bytea,bytea,bytea,bytea),
|
||||
evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea,bytea),
|
||||
evolution.load_cellular_publication_births(evolution.u64,evolution.u64,uuid,evolution.u64,uuid)
|
||||
FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION evolution.publish_cellular_checkpoint(bytea,bytea,bytea,bytea),
|
||||
evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea,bytea),
|
||||
evolution.load_cellular_publication_births(evolution.u64,evolution.u64,uuid,evolution.u64,uuid)
|
||||
TO :"runtime_role";
|
||||
INSERT INTO evolution.schema_migrations(version, sha256) VALUES (23, :'migration_sha_23');
|
||||
+29
-3
@@ -96,27 +96,35 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' || ',18:' || :'migration_sha_18' || ',19:' || :'migration_sha_19' || ',20:' || :'migration_sha_20' AS at_v20,
|
||||
:'history' = '1:' || :'migration_sha' || ',2:' || :'migration_sha_2' || ',3:' || :'migration_sha_3' || ',4:' || :'migration_sha_4' || ',5:' || :'migration_sha_5' || ',6:' || :'migration_sha_6' || ',7:' || :'migration_sha_7' || ',8:' || :'migration_sha_8' || ',9:' || :'migration_sha_9' || ',10:' || :'migration_sha_10' || ',11:' || :'migration_sha_11' || ',12:' || :'migration_sha_12' || ',13:' || :'migration_sha_13' || ',14:' || :'migration_sha_14' || ',15:' || :'migration_sha_15' || ',16:' || :'migration_sha_16' || ',17:' || :'migration_sha_17' || ',18:' || :'migration_sha_18' || ',19:' || :'migration_sha_19' || ',20:' || :'migration_sha_20' || ',21:' || :'migration_sha_21' AS at_v21 \gset
|
||||
SELECT right(:'history', length(',22:' || :'migration_sha_22')) = ',22:' || :'migration_sha_22' AS at_v22 \gset
|
||||
\if :at_v22
|
||||
SELECT right(:'history', length(',23:' || :'migration_sha_23')) = ',23:' || :'migration_sha_23' AS at_v23 \gset
|
||||
\if :at_v23
|
||||
\elif :at_v22
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v21
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v20
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v19
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v18
|
||||
\ir 0019_cellular_action_records.sql
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v17
|
||||
\ir 0018_cellular_profile_admission.sql
|
||||
\ir 0019_cellular_action_records.sql
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v16
|
||||
\ir 0017_life_request_outcomes.sql
|
||||
\ir 0018_cellular_profile_admission.sql
|
||||
@@ -124,6 +132,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v15
|
||||
\ir 0016_primitive_publication.sql
|
||||
\ir 0017_life_request_outcomes.sql
|
||||
@@ -132,6 +141,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v14
|
||||
\ir 0015_life_reservations.sql
|
||||
\ir 0016_primitive_publication.sql
|
||||
@@ -141,6 +151,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v13
|
||||
\ir 0014_probe_overdue.sql
|
||||
\ir 0015_life_reservations.sql
|
||||
@@ -151,6 +162,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v12
|
||||
\ir 0013_probe_incoming.sql
|
||||
\ir 0014_probe_overdue.sql
|
||||
@@ -162,6 +174,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v11
|
||||
\ir 0012_probe_handoff.sql
|
||||
\ir 0013_probe_incoming.sql
|
||||
@@ -174,6 +187,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v10
|
||||
\ir 0011_region_actions.sql
|
||||
\ir 0012_probe_handoff.sql
|
||||
@@ -187,6 +201,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v9
|
||||
\ir 0010_account_control.sql
|
||||
\ir 0011_region_actions.sql
|
||||
@@ -201,6 +216,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v8
|
||||
\ir 0009_serialized_authority.sql
|
||||
\ir 0010_account_control.sql
|
||||
@@ -216,6 +232,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v7
|
||||
\ir 0008_upgrade_barrier.sql
|
||||
\ir 0009_serialized_authority.sql
|
||||
@@ -232,6 +249,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v6
|
||||
\ir 0007_region_clones.sql
|
||||
\ir 0008_upgrade_barrier.sql
|
||||
@@ -249,6 +267,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v5
|
||||
\ir 0006_commit_lookup.sql
|
||||
\ir 0007_region_clones.sql
|
||||
@@ -267,6 +286,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v4
|
||||
\ir pre_v5_guard.sql
|
||||
\ir 0005_batch_decisions.sql
|
||||
@@ -287,6 +307,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v3
|
||||
\ir 0004_lineage_profile.sql
|
||||
\ir pre_v5_guard.sql
|
||||
@@ -308,6 +329,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v2
|
||||
\ir 0003_region_checkpoints.sql
|
||||
\ir 0004_lineage_profile.sql
|
||||
@@ -330,6 +352,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\elif :at_v1
|
||||
\ir 0002_region_fencing.sql
|
||||
\ir 0003_region_checkpoints.sql
|
||||
@@ -353,6 +376,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\else
|
||||
\echo 'Unknown or changed migration history'
|
||||
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
||||
@@ -381,6 +405,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
\ir 0020_cellular_publication.sql
|
||||
\ir 0021_cellular_trace_and_recovery.sql
|
||||
\ir 0022_cellular_birth_trace_bound.sql
|
||||
\ir 0023_cellular_birth_publication.sql
|
||||
\endif
|
||||
-- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes
|
||||
-- alone are insufficient: predefined roles such as pg_write_all_data, PUBLIC
|
||||
@@ -425,9 +450,10 @@ BEGIN
|
||||
('evolution.resolve_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)'::regprocedure::oid),
|
||||
('evolution.find_region_action(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64)'::regprocedure::oid),
|
||||
('evolution.find_region_action_record(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64)'::regprocedure::oid),
|
||||
('evolution.publish_cellular_checkpoint(bytea,bytea,bytea)'::regprocedure::oid),
|
||||
('evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea)'::regprocedure::oid),
|
||||
('evolution.publish_cellular_checkpoint(bytea,bytea,bytea,bytea)'::regprocedure::oid),
|
||||
('evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,bytea,bytea,bytea,bytea)'::regprocedure::oid),
|
||||
('evolution.load_cellular_publication_actions(evolution.u64,evolution.u64,uuid,evolution.u64,uuid)'::regprocedure::oid),
|
||||
('evolution.load_cellular_publication_births(evolution.u64,evolution.u64,uuid,evolution.u64,uuid)'::regprocedure::oid),
|
||||
('evolution.open_probe(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,bigint,bigint,bigint,evolution.u64)'::regprocedure::oid),
|
||||
('evolution.save_probe(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64,bigint,bigint,bigint)'::regprocedure::oid),
|
||||
('evolution.prepare_probe_transfer(evolution.u64,evolution.u64,uuid,evolution.u64,uuid,evolution.u64,uuid,evolution.u64,bigint,bigint,bigint)'::regprocedure::oid),
|
||||
|
||||
@@ -55,6 +55,7 @@ bool prepared_is_canonical(const CellularPreparedCommit& prepared,
|
||||
manifest.end_tick)
|
||||
: std::expected<std::vector<std::uint8_t>, server::CellularActionBlockError>{
|
||||
std::unexpected{server::CellularActionBlockError::format}};
|
||||
const auto encoded_trace = server::encode_cellular_batch(trace);
|
||||
const auto digest = sha256(prepared.trace);
|
||||
return manifest.profile == CheckpointProfile::cellular_lives_v1 &&
|
||||
manifest.key == prepared.key && manifest.commit == prepared.commit &&
|
||||
@@ -66,7 +67,8 @@ bool prepared_is_canonical(const CellularPreparedCommit& prepared,
|
||||
trace.header.predecessor == manifest.predecessor_commit &&
|
||||
trace.header.predecessor_digest == manifest.predecessor_digest &&
|
||||
trace.header.begin_tick == manifest.begin_tick && trace.header.end_tick == manifest.end_tick &&
|
||||
encoded_actions && *encoded_actions == prepared.actions;
|
||||
encoded_actions && *encoded_actions == prepared.actions && encoded_trace &&
|
||||
*encoded_trace == prepared.trace;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -135,7 +137,8 @@ retry_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
auto trace = server::decode_cellular_batch(prepared.trace);
|
||||
if (!manifest || !trace || !prepared_is_canonical(prepared, *manifest, *trace))
|
||||
return std::unexpected{failure(PublicationError::candidate)};
|
||||
auto result = publish_cellular_checkpoint(db, prepared.manifest, {}, prepared.actions, timeout);
|
||||
auto result = publish_cellular_checkpoint(db, prepared.manifest, {}, prepared.actions,
|
||||
prepared.trace, timeout);
|
||||
if (!result) {
|
||||
return std::unexpected{failure(
|
||||
result.error().kind == LeaseStoreError::unknown ? PublicationError::unknown
|
||||
@@ -153,7 +156,7 @@ resolve_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
if (!manifest || !trace || !prepared_is_canonical(prepared, *manifest, *trace))
|
||||
return std::unexpected{LeaseStoreFailure{LeaseStoreError::invalid, {}}};
|
||||
return resolve_cellular_region_commit(db, prepared.key, prepared.commit, prepared.manifest,
|
||||
{}, prepared.actions, timeout);
|
||||
{}, prepared.actions, prepared.trace, timeout);
|
||||
}
|
||||
|
||||
std::expected<PublishedCellularBatch, CellularPublicationFailure>
|
||||
@@ -278,6 +281,23 @@ recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects,
|
||||
trace->header.end_tick != manifest->end_tick)
|
||||
return fail_with(RecoveryError::tail);
|
||||
|
||||
auto committed_births = load_cellular_publication_births(db, key, lease,
|
||||
manifest->commit, timeout);
|
||||
if (!committed_births)
|
||||
return std::unexpected{RecoveryFailure{RecoveryError::store,
|
||||
committed_births.error()}};
|
||||
std::vector<CellularBirthBinding> traced_births;
|
||||
for (std::size_t tick_index = 0; tick_index < trace->ticks.size(); ++tick_index) {
|
||||
for (const auto& birth : trace->ticks[tick_index].births) {
|
||||
traced_births.push_back({birth.account, manifest->commit, birth.request,
|
||||
birth.identity,
|
||||
manifest->begin_tick + tick_index + 1,
|
||||
manifest->sequence});
|
||||
}
|
||||
}
|
||||
if (traced_births != *committed_births)
|
||||
return fail_with(RecoveryError::history);
|
||||
|
||||
auto predecessor = load_region_commit(db, key, manifest->sequence - 1, timeout);
|
||||
if (!predecessor)
|
||||
return std::unexpected{RecoveryFailure{RecoveryError::tail, predecessor.error()}};
|
||||
|
||||
@@ -340,11 +340,13 @@ publish_region_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::expected<RegionHead, LeaseStoreFailure>
|
||||
publish_cellular_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions, milliseconds timeout) {
|
||||
const std::array<std::string, 3> p{bytea(manifest), bytea(decisions), bytea(actions)};
|
||||
std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace, milliseconds timeout) {
|
||||
const std::array<std::string, 4> p{bytea(manifest), bytea(decisions), bytea(actions),
|
||||
bytea(trace)};
|
||||
auto rows = db.query(
|
||||
"SELECT * FROM evolution.publish_cellular_checkpoint($1::bytea, $2::bytea, $3::bytea)",
|
||||
p, timeout);
|
||||
"SELECT * FROM evolution.publish_cellular_checkpoint($1::bytea, $2::bytea, $3::bytea, "
|
||||
"$4::bytea)", p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{classify(rows.error())};
|
||||
auto head = parse_head(*rows);
|
||||
@@ -388,13 +390,14 @@ std::expected<ResolvedCommit, LeaseStoreFailure>
|
||||
resolve_cellular_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions, milliseconds timeout) {
|
||||
const std::array<std::string, 6> p{std::to_string(key.world), std::to_string(key.region),
|
||||
std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace, milliseconds timeout) {
|
||||
const std::array<std::string, 7> p{std::to_string(key.world), std::to_string(key.region),
|
||||
uuid_text(commit), bytea(manifest),
|
||||
bytea(decisions), bytea(actions)};
|
||||
bytea(decisions), bytea(actions), bytea(trace)};
|
||||
auto rows = db.query(
|
||||
"SELECT * FROM evolution.resolve_cellular_region_commit($1::evolution.u64, "
|
||||
"$2::evolution.u64, $3::uuid, $4::bytea, $5::bytea, $6::bytea)",
|
||||
"$2::evolution.u64, $3::uuid, $4::bytea, $5::bytea, $6::bytea, $7::bytea)",
|
||||
p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{classify(rows.error())};
|
||||
@@ -436,6 +439,36 @@ load_cellular_publication_actions(Postgres& db, RegionKey key, const LeaseGrant&
|
||||
return std::optional<std::vector<std::uint8_t>>{std::move(*actions)};
|
||||
}
|
||||
|
||||
std::expected<std::vector<CellularBirthBinding>, LeaseStoreFailure>
|
||||
load_cellular_publication_births(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const Uuid& commit, milliseconds timeout) {
|
||||
const std::array<std::string, 5> p{std::to_string(key.world), std::to_string(key.region),
|
||||
uuid_text(lease.holder), std::to_string(lease.epoch),
|
||||
uuid_text(commit)};
|
||||
auto rows = db.query(
|
||||
"SELECT account_id::text, request_id::text, identity::text, born::text, "
|
||||
"commit_sequence::text FROM evolution.load_cellular_publication_births("
|
||||
"$1::evolution.u64, $2::evolution.u64, $3::uuid, $4::evolution.u64, $5::uuid)",
|
||||
p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{classify(rows.error())};
|
||||
std::vector<CellularBirthBinding> bindings;
|
||||
bindings.reserve(rows->size());
|
||||
for (const auto& row : *rows) {
|
||||
if (row.size() != 5)
|
||||
return std::unexpected{malformed(false)};
|
||||
const auto account = parse_uuid(row[0]);
|
||||
const auto request = parse_integer<std::uint64_t>(row[1]);
|
||||
const auto identity = parse_integer<std::uint64_t>(row[2]);
|
||||
const auto born = parse_integer<std::uint64_t>(row[3]);
|
||||
const auto sequence = parse_integer<std::uint64_t>(row[4]);
|
||||
if (!account || !request || !identity || !born || !sequence)
|
||||
return std::unexpected{malformed(false)};
|
||||
bindings.push_back({*account, commit, *request, *identity, *born, *sequence});
|
||||
}
|
||||
return bindings;
|
||||
}
|
||||
|
||||
std::expected<std::optional<CommittedAction>, LeaseStoreFailure>
|
||||
find_region_action(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
||||
std::uint64_t action_id, milliseconds timeout) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Profile-4 publication and recovery against the migration-backed PostgreSQL adapter.
|
||||
#include "evo/persistence/checkpoint_store.hpp"
|
||||
#include "evo/persistence/account_control_store.hpp"
|
||||
#include "evo/persistence/life_reservation_store.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/server/cellular_region_host.hpp"
|
||||
|
||||
@@ -45,7 +47,90 @@ std::string hex(std::span<const std::uint8_t> bytes) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
void cellular_birth_publication_is_durable() {
|
||||
using namespace evo::biology;
|
||||
constexpr RegionKey key{9758, 1};
|
||||
auto owner = connect_as(env("PGUSER"));
|
||||
auto runtime = connect_as(env("EVO_PG_RUNTIME_USER"));
|
||||
const auto build = filled<32>(0xD9);
|
||||
CHECK(owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
|
||||
"(decode(repeat('d9',32),'hex')) ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
auto endowed = primitive_endowment();
|
||||
CHECK(endowed);
|
||||
auto funding = endowed->body;
|
||||
funding.energy.value = endowed->reserve.energy.value + endowed->construction.value;
|
||||
auto primitive = PrimitiveLives::create({key.world, key.region, 1, 17, funding, {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
auto habitat = CellularHabitat::create({key.world, key.region, 1, 1'000, 1'000, {}});
|
||||
CHECK(habitat);
|
||||
auto opening = CellularLives::create(**primitive, std::move(*habitat),
|
||||
{{1'000, 1'000}, 0, 293'150});
|
||||
CHECK(opening && (*opening)->lives().empty());
|
||||
auto objects = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(objects);
|
||||
const auto genesis = provision_cellular_region(*owner, **objects, key, 1, **opening,
|
||||
filled<16>(0x30), build, 5s);
|
||||
CHECK(genesis);
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators VALUES(9758,1000)", {}, 5s));
|
||||
const auto connect = [&]() -> std::expected<std::unique_ptr<Postgres>, PgFailure> {
|
||||
return Postgres::connect({env("PGHOST"), {}, env("PGPORT"), env("PGDATABASE"),
|
||||
env("EVO_PG_RUNTIME_USER"), {}, {}}, 5s);
|
||||
};
|
||||
CellularHostConfig config{key, 1, {}, build, {build}};
|
||||
auto made = CellularRegionHost::create(config, connect, std::move(*objects));
|
||||
CHECK(made);
|
||||
auto host = std::move(*made);
|
||||
CHECK(host->step().ready);
|
||||
const auto authority = host->authority();
|
||||
CHECK(authority);
|
||||
const auto account = filled<16>(0x47);
|
||||
const auto control = claim_account_control(*runtime, key, *authority, account, 1, 1,
|
||||
20'000ms, 5s);
|
||||
CHECK(control);
|
||||
const auto reservation = reserve_primitive_life(*runtime, key, *authority, account,
|
||||
control->generation, 7, 1, 5s);
|
||||
CHECK(reservation && reservation->refusal == LifeRefusal::none &&
|
||||
reservation->region == key.region);
|
||||
|
||||
CellularBatch batch;
|
||||
const auto predecessor_digest = sha256(host->committed()->manifest);
|
||||
CHECK(predecessor_digest);
|
||||
batch.header = {key.world, key.region, 1, host->committed()->head.commit,
|
||||
*predecessor_digest, 0, 1};
|
||||
CellularTickIntents tick;
|
||||
tick.births.push_back({account, 7, control->generation, reservation->identity});
|
||||
batch.ticks.push_back(tick);
|
||||
auto candidate = replay_cellular_batch(*host->state(), batch);
|
||||
CHECK(candidate && (*candidate)->lives().size() == 1 &&
|
||||
(*candidate)->lives()[0].identity.life == reservation->identity);
|
||||
auto published = host->publish(batch);
|
||||
CHECK(published && published->committed.head.sequence == 1 &&
|
||||
host->state()->snapshot() == (*candidate)->snapshot());
|
||||
const auto outcome = query_primitive_life(*runtime, key, *authority, account,
|
||||
control->generation, 7, 5s);
|
||||
CHECK(outcome && outcome->has_value() && (*outcome)->published &&
|
||||
(*outcome)->published->identity == reservation->identity &&
|
||||
(*outcome)->published->born == 1);
|
||||
host->drain();
|
||||
host.reset();
|
||||
|
||||
auto restarted_objects = FilesystemObjectStore::open(env("PGHOST"), key,
|
||||
max_cellular_lives_bytes);
|
||||
CHECK(restarted_objects);
|
||||
auto restarted_made = CellularRegionHost::create(config, connect,
|
||||
std::move(*restarted_objects));
|
||||
CHECK(restarted_made);
|
||||
auto restarted = std::move(*restarted_made);
|
||||
CHECK(restarted->step().ready && restarted->state()->tick() == 1 &&
|
||||
restarted->state()->snapshot() == (*candidate)->snapshot());
|
||||
restarted->drain();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void run_cellular_publication_tests() {
|
||||
cellular_birth_publication_is_durable();
|
||||
auto owner = connect_as(env("PGUSER"));
|
||||
const auto build = filled<32>(0xD9);
|
||||
CHECK(owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
|
||||
|
||||
@@ -186,10 +186,10 @@ void runtime_cannot_bypass_the_guard() {
|
||||
void cellular_publisher_adapter_rejects_malformed_requests() {
|
||||
auto db = runtime();
|
||||
const std::vector<std::uint8_t> empty;
|
||||
auto published = publish_cellular_checkpoint(*db, empty, empty, empty, 5s);
|
||||
auto published = publish_cellular_checkpoint(*db, empty, empty, empty, empty, 5s);
|
||||
CHECK(failed(published, LeaseStoreError::invalid));
|
||||
auto resolved = resolve_cellular_region_commit(*db, {1, 999}, id(0xC1), empty, empty, empty,
|
||||
5s);
|
||||
empty, 5s);
|
||||
CHECK(failed(resolved, LeaseStoreError::invalid));
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +188,7 @@ void upgrade_across_migration_and_barrier() {
|
||||
" -v migration_sha_20=$(s 0020_cellular_publication.sql)"
|
||||
" -v migration_sha_21=$(s 0021_cellular_trace_and_recovery.sql)"
|
||||
" -v migration_sha_22=$(s 0022_cellular_birth_trace_bound.sql)"
|
||||
" -v migration_sha_23=$(s 0023_cellular_birth_publication.sql)"
|
||||
" -v runtime_role=evo_runtime_test -f migrations/apply.sql"
|
||||
" > /dev/null 2>&1") != 0);
|
||||
CHECK(history(*owner_db) == "1,2,3,4,5,6,7");
|
||||
@@ -204,7 +205,7 @@ void upgrade_across_migration_and_barrier() {
|
||||
" EVO_PG_RUNTIME_ROLE=evo_runtime_test bash \"$EVO_SOURCE_ROOT/"
|
||||
"tools/migrate-postgres.sh\" > /dev/null") == 0);
|
||||
CHECK(history(*owner_db) ==
|
||||
"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22");
|
||||
"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23");
|
||||
CHECK(scalar(*owner_db, "SELECT count(*) FROM information_schema.columns WHERE "
|
||||
"table_schema = 'evolution' AND table_name = 'region_actions' AND "
|
||||
"column_name IN ('input_bytes', 'result')") == "2");
|
||||
@@ -223,12 +224,24 @@ void upgrade_across_migration_and_barrier() {
|
||||
"'0100000000000000' || '0100000000000000' || repeat('00', 16), 'hex'), "
|
||||
"0, 1)::text") == "1");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT (to_regprocedure('evolution.publish_cellular_checkpoint(bytea,bytea,bytea)') "
|
||||
"SELECT (to_regprocedure('evolution.publish_cellular_checkpoint(bytea,bytea,bytea,bytea)') "
|
||||
"IS NOT NULL)::text") == "true");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT has_function_privilege('evo_runtime_login', "
|
||||
"'evolution.publish_cellular_checkpoint(bytea,bytea,bytea)', 'EXECUTE')::text") ==
|
||||
"'evolution.publish_cellular_checkpoint(bytea,bytea,bytea,bytea)', 'EXECUTE')::text") ==
|
||||
"true");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT has_function_privilege('evo_runtime_login', "
|
||||
"'evolution.publish_cellular_checkpoint(bytea,bytea,bytea)', 'EXECUTE')::text") ==
|
||||
"false");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT (to_regprocedure('evolution.load_cellular_publication_births("
|
||||
"evolution.u64,evolution.u64,uuid,evolution.u64,uuid)') IS NOT NULL)::text") ==
|
||||
"true");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT has_function_privilege('evo_runtime_login', "
|
||||
"'evolution.resolve_cellular_region_commit(evolution.u64,evolution.u64,uuid,"
|
||||
"bytea,bytea,bytea,bytea)', 'EXECUTE')::text") == "true");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT has_table_privilege('evo_runtime_login', "
|
||||
"'evolution.cellular_publications', 'INSERT')::text") == "false");
|
||||
|
||||
@@ -69,7 +69,7 @@ PGDATABASE=upgrade_path psql -X -v ON_ERROR_STOP=1 -1 -v "migration_sha=$v1_sha"
|
||||
-f "$root/migrations/0001_region_bootstrap.sql" > /dev/null
|
||||
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',') FROM evolution.schema_migrations")" = 1
|
||||
PGDATABASE=upgrade_path bash "$root/tools/migrate-postgres.sh"
|
||||
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
|
||||
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
|
||||
# v2 heads have no payload binding: v2->v3 fails closed and leaves history at v2.
|
||||
v2_sha="$(sha256sum "$root/migrations/0002_region_fencing.sql")"
|
||||
v2_sha="${v2_sha%% *}"
|
||||
@@ -90,7 +90,7 @@ PGDATABASE=v3_commits psql -X -v ON_ERROR_STOP=1 \
|
||||
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
|
||||
-c "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'))" > /dev/null
|
||||
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")" = 22:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 23:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
|
||||
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.
|
||||
@@ -144,7 +144,7 @@ PGDATABASE=v6_populated psql -X -v ON_ERROR_STOP=1 \
|
||||
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
|
||||
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '02000000' || '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) || repeat('00', 80), 'hex'))" > /dev/null
|
||||
PGDATABASE=v6_populated bash "$root/tools/migrate-postgres.sh"
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT count(*) FROM evolution.region_commits c, LATERAL evolution.parse_checkpoint_manifest(c.manifest) m WHERE m.commit_sequence = 0 AND m.predecessor_commit IS NULL")" = 1
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(conname, ',') FROM pg_constraint WHERE conrelid = 'evolution.region_heads'::regclass AND contype = 'c' AND pg_get_constraintdef(oid) LIKE '%end_tick%'")" = region_heads_published_tick
|
||||
# Inherited privileges bypass fencing, so every migrate run audits effective rights.
|
||||
@@ -190,9 +190,9 @@ expect_audit_failure 'GRANT SELECT ON evolution.account_controls TO evo_runtime_
|
||||
expect_audit_failure 'REVOKE EXECUTE ON FUNCTION evolution.claim_account_control(evolution.u64, evolution.u64, uuid, evolution.u64, uuid, evolution.u64, evolution.u64, integer) FROM evo_runtime_test' 'GRANT EXECUTE ON FUNCTION evolution.claim_account_control(evolution.u64, evolution.u64, uuid, evolution.u64, uuid, evolution.u64, evolution.u64, integer) TO evo_runtime_test'
|
||||
bash "$root/tools/migrate-postgres.sh" # Restored configuration passes the audit again.
|
||||
# Unknown future versions and checksum drift must not be repaired silently.
|
||||
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=23 WHERE version=22'
|
||||
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=24 WHERE version=23'
|
||||
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=22 WHERE version=23"
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=23 WHERE version=24"
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=14"
|
||||
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=13"
|
||||
|
||||
@@ -61,7 +61,7 @@ SQL
|
||||
[ "$code" != 0 ] && grep -q 'division by zero' "$work/migration.log" || fail "the rehearsal migration did not fail"
|
||||
[ "$(q -c "SELECT count(*) FROM information_schema.columns WHERE table_name = 'region_commits' AND column_name = 'rehearsal_column'")" = 0 ] ||
|
||||
fail "the failed migration left a column"
|
||||
[ "$(q -c 'SELECT max(version) FROM evolution.schema_migrations')" = 22 ] || fail "schema version moved"
|
||||
[ "$(q -c 'SELECT max(version) FROM evolution.schema_migrations')" = 23 ] || fail "schema version moved"
|
||||
wait_ack "$work/b1.log" $((before + 40)) || fail "b1 did not resume after the failed migration"
|
||||
kill -0 "$b1_pid" 2> /dev/null || fail "b1 exited during the failed migration"
|
||||
bash "$root/tools/migrate-postgres.sh" > /dev/null || fail "migrate after the failure"
|
||||
|
||||
@@ -56,6 +56,8 @@ digest_21="$(sha256sum "$root/migrations/0021_cellular_trace_and_recovery.sql")"
|
||||
digest_21="${digest_21%% *}"
|
||||
digest_22="$(sha256sum "$root/migrations/0022_cellular_birth_trace_bound.sql")"
|
||||
digest_22="${digest_22%% *}"
|
||||
digest_23="$(sha256sum "$root/migrations/0023_cellular_birth_publication.sql")"
|
||||
digest_23="${digest_23%% *}"
|
||||
psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
|
||||
--set="migration_sha_2=$digest_2" --set="migration_sha_3=$digest_3" \
|
||||
--set="migration_sha_4=$digest_4" --set="migration_sha_5=$digest_5" \
|
||||
@@ -71,5 +73,6 @@ psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
|
||||
--set="migration_sha_20=$digest_20" \
|
||||
--set="migration_sha_21=$digest_21" \
|
||||
--set="migration_sha_22=$digest_22" \
|
||||
--set="migration_sha_23=$digest_23" \
|
||||
--set="runtime_role=$runtime_role" \
|
||||
--file="$root/migrations/apply.sql"
|
||||
|
||||
Reference in New Issue
Block a user