-- M10.8d overdue probe transfers (ADR-0096). A source region aborts the transfers whose -- client never arrived once their ticket has expired; it kept that deadline only in memory, -- so a source restarted after a prepare (SIGKILL, lease loss) left the probe frozen for good. -- This lists the caller's open outgoing transfers prepared more than `p_age_seconds` ago by -- the database clock, so any later process holding the region's lease can abort them (abort -- is serialized with stage and commit: a transfer committed meanwhile stays committed). -- Read-only, under the caller's exact unexpired region lease. At most 256 rows, oldest first. CREATE FUNCTION evolution.overdue_probe_transfers(p_world evolution.u64, p_region evolution.u64, p_holder uuid, p_epoch evolution.u64, p_age_seconds integer) RETURNS TABLE (transfer_id uuid) LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$ DECLARE now_t timestamptz; BEGIN IF p_age_seconds IS NULL OR p_age_seconds NOT BETWEEN 1 AND 86400 THEN RAISE EXCEPTION 'invalid probe request' USING ERRCODE = '22023'; END IF; now_t := evolution.check_region_lease(p_world, p_region, p_holder, p_epoch); RETURN QUERY SELECT t.transfer_id FROM evolution.probe_transfers t WHERE t.world_id = p_world AND t.source_region = p_region AND t.state IN ('prepared', 'staged') AND t.prepared_at < now_t - p_age_seconds * interval '1 second' ORDER BY t.prepared_at, t.transfer_id LIMIT 256; END $$; REVOKE ALL ON FUNCTION evolution.overdue_probe_transfers(evolution.u64, evolution.u64, uuid, evolution.u64, integer) FROM PUBLIC; GRANT EXECUTE ON FUNCTION evolution.overdue_probe_transfers(evolution.u64, evolution.u64, uuid, evolution.u64, integer) TO :"runtime_role"; INSERT INTO evolution.schema_migrations(version, sha256) VALUES (14, :'migration_sha_14');