M12.7: reconcile pending migration evidence in census snapshots
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (network) (push) Successful in 21m1s
Foundation / checks (client) (push) Successful in 22m9s
Foundation / checks (tsan) (push) Successful in 24m36s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 33m38s
Foundation / checks (checks) (push) Canceled after 33m49s

This commit is contained in:
dingo
2026-10-18 21:14:53 -04:00
parent 709dfb9557
commit 27ec5729bf
23 changed files with 592 additions and 23 deletions
+48 -1
View File
@@ -1,5 +1,7 @@
#include "evo/persistence/cellular_census_snapshot.hpp"
#include "cellular_migration_observation_detail.hpp"
#include <algorithm>
#include <array>
#include <charconv>
#include <optional>
@@ -19,10 +21,14 @@ auto history_failure(std::uint64_t region, CellularHistoryFailure error) {
auto coverage_failure(CellularCoverageError kind, PgFailure cause = {}) {
return std::unexpected(Failure{Error::coverage, 0, {}, {}, {}, {kind, cause}});
}
auto migration_failure(RecoveryFailure cause, std::uint64_t region = 0) {
return std::unexpected(Failure{Error::migration, region, {}, {}, {}, {}, cause});
}
struct Captured {
std::vector<RegisteredCellularRegion> catalog;
std::vector<CommittedCheckpoint> cuts;
Uuid history_domain{};
std::vector<detail::CapturedCellularMigration> migrations;
};
std::expected<Uuid, Failure> history_domain(Postgres& db, std::chrono::milliseconds timeout) {
const auto rows = db.query("SELECT pg_catalog.encode(pg_catalog.uuid_send("
@@ -120,6 +126,10 @@ std::expected<Captured, Failure> capture(Postgres& db, std::uint64_t world,
return coverage_failure(CellularCoverageError::frame);
}
captured.catalog = std::move(*required);
auto pending = detail::capture_cellular_migrations(db, world, timeout);
if (!pending)
return migration_failure(pending.error());
captured.migrations = std::move(*pending);
}
captured.cuts.reserve(requests.size());
for (std::size_t i = 0; i < requests.size(); ++i) {
@@ -163,6 +173,42 @@ load_snapshot(Postgres& db, std::uint64_t world,
auto cuts = capture(db, world, requests, timeout, hooks, registered);
if (!cuts)
return std::unexpected(cuts.error());
std::vector<CellularMigrationObservation> migrations;
for (const auto& pending : cuts->migrations) {
const auto source_manifest = decode_manifest(pending.source);
const auto destination_manifest = decode_manifest(pending.destination);
if (!source_manifest || !destination_manifest)
return migration_failure({RecoveryError::manifest});
if (std::ranges::find(builds, source_manifest->build) == builds.end() ||
std::ranges::find(builds, destination_manifest->build) == builds.end())
return migration_failure({RecoveryError::unsupported});
const auto trace = server::decode_migration_trace(pending.trace);
if (!trace || trace->world != world ||
(!migrations.empty() &&
trace->request.request <= migrations.back().trace.request.request))
return migration_failure({RecoveryError::history});
const auto endpoint = [&](std::uint64_t region) {
return std::ranges::lower_bound(requests, region, {},
&CellularCensusRegionRequest::region);
};
const auto s = endpoint(trace->request.source.region);
const auto d = endpoint(trace->request.destination.region);
if (s == requests.end() || d == requests.end() ||
s->region != trace->request.source.region ||
d->region != trace->request.destination.region || s->lease.frame != trace->frame ||
d->lease.frame != trace->frame)
return migration_failure({RecoveryError::history});
const auto si = static_cast<std::size_t>(s - requests.begin());
const auto di = static_cast<std::size_t>(d - requests.begin());
if (cuts->cuts[si].manifest != pending.source ||
(pending.ghost && cuts->cuts[di].manifest != pending.destination))
return migration_failure({RecoveryError::history}, s->region);
auto verified =
detail::verify_captured_cellular_migration(pending, *s->objects, *d->objects);
if (!verified)
return migration_failure(verified.error(), s->region);
migrations.push_back(std::move(*verified));
}
std::vector<server::CellularCensus> observations;
observations.reserve(requests.size());
for (std::size_t i = 0; i < requests.size(); ++i) {
@@ -187,7 +233,8 @@ load_snapshot(Postgres& db, std::uint64_t world,
return std::unexpected(Failure{Error::census, 0, {}, {}, census.error()});
return RegisteredCellularCensusSnapshot{std::move(cuts->catalog),
{std::move(cuts->cuts), std::move(*census)},
cuts->history_domain};
cuts->history_domain,
std::move(migrations)};
}
} // namespace