Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (client) (push) Successful in 12m15s
Foundation / checks (network) (push) Successful in 13m46s
Foundation / checks (tsan) (push) Successful in 8m9s
Foundation / checks (checks) (push) Successful in 33m12s
Foundation / checks (postgres) (push) Successful in 46m13s
Foundation / postgres-tools (push) Successful in 48s
Foundation / image (push) Successful in 2m45s
Foundation / server-image (push) Successful in 4m27s
49 lines
2.1 KiB
C++
49 lines
2.1 KiB
C++
#pragma once
|
|
#include "evo/persistence/postgres.hpp"
|
|
#include "evo/persistence/region_lease.hpp"
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
|
|
namespace evo::persistence {
|
|
// Schema v15, ADR-0100. These operations allocate identity, never a biological
|
|
// body. Each call is one statement on the caller's connection, without retries.
|
|
enum class LifeReservationError : std::uint8_t {
|
|
existing_life,
|
|
fenced,
|
|
not_available, // Missing allocator/reservation, or reservation belongs elsewhere.
|
|
exhausted,
|
|
invalid,
|
|
store,
|
|
unknown // May have committed. Reconnect and retry the SAME request to reconcile.
|
|
};
|
|
struct LifeReservationFailure {
|
|
LifeReservationError kind{};
|
|
PgFailure cause{};
|
|
};
|
|
enum class LifeRefusal : std::uint8_t {
|
|
none = 0, // Reserved only; NOT successful spawn.
|
|
insufficient_funding = 1,
|
|
no_placement = 2,
|
|
cancelled = 3
|
|
};
|
|
struct LifeReservation {
|
|
std::uint64_t identity{}, region{};
|
|
LifeRefusal refusal{};
|
|
friend bool operator==(const LifeReservation&, const LifeReservation&) = 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.
|
|
[[nodiscard]] std::expected<LifeReservation, LifeReservationFailure>
|
|
reserve_primitive_life(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
|
std::uint64_t generation, std::uint64_t request_id, std::uint32_t rules,
|
|
std::chrono::milliseconds timeout);
|
|
// Requires control in the reservation's owning region. First refusal is final;
|
|
// repeats return it. Passing none or an unknown enum value is invalid.
|
|
[[nodiscard]] std::expected<LifeRefusal, LifeReservationFailure>
|
|
reject_primitive_life(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
|
std::uint64_t generation, std::uint64_t request_id, LifeRefusal reason,
|
|
std::chrono::milliseconds timeout);
|
|
} // namespace evo::persistence
|