Complete M7.4b lineage checkpoint profile; M7.4 done
ADR-0062 adds a canonical LineageArchive codec (parents before children, organisms by id, FNV) that decodes by replaying admit/record_birth/ record_death and requires byte-identical re-encoding; it never overwrites an existing archive. LineageRegion binds the environmental producer and consumer accounts to archived organisms with identity high-waters, enforces closure (lifecycle vs deaths, exact living set, tick bounds) and records deaths in the tick that causes them. Checkpoint profile 2 (environmental-lineage-v1, history profile 1) publishes that container; schema v4 admits it with a 4,268,144-byte cap and requires each commit to keep its predecessor's profile, RNG, history and durability declarations. Linux adds provision/publish/recover for the profile on the shared publication path. Qualification found WSL2 stepping CLOCK_REALTIME back ~0.5 s every ~32 s, which made two 1 s-lease tests flaky under ASan. Tests now wait on database-time expiry; ADR-0060 records the slewed-clock requirement. Validated: Windows CTest 57/57; Linux GCC Debug/Release, clang-tidy and ASan/UBSan CTest 57/57 each; PostgreSQL suites 2x Release, 2x analysis, 5x ASan; SQL and C++ mutations each caught. 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:
@@ -7,16 +7,56 @@
|
||||
namespace evo::persistence {
|
||||
namespace {
|
||||
using std::chrono::milliseconds;
|
||||
|
||||
// Per-profile payload operations; the publication and recovery paths are shared.
|
||||
struct EnvironmentalCodec {
|
||||
using State = processes::EnvironmentalCommunity;
|
||||
using Recovered = RecoveredCheckpoint;
|
||||
static constexpr auto profile = CheckpointProfile::environmental_v1;
|
||||
static auto snapshot(const State& s) {
|
||||
return s.snapshot();
|
||||
}
|
||||
static std::uint64_t tick(const State& s) {
|
||||
return s.progress().tick;
|
||||
}
|
||||
static std::uint64_t quantum(const State& s) {
|
||||
return s.tick_microseconds();
|
||||
}
|
||||
static auto restore(std::span<const std::uint8_t> payload, const CheckpointManifest& m,
|
||||
std::size_t budget) {
|
||||
return restore_environmental_payload(payload, m, budget);
|
||||
}
|
||||
};
|
||||
struct LineageCodec {
|
||||
using State = processes::LineageRegion;
|
||||
using Recovered = RecoveredLineageCheckpoint;
|
||||
static constexpr auto profile = CheckpointProfile::environmental_lineage_v1;
|
||||
static auto snapshot(const State& s) {
|
||||
return s.snapshot();
|
||||
}
|
||||
static std::uint64_t tick(const State& s) {
|
||||
return s.community().progress().tick;
|
||||
}
|
||||
static std::uint64_t quantum(const State& s) {
|
||||
return s.community().tick_microseconds();
|
||||
}
|
||||
static auto restore(std::span<const std::uint8_t> payload, const CheckpointManifest& m,
|
||||
std::size_t budget) {
|
||||
return restore_lineage_payload(payload, m, budget);
|
||||
}
|
||||
};
|
||||
|
||||
PublicationFailure fail(PublicationError kind) {
|
||||
return {kind, {}, {}};
|
||||
}
|
||||
// Encodes the candidate, validates the exact payload bytes as recovery would,
|
||||
// uploads and reads back. Returns the manifest bytes ready for the database.
|
||||
// Validates the exact payload bytes as recovery would, uploads and reads back.
|
||||
// Returns the manifest bytes ready for the database.
|
||||
template <typename Codec>
|
||||
std::expected<std::vector<std::uint8_t>, PublicationFailure>
|
||||
stage(const FilesystemObjectStore& objects, const std::vector<std::uint8_t>& payload,
|
||||
const CheckpointManifest& manifest, std::size_t budget) {
|
||||
auto bytes = encode_manifest(manifest);
|
||||
if (!bytes || !restore_environmental_payload(payload, manifest, budget))
|
||||
if (!bytes || manifest.profile != Codec::profile || !Codec::restore(payload, manifest, budget))
|
||||
return std::unexpected{fail(PublicationError::candidate)};
|
||||
auto stored = objects.put(payload);
|
||||
if (!stored)
|
||||
@@ -45,23 +85,23 @@ confirm(const std::expected<RegionHead, LeaseStoreFailure>& published,
|
||||
return std::unexpected{fail(PublicationError::receipt)};
|
||||
return CommittedCheckpoint{*published, std::move(manifest_bytes)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::expected<CommittedCheckpoint, PublicationFailure> provision_environmental_region(
|
||||
Postgres& owner, const FilesystemObjectStore& objects, RegionKey key, std::uint64_t frame,
|
||||
const processes::EnvironmentalCommunity& opening, Uuid commit, const Sha256Digest& build,
|
||||
std::size_t restore_budget, milliseconds timeout) {
|
||||
auto payload = opening.snapshot();
|
||||
if (!payload || opening.progress().tick != 0)
|
||||
template <typename Codec>
|
||||
std::expected<CommittedCheckpoint, PublicationFailure>
|
||||
provision(Postgres& owner, const FilesystemObjectStore& objects, RegionKey key, std::uint64_t frame,
|
||||
const typename Codec::State& opening, Uuid commit, const Sha256Digest& build,
|
||||
std::size_t budget, milliseconds timeout) {
|
||||
auto payload = Codec::snapshot(opening);
|
||||
if (!payload || Codec::tick(opening) != 0)
|
||||
return std::unexpected{fail(PublicationError::candidate)};
|
||||
const auto digest = sha256(*payload);
|
||||
if (!digest)
|
||||
return std::unexpected{fail(PublicationError::digest)};
|
||||
auto manifest = genesis_manifest(key, frame, commit, opening.tick_microseconds(), build,
|
||||
payload->size(), *digest);
|
||||
auto manifest = genesis_manifest(key, frame, commit, Codec::quantum(opening), build,
|
||||
payload->size(), *digest, Codec::profile);
|
||||
if (!manifest)
|
||||
return std::unexpected{fail(PublicationError::candidate)};
|
||||
auto bytes = stage(objects, *payload, *manifest, restore_budget);
|
||||
auto bytes = stage<Codec>(objects, *payload, *manifest, budget);
|
||||
if (!bytes)
|
||||
return std::unexpected{bytes.error()};
|
||||
constexpr char digits[] = "0123456789abcdef";
|
||||
@@ -73,14 +113,11 @@ std::expected<CommittedCheckpoint, PublicationFailure> provision_environmental_r
|
||||
const std::array<std::string, 1> p{parameter};
|
||||
auto done = owner.query("SELECT evolution.provision_region_checkpoint($1::bytea)", p, timeout);
|
||||
if (!done) {
|
||||
const auto kind = done.error().kind == PgError::unknown ? PublicationError::unknown
|
||||
: PublicationError::rejected;
|
||||
return std::unexpected{
|
||||
PublicationFailure{kind,
|
||||
{done.error().kind == PgError::unknown ? LeaseStoreError::unknown
|
||||
: LeaseStoreError::store,
|
||||
done.error()},
|
||||
{}}};
|
||||
const bool unknown = done.error().kind == PgError::unknown;
|
||||
return std::unexpected{PublicationFailure{
|
||||
unknown ? PublicationError::unknown : PublicationError::rejected,
|
||||
{unknown ? LeaseStoreError::unknown : LeaseStoreError::store, done.error()},
|
||||
{}}};
|
||||
}
|
||||
auto committed = load_region_checkpoint(owner, key, timeout);
|
||||
if (!committed)
|
||||
@@ -89,32 +126,33 @@ std::expected<CommittedCheckpoint, PublicationFailure> provision_environmental_r
|
||||
return confirm(committed->head, std::move(*bytes), *manifest);
|
||||
}
|
||||
|
||||
std::expected<CommittedCheckpoint, PublicationFailure> publish_environmental_checkpoint(
|
||||
Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, const processes::EnvironmentalCommunity& state,
|
||||
Uuid commit, const Sha256Digest& build, std::size_t restore_budget, milliseconds timeout) {
|
||||
template <typename Codec>
|
||||
std::expected<CommittedCheckpoint, PublicationFailure>
|
||||
publish(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, const typename Codec::State& state, Uuid commit,
|
||||
const Sha256Digest& build, std::size_t budget, milliseconds timeout) {
|
||||
const auto previous = decode_manifest(predecessor.manifest);
|
||||
auto payload = state.snapshot();
|
||||
if (!previous || !payload)
|
||||
auto payload = Codec::snapshot(state);
|
||||
if (!previous || !payload || previous->profile != Codec::profile)
|
||||
return std::unexpected{fail(PublicationError::candidate)};
|
||||
const auto digest = sha256(*payload);
|
||||
if (!digest)
|
||||
return std::unexpected{fail(PublicationError::digest)};
|
||||
auto manifest = successor_manifest(*previous, predecessor.head.digest, commit, lease,
|
||||
state.progress().tick, build, payload->size(), *digest);
|
||||
Codec::tick(state), build, payload->size(), *digest);
|
||||
if (!manifest)
|
||||
return std::unexpected{fail(PublicationError::candidate)};
|
||||
auto bytes = stage(objects, *payload, *manifest, restore_budget);
|
||||
auto bytes = stage<Codec>(objects, *payload, *manifest, budget);
|
||||
if (!bytes)
|
||||
return std::unexpected{bytes.error()};
|
||||
auto published = publish_region_checkpoint(db, *bytes, timeout);
|
||||
return confirm(published, std::move(*bytes), *manifest);
|
||||
}
|
||||
|
||||
std::expected<RecoveredCheckpoint, RecoveryFailure>
|
||||
recover_environmental_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
std::span<const Sha256Digest> retained_builds,
|
||||
std::size_t restore_budget, milliseconds timeout) {
|
||||
template <typename Codec>
|
||||
std::expected<typename Codec::Recovered, RecoveryFailure>
|
||||
recover(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
std::span<const Sha256Digest> retained_builds, std::size_t budget, milliseconds timeout) {
|
||||
auto committed = load_region_checkpoint(db, key, timeout);
|
||||
if (!committed)
|
||||
return std::unexpected{
|
||||
@@ -138,7 +176,7 @@ recover_environmental_checkpoint(Postgres& db, const FilesystemObjectStore& obje
|
||||
manifest->sequence != head.sequence || manifest->commit != head.commit ||
|
||||
manifest->end_tick != head.end_tick)
|
||||
return fail_with(RecoveryError::manifest);
|
||||
if (!supported(*manifest) ||
|
||||
if (!supported(*manifest) || manifest->profile != Codec::profile ||
|
||||
std::ranges::find(retained_builds, manifest->build) == retained_builds.end())
|
||||
return fail_with(RecoveryError::unsupported);
|
||||
auto payload = objects.get({manifest->payload_sha256, manifest->payload_bytes});
|
||||
@@ -146,9 +184,53 @@ recover_environmental_checkpoint(Postgres& db, const FilesystemObjectStore& obje
|
||||
return fail_with(payload.error() == ObjectError::missing ? RecoveryError::missing_payload
|
||||
: payload.error() == ObjectError::corrupt ? RecoveryError::corrupt_payload
|
||||
: RecoveryError::store);
|
||||
auto state = restore_environmental_payload(*payload, *manifest, restore_budget);
|
||||
auto state = Codec::restore(*payload, *manifest, budget);
|
||||
if (!state)
|
||||
return fail_with(RecoveryError::payload);
|
||||
return RecoveredCheckpoint{std::move(*committed), *manifest, std::move(*state)};
|
||||
return typename Codec::Recovered{std::move(*committed), *manifest, std::move(*state)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::expected<CommittedCheckpoint, PublicationFailure> provision_environmental_region(
|
||||
Postgres& owner, const FilesystemObjectStore& objects, RegionKey key, std::uint64_t frame,
|
||||
const processes::EnvironmentalCommunity& opening, Uuid commit, const Sha256Digest& build,
|
||||
std::size_t restore_budget, milliseconds timeout) {
|
||||
return provision<EnvironmentalCodec>(owner, objects, key, frame, opening, commit, build,
|
||||
restore_budget, timeout);
|
||||
}
|
||||
std::expected<CommittedCheckpoint, PublicationFailure> publish_environmental_checkpoint(
|
||||
Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, const processes::EnvironmentalCommunity& state,
|
||||
Uuid commit, const Sha256Digest& build, std::size_t restore_budget, milliseconds timeout) {
|
||||
return publish<EnvironmentalCodec>(db, objects, lease, predecessor, state, commit, build,
|
||||
restore_budget, timeout);
|
||||
}
|
||||
std::expected<RecoveredCheckpoint, RecoveryFailure>
|
||||
recover_environmental_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
std::span<const Sha256Digest> retained_builds,
|
||||
std::size_t restore_budget, milliseconds timeout) {
|
||||
return recover<EnvironmentalCodec>(db, objects, key, retained_builds, restore_budget, timeout);
|
||||
}
|
||||
|
||||
std::expected<CommittedCheckpoint, PublicationFailure>
|
||||
provision_lineage_region(Postgres& owner, const FilesystemObjectStore& objects, RegionKey key,
|
||||
std::uint64_t frame, const processes::LineageRegion& opening, Uuid commit,
|
||||
const Sha256Digest& build, std::size_t restore_budget,
|
||||
milliseconds timeout) {
|
||||
return provision<LineageCodec>(owner, objects, key, frame, opening, commit, build,
|
||||
restore_budget, timeout);
|
||||
}
|
||||
std::expected<CommittedCheckpoint, PublicationFailure> publish_lineage_checkpoint(
|
||||
Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, const processes::LineageRegion& state, Uuid commit,
|
||||
const Sha256Digest& build, std::size_t restore_budget, milliseconds timeout) {
|
||||
return publish<LineageCodec>(db, objects, lease, predecessor, state, commit, build,
|
||||
restore_budget, timeout);
|
||||
}
|
||||
std::expected<RecoveredLineageCheckpoint, RecoveryFailure>
|
||||
recover_lineage_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
std::span<const Sha256Digest> retained_builds,
|
||||
std::size_t restore_budget, milliseconds timeout) {
|
||||
return recover<LineageCodec>(db, objects, key, retained_builds, restore_budget, timeout);
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
Reference in New Issue
Block a user