M12.3: publish and recover durable exact populations
Foundation / checks (ecs) (push) Successful in 2m41s
Foundation / checks (tsan) (push) Failing after 18m12s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 20m41s
Foundation / checks (postgres) (push) Canceled after 20m43s
Foundation / checks (checks) (push) Canceled after 20m49s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (client) (push) Failing after 17m4s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / checks (ecs) (push) Successful in 2m41s
Foundation / checks (tsan) (push) Failing after 18m12s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 20m41s
Foundation / checks (postgres) (push) Canceled after 20m43s
Foundation / checks (checks) (push) Canceled after 20m49s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (client) (push) Failing after 17m4s
Foundation / postgres-tools (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#include "evo/persistence/region_checkpoint.hpp"
|
||||
|
||||
namespace evo::persistence {
|
||||
namespace {
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
next_population(const CheckpointManifest& previous, const Sha256Digest& previous_digest,
|
||||
Uuid commit, const LeaseGrant& lease, std::uint64_t end_tick,
|
||||
const Sha256Digest& build, std::uint64_t bytes, const Sha256Digest& digest,
|
||||
BatchDigests batch, bool transition) {
|
||||
if (!supported(previous) || !encode_manifest(previous) || previous.sequence == 0 ||
|
||||
previous.sequence == ~std::uint64_t{0} || previous.end_tick == 0 ||
|
||||
previous.cellular_versions != cellular_v9_versions || previous_digest == Sha256Digest{} ||
|
||||
lease.frame != previous.frame || lease.epoch == 0 || lease.holder == Uuid{} ||
|
||||
commit == Uuid{} || commit == previous.commit || end_tick < previous.end_tick ||
|
||||
end_tick - previous.end_tick > max_checkpoint_ticks ||
|
||||
(previous.profile != CheckpointProfile::cellular_lives_v1 &&
|
||||
previous.profile != CheckpointProfile::cellular_population_v1) ||
|
||||
(!transition && previous.profile != CheckpointProfile::cellular_population_v1))
|
||||
return std::unexpected(CheckpointError::chain);
|
||||
auto next = previous;
|
||||
if (transition) {
|
||||
next.profile = previous.profile == CheckpointProfile::cellular_lives_v1
|
||||
? CheckpointProfile::cellular_population_v1
|
||||
: CheckpointProfile::cellular_lives_v1;
|
||||
next.history_profile = next.profile == CheckpointProfile::cellular_population_v1
|
||||
? population_history_profile
|
||||
: cellular_revision_history_profile;
|
||||
}
|
||||
next.commit = commit;
|
||||
++next.sequence;
|
||||
next.predecessor_commit = previous.commit;
|
||||
next.predecessor_digest = previous_digest;
|
||||
next.begin_tick = previous.end_tick;
|
||||
next.end_tick = end_tick;
|
||||
next.holder = lease.holder;
|
||||
next.epoch = lease.epoch;
|
||||
next.build = build;
|
||||
next.payload_bytes = bytes;
|
||||
next.payload_sha256 = digest;
|
||||
next.batch = batch;
|
||||
if (!encode_manifest(next))
|
||||
return std::unexpected(CheckpointError::format);
|
||||
return next;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
population_profile_transition_manifest(const CheckpointManifest& previous,
|
||||
const Sha256Digest& previous_digest, Uuid commit,
|
||||
const LeaseGrant& lease, const Sha256Digest& build,
|
||||
std::uint64_t bytes, const Sha256Digest& digest) {
|
||||
return next_population(previous, previous_digest, commit, lease, previous.end_tick, build,
|
||||
bytes, digest, {}, true);
|
||||
}
|
||||
std::expected<CheckpointManifest, CheckpointError> population_successor_manifest(
|
||||
const CheckpointManifest& previous, const Sha256Digest& previous_digest, Uuid commit,
|
||||
const LeaseGrant& lease, std::uint64_t end_tick, const Sha256Digest& build, std::uint64_t bytes,
|
||||
const Sha256Digest& digest, const BatchDigests& batch) {
|
||||
if (batch.trace_bytes == 0)
|
||||
return std::unexpected(CheckpointError::chain);
|
||||
return next_population(previous, previous_digest, commit, lease, end_tick, build, bytes, digest,
|
||||
batch, false);
|
||||
}
|
||||
std::expected<std::unique_ptr<server::CellularPopulation>, CheckpointError>
|
||||
restore_population_payload(std::span<const std::uint8_t> payload, const CheckpointManifest& m) {
|
||||
if (!supported(m) || m.profile != CheckpointProfile::cellular_population_v1)
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
if (!encode_manifest(m) || payload.size() != m.payload_bytes)
|
||||
return std::unexpected(CheckpointError::format);
|
||||
auto state = server::CellularPopulation::restore(payload, m.key.world, m.key.region, m.frame,
|
||||
m.end_tick);
|
||||
if (!state)
|
||||
return std::unexpected(state.error() == server::CellularPopulationError::unsupported
|
||||
? CheckpointError::unsupported
|
||||
: CheckpointError::payload);
|
||||
return std::move(*state);
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
Reference in New Issue
Block a user