#pragma once #include "evo/persistence/cellular_history_store.hpp" #include "evo/persistence/cellular_migration_store.hpp" #include "evo/server/lifecycle/cellular_census_set.hpp" #include #include #include #include #include #include #include namespace evo::persistence { struct CellularCensusRegionRequest { std::uint64_t region{}; LeaseGrant lease{}; const FilesystemObjectStore* objects{}; // Non-owning, valid throughout the call. }; struct CellularCensusSnapshot { std::vector cuts; // Sorted regions, exact captured head/manifest pairs. server::CellularCensusSet census; }; enum class CellularSnapshotError : std::uint8_t { invalid_request, transaction, history, census, coverage, context, migration }; struct RegisteredCellularRegion { std::uint64_t region{}, frame{}; bool operator==(const RegisteredCellularRegion&) const = default; }; enum class CellularCoverageError : std::uint8_t { store, unknown_world, bounds, regions, frame, malformed }; struct CellularCoverageFailure { CellularCoverageError kind{}; PgFailure cause{}; // Meaningful for store. }; struct RegisteredCellularCensusSnapshot { std::vector catalog; // Exact registry view used for head selection. CellularCensusSnapshot snapshot; Uuid history_domain{}; // Schema 51 database namespace captured with catalog and heads. std::vector migrations; // Schema 52 verified pending handoffs. }; struct CellularSnapshotFailure { CellularSnapshotError kind{}; std::uint64_t region{}; // Failed region, or zero for a request/transaction/set error. PgFailure transaction{}; // Meaningful for transaction. CellularHistoryFailure history{}; // Meaningful for history. server::CellularCensusSetError census{}; // Meaningful for census. CellularCoverageFailure coverage{}; // Meaningful for coverage. RecoveryFailure migration{}; // Meaningful for migration; no partial result on failure. }; // Test/fault seam after each head has been captured (zero-based request index). // Production callers pass nothing. A throwing hook closes the capture connection. struct CellularCensusSnapshotHooks { std::function after_head; }; // Idle connected session only. Requests: 1..64, nonzero strictly ascending regions // in one world; all stores nonnull. Capture current heads in a short READ ONLY // REPEATABLE READ transaction, finish it, then fully replay each immutable cut. // All cuts must share frame/tick/owner/rules/quantum/projection. No partial census. // Per-I/O timeout 1..30000 ms; no automatic retry or whole-query latency promise. // Metadata failures roll back; failed cleanup or an exception closes the session. // Caller-declared coverage, NOT world/branch completeness or live authority. [[nodiscard]] std::expected load_cellular_census_snapshot(Postgres&, std::uint64_t world, std::span, std::span retained_builds, std::chrono::milliseconds timeout, const CellularCensusSnapshotHooks& hooks = {}); // Schema 52: require resources for EVERY registered region of this world, // including expired/released holders and regions with unavailable checkpoints. // Capture domain, registry, pending handoffs and heads in the SAME database view. // Fully verify retained handoff capsules/ghosts after capture. Ghosts add no stock. // Empty/over-bound registries or any coverage/frame mismatch fail, never zero. // Completeness is only for registered regions of this connected database view; // Domain/world identifies this database history, including supported restore forks. // No other viable-store reconciliation, live authority or terminal extinction. [[nodiscard]] std::expected load_registered_cellular_census_snapshot(Postgres&, std::uint64_t world, std::span, std::span retained_builds, std::chrono::milliseconds timeout, const CellularCensusSnapshotHooks& hooks = {}); } // namespace evo::persistence