Add primitive profile region host
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (checks) (push) Failing after 3m43s
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 (postgres) (push) Canceled after 3m2s
Foundation / checks (network) (push) Canceled after 4m39s
Foundation / checks (client) (push) Canceled after 6m48s

This commit is contained in:
dingo
2026-10-10 14:29:22 -04:00
parent ea07d7c1f5
commit 4f49c54232
8 changed files with 679 additions and 13 deletions
@@ -0,0 +1,88 @@
#pragma once
#include "evo/persistence/checkpoint_store.hpp"
#include "evo/server/ops.hpp"
#include <chrono>
#include <expected>
#include <functional>
#include <memory>
#include <optional>
#include <vector>
// Authoritative creation-only host for checkpoint profile 3. This host does not
// advance biology; each accepted birth is its own fenced, replayable checkpoint.
namespace evo::server {
using PrimitiveConnect =
std::function<std::expected<std::unique_ptr<persistence::Postgres>, persistence::PgFailure>()>;
struct PrimitiveHostConfig {
persistence::RegionKey key{};
std::uint64_t frame{};
persistence::LeasePolicy lease{};
persistence::Sha256Digest build{};
std::vector<persistence::Sha256Digest> retained_builds;
};
enum class PrimitiveHostError : std::uint8_t { configuration };
enum class PrimitiveHostReplyKind : std::uint8_t {
born,
refused,
pending,
unknown,
routed,
unavailable
};
struct PrimitiveHostReply {
PrimitiveHostReplyKind kind{};
persistence::LifeReservation reservation{};
std::optional<persistence::PrimitiveLifeBinding> published;
friend bool operator==(const PrimitiveHostReply&, const PrimitiveHostReply&) = default;
};
class PrimitiveRegionHost {
public:
[[nodiscard]] static std::expected<std::unique_ptr<PrimitiveRegionHost>,
PrimitiveHostError>
create(PrimitiveHostConfig config, PrimitiveConnect connect,
std::unique_ptr<persistence::FilesystemObjectStore> objects);
PrimitiveRegionHost(const PrimitiveRegionHost&) = delete;
PrimitiveRegionHost& operator=(const PrimitiveRegionHost&) = delete;
~PrimitiveRegionHost();
// Performs lease upkeep and full profile-3 recovery. It is the only path to
// ready; no missing/empty checkpoint is substituted.
const HostStatus& step();
// Stops requests and best-effort releases the current lease.
void drain();
// The caller supplies the authenticated account-control generation. The
// operation is durable before `born` or a final refusal is returned.
[[nodiscard]] PrimitiveHostReply new_life(const persistence::Uuid& account,
std::uint64_t generation,
std::uint64_t request,
std::uint32_t rules);
[[nodiscard]] std::optional<persistence::LeaseGrant> authority() const;
[[nodiscard]] const HostStatus& status() const noexcept { return status_; }
[[nodiscard]] const PrimitiveLives* state() const noexcept { return state_.get(); }
private:
struct Pending;
PrimitiveRegionHost(PrimitiveHostConfig config, PrimitiveConnect connect,
std::unique_ptr<persistence::FilesystemObjectStore> objects);
bool database();
void acquire();
void upkeep();
void refresh();
[[nodiscard]] PrimitiveHostReply query(const persistence::Uuid& account,
std::uint64_t generation,
std::uint64_t request);
PrimitiveHostConfig config_;
PrimitiveConnect connect_;
std::unique_ptr<persistence::FilesystemObjectStore> objects_;
std::unique_ptr<persistence::Postgres> db_;
persistence::LeaseAuthority authority_;
std::unique_ptr<PrimitiveLives> state_;
std::optional<persistence::CommittedCheckpoint> committed_;
std::unique_ptr<Pending> pending_;
HostStatus status_{};
};
} // namespace evo::server