install_working_expiry(installer_pool, guard, *, fleet_attestation=None)
Versioned additive offline migration over an attested v1 guard.
Locks nodes/edges/guard against writers. Existing registrations backfill as
permanent; TTL was refused by the old host. Never invoke during admission.
An explicit operator fleet attestation is required; it is not drain proof.
Source code in src/symfonic/memory/backends/postgres_working_expiry.py
| async def install_working_expiry(installer_pool, guard, *, fleet_attestation=None):
"""Versioned additive offline migration over an attested v1 guard.
Locks nodes/edges/guard against writers. Existing registrations backfill as
permanent; TTL was refused by the old host. Never invoke during admission.
An explicit operator fleet attestation is required; it is not drain proof.
"""
from symfonic.memory.backends.postgres_working_expiry_fleet import (
require_expiry_fleet_attestation,
)
require_expiry_fleet_attestation(guard, fleet_attestation)
if bound_connection(installer_pool) is not None:
raise RuntimeError('Working expiry installation requires its own transaction')
conn = await installer_pool.acquire()
try:
async with conn.transaction():
await conn.execute("SET LOCAL lock_timeout = '5s'")
await conn.execute(
"SELECT pg_advisory_xact_lock("
"hashtextextended('symfonic-working-guard-install',0))"
)
if await conn.fetchval('SELECT current_schema()') != guard.schema:
raise RuntimeError('Working expiry installation requires the guard schema')
if await conn.fetchval('SELECT current_user') == guard.working_host_role:
raise RuntimeError('Working expiry installation requires the installer role')
await attest_working_guard(
conn, guard.schema, guard.quoted_schema,
WORKING_GUARD_DDL.replace('__GUARD_SCHEMA__', guard.quoted_schema),
guard.working_host_role,
)
await conn.execute(
f'LOCK TABLE {guard.quoted_schema}.memory_nodes, '
f'{guard.quoted_schema}.memory_edges, '
f'{guard.quoted_schema}.memory_working_endpoint_guard '
'IN SHARE ROW EXCLUSIVE MODE'
)
exists = await conn.fetchval('SELECT to_regclass($1) IS NOT NULL',
guard.quoted_schema + '.memory_working_expiry')
if not exists:
marker = await conn.fetchval(
"SELECT col_description(a.attrelid,a.attnum) FROM pg_attribute a "
"WHERE a.attrelid=to_regclass($1) AND a.attname='retired'",
guard.quoted_schema + '.memory_working_endpoint_guard',
)
if marker is not None:
raise RuntimeError('Working expiry migration is incomplete or conflicts')
await conn.execute(EXPIRY_DDL.replace('__SCHEMA__', guard.quoted_schema)
.replace('__HOST__', guard.working_host_role))
await conn.execute(
f'COMMENT ON COLUMN {guard.quoted_schema}.'
'memory_working_endpoint_guard.retired '
f"IS 'symfonic-working-expiry-v1:{guard.working_host_role}'"
)
await attest_working_expiry(conn, guard)
finally:
await installer_pool.release(conn)
|