Add durable cellular mutation reservations
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (checks) (push) Failing after 4m5s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 3m44s
Foundation / checks (postgres) (push) Canceled after 1m44s
Foundation / checks (client) (push) Canceled after 5m49s

This commit is contained in:
dingo
2026-10-11 07:20:26 -04:00
parent 5c4ab4c1ce
commit 4bc8dfc05d
9 changed files with 328 additions and 14 deletions
@@ -1,6 +1,7 @@
#pragma once
#include "evo/persistence/postgres.hpp"
#include "evo/persistence/region_lease.hpp"
#include <array>
#include <chrono>
#include <cstdint>
#include <expected>
@@ -16,7 +17,9 @@ enum class LifeReservationError : std::uint8_t {
exhausted,
invalid,
store,
unknown // May have committed. Reconnect and retry the SAME request to reconcile.
unknown, // May have committed. Reconnect and retry the SAME request to reconcile.
pending_mutation,
identity_conflict
};
struct LifeReservationFailure {
LifeReservationError kind{};
@@ -46,6 +49,14 @@ struct PrimitiveLifeOutcome {
std::optional<PrimitiveLifeBinding> published;
friend bool operator==(const PrimitiveLifeOutcome&, const PrimitiveLifeOutcome&) = default;
};
inline constexpr std::size_t cellular_mutation_reservation_input_bytes = 34;
struct CellularMutationReservation {
Uuid account{};
std::uint64_t action_id{}, region{}, generation{}, target_tick{}, successor_identity{};
std::array<std::uint8_t, cellular_mutation_reservation_input_bytes> input{};
friend bool operator==(const CellularMutationReservation&,
const CellularMutationReservation&) = default;
};
// Exact retry returns the original identity/owning region/refusal, even after
// account control moves. The result grants no authority in the returned region.
// request_id is in the new-life namespace, separate from M10 probe action IDs.
@@ -74,4 +85,17 @@ query_primitive_life(Postgres& db, RegionKey key, const LeaseGrant& lease, const
[[nodiscard]] std::expected<std::optional<std::uint64_t>, LifeReservationFailure>
primitive_life_owner(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
std::chrono::milliseconds timeout);
// Schema v29, ADR-0121. The canonical bytes are target tick (u64 LE), life ID
// (u64 LE), offer event index (u64 LE), offer tick (u64 LE), and operator ID
// (u16 LE). Exact retries return the same world-allocated successor identity.
[[nodiscard]] std::expected<CellularMutationReservation, LifeReservationFailure>
reserve_cellular_mutation(
Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
std::uint64_t generation, std::uint64_t action_id,
const std::array<std::uint8_t, cellular_mutation_reservation_input_bytes>& input,
std::chrono::milliseconds timeout);
// Pending selections are reloaded under the recovered region lease after restart.
[[nodiscard]] std::expected<std::vector<CellularMutationReservation>, LifeReservationFailure>
load_pending_cellular_mutations(Postgres& db, RegionKey key, const LeaseGrant& lease,
std::chrono::milliseconds timeout);
} // namespace evo::persistence