Select the primitive region host explicitly
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (postgres) (push) Canceled after 0s
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 6m34s
Foundation / checks (client) (push) Canceled after 8m38s
Foundation / checks (checks) (push) Canceled after 8m44s

This commit is contained in:
dingo
2026-10-10 20:37:58 -04:00
parent 9e8de204f0
commit 7da7ef2a6c
4 changed files with 264 additions and 24 deletions
+134 -17
View File
@@ -48,8 +48,13 @@
// --crash-at <point>:<n> (tests only, M7.7) SIGKILLs this process at the n-th
// occurrence of before-upload, before-transaction, after-commit or after-ack (right
// after a step's acknowledgements are written and flushed).
// --profile primitive (M11.2d-5) starts the creation-only profile-3 host. It requires
// an owner-provisioned checkpoint, becomes ready only after recovery, and does not
// accept M9/M10 sessions, synthetic tick input or genesis provisioning.
#include "evo/processes/development_opening.hpp"
#include "evo/server/lifecycle/primitive_lives.hpp"
#include "evo/server/ops_http.hpp"
#include "evo/server/primitive_region_host.hpp"
#include "evo/server/region_host.hpp"
#include "m10_bridge.hpp"
#include "session_bridge.hpp"
@@ -67,6 +72,7 @@
#include <signal.h>
#include <string>
#include <string_view>
#include <thread>
#include <unistd.h>
#include <vector>
@@ -143,7 +149,8 @@ std::optional<Options> parse(int argc, char** argv) {
return std::nullopt;
const std::string_view value = argv[++i];
const auto n = number(value);
if (flag == "--profile" && (value == "lineage" || value == "environmental"))
if (flag == "--profile" &&
(value == "lineage" || value == "environmental" || value == "primitive"))
o.profile = value;
else if (flag == "--world" && n)
o.host.key.world = *n;
@@ -269,6 +276,12 @@ std::optional<Options> parse(int argc, char** argv) {
// M10 sessions (ADR-0091/0092) need every setting and the QUIC build.
if (o.m10.any() && (!server_app::m10_available || !o.m10.complete()))
return std::nullopt;
// Primitive profile serves only the creation-only host in this slice. It
// cannot accept M9/M10 sessions or synthetic biological ticks.
if (o.profile == "primitive" &&
(o.synthetic || !o.crash_point.empty() || o.session.any() || o.m10.any() ||
o.host.flush_interval != 1000ms || o.drain != 10000ms))
return std::nullopt;
if (std::ranges::find(o.host.retained_builds, o.host.build) == o.host.retained_builds.end())
o.host.retained_builds.push_back(o.host.build);
return o;
@@ -591,27 +604,129 @@ template <typename State> int serve(Options& o) {
return finish(3); // Pending/unknown work is left for the next owner to reconcile.
}
}
int serve_primitive(Options& o) {
auto objects = persistence::FilesystemObjectStore::open(
o.objects, o.host.key, server::max_primitive_lives_bytes, nullptr,
o.objects_reserve_mib * 1024 * 1024);
if (!objects) {
std::puts("error objects");
return 2;
}
// The unique_ptr moves into the host, but the store object itself stays put.
const auto* objects_view = objects->get();
const auto pg = o.pg;
auto made = server::PrimitiveRegionHost::create(
{o.host.key, o.host.frame, o.host.lease, o.host.build, o.host.retained_builds},
[pg] { return persistence::Postgres::connect(pg, 2s); }, std::move(*objects));
if (!made) {
std::puts("error config");
return 2;
}
auto& host = **made;
std::unique_ptr<server::OpsServer> ops;
if (!o.ops_listen.empty()) {
auto listening = server::OpsServer::listen(o.ops_listen);
if (!listening) {
std::puts("error ops-listen");
return 2;
}
ops = std::move(*listening);
std::printf("ops listening %u\n", static_cast<unsigned>(ops->port()));
}
server::OpsCounters counters;
counters.objects_reserve_bytes = o.objects_reserve_mib * 1024 * 1024;
bool ready = false;
std::optional<server::HostPhase> phase;
const auto set_ready = [&](bool now) {
if (ready != now) {
ready = now;
std::printf("ready %d\n", ready ? 1 : 0);
}
if (!o.ready_file.empty()) {
std::error_code ignored;
if (ready)
std::ofstream(o.ready_file) << "ready\n";
else
std::filesystem::remove(o.ready_file, ignored);
}
};
const auto finish = [&](int code) {
set_ready(false);
const auto& status = host.status();
std::printf("phase %s epoch=%llu committed=%llu simulated=%llu\n",
server::phase_name(status.phase), static_cast<unsigned long long>(status.epoch),
static_cast<unsigned long long>(status.committed_tick),
static_cast<unsigned long long>(status.simulated_tick));
std::printf("stats commits=%llu store_failures=%llu\n",
static_cast<unsigned long long>(status.commits),
static_cast<unsigned long long>(status.store_failures));
std::printf("exit %d\n", code);
std::fflush(stdout);
return code;
};
for (;;) {
if (stop_requested) {
host.drain();
return finish(0);
}
const auto& status = host.step();
set_ready(status.ready);
if (!phase || *phase != status.phase) {
phase = status.phase;
std::printf("phase %s epoch=%llu committed=%llu simulated=%llu\n",
server::phase_name(status.phase),
static_cast<unsigned long long>(status.epoch),
static_cast<unsigned long long>(status.committed_tick),
static_cast<unsigned long long>(status.simulated_tick));
}
if (ops) {
const auto handler = [&](std::string_view path) -> server::OpsResponse {
const auto& current = host.status();
if (path == "/livez")
return {200, "live\n"};
if (path == "/readyz")
return current.ready ? server::OpsResponse{200, "ready\n"}
: server::OpsResponse{
503, std::string("not ready: ") +
server::phase_name(current.phase) + "\n"};
if (path == "/metrics") {
counters.objects_available_bytes = objects_view->available_bytes().value_or(0);
return {200, server::render_metrics(current, counters),
"text/plain; version=0.0.4; charset=utf-8"};
}
return {404, "not found\n"};
};
ops->serve(handler);
}
std::fflush(stdout);
if (status.phase == server::HostPhase::quarantined)
return finish(4);
std::this_thread::sleep_for(5ms);
}
}
} // namespace
int main(int argc, char** argv) {
auto options = parse(argc, argv);
if (!options) {
std::fputs("usage: evo-server --profile lineage|environmental --world N --region N "
"--frame N --pg-host H --pg-port P --pg-database D --pg-user U "
"--objects DIR --build HEX64 [--retained HEX64]... [--pg-hostaddr A "
"--pg-passfile F --pg-ca F] [--flush-ms N] [--drain-ms N] "
"[--lease-profile default|fast] [--ready-file PATH] "
"[--ops-listen ADDRESS:PORT] [--synthetic-inputs development-v1 "
"[--synthetic-until TICK] [--accelerate N] [--session-listen ADDRESS:PORT "
"--session-cert F --session-key F --session-grant-key F "
"--session-grant-ledger F --session-environment dev]] [--m10-listen "
"ADDRESS:PORT --m10-cert F --m10-key F --m10-issuer F "
"--m10-environment dev|stage|world0 --session-window ACTIVATION:UTC_EXPIRY "
"[--m10-max-grant-lifetime 60..14400] [--m10-area X0,Y0,X1,Y1] "
"[--m10-handoff-key F [--m10-neighbour "
"REGION=X0,Y0,X1,Y1=HOST:PORT=NAME=PUBFILE]...] "
"[--m10-load-governor on|off]]\\n",
stderr);
std::fputs(
"usage: evo-server --profile lineage|environmental|primitive --world N --region N "
"--frame N --pg-host H --pg-port P --pg-database D --pg-user U "
"--objects DIR --build HEX64 [--retained HEX64]... [--pg-hostaddr A "
"--pg-passfile F --pg-ca F] [--flush-ms N] [--drain-ms N] "
"[--lease-profile default|fast] [--ready-file PATH] "
"[--ops-listen ADDRESS:PORT] [--synthetic-inputs development-v1 "
"[--synthetic-until TICK] [--accelerate N] [--session-listen ADDRESS:PORT "
"--session-cert F --session-key F --session-grant-key F "
"--session-grant-ledger F --session-environment dev]] [--m10-listen "
"ADDRESS:PORT --m10-cert F --m10-key F --m10-issuer F "
"--m10-environment dev|stage|world0 --session-window ACTIVATION:UTC_EXPIRY "
"[--m10-max-grant-lifetime 60..14400] [--m10-area X0,Y0,X1,Y1] "
"[--m10-handoff-key F [--m10-neighbour "
"REGION=X0,Y0,X1,Y1=HOST:PORT=NAME=PUBFILE]...] "
"[--m10-load-governor on|off]]\\n",
stderr);
return 2;
}
struct sigaction action{};
@@ -620,6 +735,8 @@ int main(int argc, char** argv) {
sigaction(SIGTERM, &action, nullptr);
sigaction(SIGINT, &action, nullptr);
std::signal(SIGPIPE, SIG_IGN);
if (options->profile == "primitive")
return serve_primitive(*options);
return options->profile == "lineage" ? serve<processes::LineageRegion>(*options)
: serve<processes::EnvironmentalCommunity>(*options);
}