Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (client) (push) Successful in 12m38s
Foundation / checks (network) (push) Successful in 14m7s
Foundation / checks (tsan) (push) Successful in 8m11s
Foundation / checks (postgres) (push) Failing after 18m3s
Foundation / checks (checks) (push) Successful in 33m8s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
90 lines
3.4 KiB
C++
90 lines
3.4 KiB
C++
#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
|