Implement M7.4a checkpoint publication and verified recovery
ADR-0061 publishes environmental-v1 full checkpoints. Manifest v1 is a fixed 280-byte record (identity, chain, lease, versions, build, zero RNG/history declarations, durability policy, payload length/SHA-256) that PostgreSQL parses and digests itself. Schema v3 adds region_commits with a digest CHECK and a composite head FK, owner-managed retained builds, fenced publish/load functions and owner-only genesis; it drops the bare v2 head kernel and fails closed while v2 heads exist. Linux evo::region_store adds OpenSSL SHA-256, an immutable content-addressed filesystem object store (temp+fsync+link, no overwrite/delete, O_NOFOLLOW exact-length verified reads), and publication (validate -> upload -> read back -> fenced transaction -> receipt check) and recovery (re-digest, allowlist, verify, full restore). Portable evo::region_checkpoint holds the codec and payload validation. Validated: Windows CTest 56/56; WSL Release, clang-tidy and ASan/UBSan private-PostgreSQL suites; four SQL and one host mutation each caught. M7.4 stays open for 7.4b (lineage archive codec and history binding). No Docker/Gitea CI, remote store, process kill or deployment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
// Linux-only calls to the fenced database functions of migration v2 (ADR-0060).
|
||||
// Each call is one statement on a caller-owned connection; outside an explicit
|
||||
@@ -15,6 +17,8 @@ enum class LeaseStoreError : std::uint8_t {
|
||||
head_mismatch, // Expected predecessor is not the committed head.
|
||||
not_provisioned, // No genesis; runtime can never create one.
|
||||
exhausted, // Epoch or commit sequence would wrap: fail closed.
|
||||
unsupported, // Profile/version/build not admitted, or rules/quantum changed.
|
||||
commit_conflict, // Commit ID already used by another manifest (resolve at M7.5).
|
||||
invalid, // Rejected arguments; nothing changed.
|
||||
store, // Other SQL/configuration failure; nothing committed.
|
||||
unknown, // May have executed; reconnect and reconcile before reuse.
|
||||
@@ -23,10 +27,10 @@ struct LeaseStoreFailure {
|
||||
LeaseStoreError kind{};
|
||||
PgFailure cause{};
|
||||
};
|
||||
struct HeadAdvance {
|
||||
Uuid commit{};
|
||||
Sha256Digest digest{};
|
||||
std::uint64_t end_tick{};
|
||||
// Committed head and the exact manifest bytes its digest covers.
|
||||
struct CommittedCheckpoint {
|
||||
RegionHead head{};
|
||||
std::vector<std::uint8_t> manifest;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::expected<LeaseGrant, LeaseStoreFailure>
|
||||
@@ -41,10 +45,13 @@ release_region_lease(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<RegionHead, LeaseStoreFailure>
|
||||
load_region_head(Postgres& db, RegionKey key, std::chrono::milliseconds timeout);
|
||||
// Locks the lease then the head; requires unexpired holder/epoch and the exact
|
||||
// expected predecessor. head_mismatch after unknown: load the head and compare.
|
||||
[[nodiscard]] std::expected<CommittedCheckpoint, LeaseStoreFailure>
|
||||
load_region_checkpoint(Postgres& db, RegionKey key, std::chrono::milliseconds timeout);
|
||||
// Canonical manifest v1 bytes; the database parses identity, lease and chain from
|
||||
// them, locks the lease then the head and requires the exact committed predecessor.
|
||||
// The payload must already be verified in the object store. head_mismatch after
|
||||
// unknown: load the head and compare its commit ID (full resolution is M7.5).
|
||||
[[nodiscard]] std::expected<RegionHead, LeaseStoreFailure>
|
||||
advance_region_head(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const RegionHead& expected, const HeadAdvance& next,
|
||||
std::chrono::milliseconds timeout);
|
||||
publish_region_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::chrono::milliseconds timeout);
|
||||
} // namespace evo::persistence
|
||||
|
||||
Reference in New Issue
Block a user