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
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:
@@ -1,5 +1,7 @@
|
||||
#include "evo/persistence/cellular_migration_store.hpp"
|
||||
#include "cellular_migration_observation_detail.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/server/lifecycle/cellular_census_set.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
@@ -441,6 +443,74 @@ load_cellular_migration_stage(Postgres& db, const FilesystemObjectStore& objects
|
||||
return fail(RecoveryError::history);
|
||||
return result;
|
||||
}
|
||||
namespace detail {
|
||||
std::expected<std::vector<CapturedCellularMigration>, RecoveryFailure>
|
||||
capture_cellular_migrations(Postgres& db, std::uint64_t world, milliseconds timeout) {
|
||||
const std::array<std::string, 1> args{std::to_string(world)};
|
||||
const auto rows =
|
||||
db.query("SELECT encode(trace,'hex'),encode(source_manifest,'hex'),"
|
||||
"encode(destination_manifest,'hex'),encode(ghost_sha256,'hex'),"
|
||||
"pg_catalog.trunc(ghost_bytes)::text,coherent::text "
|
||||
"FROM evolution.load_world_cellular_migrations_v1($1::evolution.u64)",
|
||||
args, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected(RecoveryFailure{RecoveryError::store, failure(rows.error())});
|
||||
if (rows->size() > server::max_cellular_census_regions)
|
||||
return std::unexpected(
|
||||
RecoveryFailure{RecoveryError::store, {LeaseStoreError::invalid, {PgError::bounds}}});
|
||||
std::vector<CapturedCellularMigration> result;
|
||||
for (const auto& row : *rows) {
|
||||
if (row.size() != 6 || row[5].value_or("") != "true")
|
||||
return std::unexpected(RecoveryFailure{RecoveryError::history});
|
||||
auto cut = parse({row[0], row[1], row[2], std::string{"false"}});
|
||||
if (!cut)
|
||||
return std::unexpected(RecoveryFailure{RecoveryError::history});
|
||||
std::optional<VerifiedObject> ghost;
|
||||
if (row[3] || row[4]) {
|
||||
auto stage =
|
||||
parse_stage({row[0], row[1], row[2], std::string{"false"}, row[3], row[4]});
|
||||
if (!stage)
|
||||
return std::unexpected(RecoveryFailure{RecoveryError::history});
|
||||
ghost = stage->ghost;
|
||||
}
|
||||
result.push_back(
|
||||
{std::move(cut->trace), std::move(cut->source), std::move(cut->destination), ghost});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::expected<CellularMigrationObservation, RecoveryFailure>
|
||||
verify_captured_cellular_migration(const CapturedCellularMigration& record,
|
||||
const FilesystemObjectStore& source_objects,
|
||||
const FilesystemObjectStore& destination_objects) {
|
||||
const auto fail = [](RecoveryError kind) { return std::unexpected(RecoveryFailure{kind}); };
|
||||
auto trace = server::decode_migration_trace(record.trace);
|
||||
const auto s = decode_manifest(record.source), d = decode_manifest(record.destination);
|
||||
const auto sd = sha256(record.source), dd = sha256(record.destination);
|
||||
if (!trace || !s || !d || !sd || !dd || !cuts(*s, *d, *sd, *dd, *trace))
|
||||
return fail(RecoveryError::history);
|
||||
const auto source = source_objects.get({s->payload_sha256, s->payload_bytes});
|
||||
const auto capsule = source_objects.get({d->payload_sha256, d->payload_bytes});
|
||||
if (!source || !capsule)
|
||||
return fail(RecoveryError::tail);
|
||||
const auto replay = derive(*s, *d, *source, *capsule, trace->request);
|
||||
if (!replay || *replay != *trace)
|
||||
return fail(RecoveryError::history);
|
||||
if (record.ghost) {
|
||||
if (record.ghost->sha256 == Sha256Digest{} || record.ghost->bytes == 0 ||
|
||||
record.ghost->bytes > max_payload_bytes(d->profile))
|
||||
return fail(RecoveryError::history);
|
||||
const auto sc = destination_objects.get({s->payload_sha256, s->payload_bytes});
|
||||
const auto dc = destination_objects.get({d->payload_sha256, d->payload_bytes});
|
||||
const auto ghost = destination_objects.get(*record.ghost);
|
||||
if (!sc || !dc || !ghost)
|
||||
return fail(RecoveryError::tail);
|
||||
const auto candidate = ghost_candidate(*s, *d, *sc, *dc, *trace);
|
||||
if (!candidate || *candidate != *ghost)
|
||||
return fail(RecoveryError::history);
|
||||
}
|
||||
return CellularMigrationObservation{std::move(*trace), record.ghost.has_value()};
|
||||
}
|
||||
} // namespace detail
|
||||
namespace {
|
||||
constexpr auto commit_columns =
|
||||
"encode(trace,'hex'),encode(source_predecessor,'hex'),"
|
||||
|
||||
Reference in New Issue
Block a user