Add M8.4 region host deployment, provisioning hook and drill
Deploy evo-region per environment (ADR-0071): one replica with the Recreate strategy (a rolling update would deadlock on the lease), /readyz readiness, /livez liveness, no CPU limit and a drain inside the grace period, with the image digest doubling as the build identity. A new idempotent evo-world-clone provision subcommand creates genesis from development_opening (byte-identical to the qualification fixture) as a Sync hook after the migration. Dev and stage paths include their region; a dev AppProject allows Deployment and Service; region-drill.sh times rollout and forced-deletion recovery; the policy check enforces the host's invariants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
// [--max-commits N]
|
||||
// evo-world-clone check-store --world W --region R --pg-* ... --objects DIR
|
||||
// [--reserve-mib N]
|
||||
// evo-world-clone provision --world W --region R --opening development-v1 --pg-* ...
|
||||
// --objects DIR --build HEX [--retain-build]
|
||||
//
|
||||
// --*pg-* is host, hostaddr, port, database, user, passfile, ca, or service (a libpq
|
||||
// service file whose [evolution] section supplies everything but the password file). The source
|
||||
@@ -31,10 +33,18 @@
|
||||
// Output: objects available_mib=A reserve_mib=R / probe created|verified digest=HEX
|
||||
// database version=V user=U ssl=S / database tables=denied functions=reachable
|
||||
//
|
||||
// provision (M8.4) creates a region's genesis with the owner (migrator) login, once:
|
||||
// an already provisioned region is reported and never touched. --retain-build first
|
||||
// records the build identity (the server image digest) in retained_builds. The only
|
||||
// opening is development-v1 (evo/processes/development_opening.hpp), for dev and
|
||||
// stage; World0's opening is a separate, reviewed decision.
|
||||
// Output: provisioned|already-provisioned world=W region=R sequence=S tick=T
|
||||
//
|
||||
// Exit: 0 done, 2 usage, 3 source/history/database failure, 4 target/objects refused,
|
||||
// 5 target unknown.
|
||||
#include "evo/persistence/region_clone.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/processes/development_opening.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
@@ -65,6 +75,9 @@ struct Options {
|
||||
std::vector<persistence::Sha256Digest> retained;
|
||||
std::optional<persistence::Uuid> commit;
|
||||
std::uint64_t audit_max{}, max_commits{1u << 20U}, reserve_mib{1024};
|
||||
std::string opening;
|
||||
std::optional<persistence::Sha256Digest> build;
|
||||
bool retain_build{};
|
||||
bool crash{};
|
||||
};
|
||||
|
||||
@@ -136,7 +149,8 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
return std::nullopt;
|
||||
Options o;
|
||||
o.command = argv[1];
|
||||
if (o.command != "clone" && o.command != "audit" && o.command != "check-store")
|
||||
if (o.command != "clone" && o.command != "audit" && o.command != "check-store" &&
|
||||
o.command != "provision")
|
||||
return std::nullopt;
|
||||
const bool clone = o.command == "clone";
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
@@ -178,12 +192,20 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
o.max_commits = *n;
|
||||
else if (o.command == "check-store" && flag == "--reserve-mib" && n && *n <= 1048576)
|
||||
o.reserve_mib = *n;
|
||||
else if (o.command == "provision" && flag == "--opening" && value == "development-v1")
|
||||
o.opening = value;
|
||||
else if (o.command == "provision" && flag == "--build" && hex<32>(value))
|
||||
o.build = hex<32>(value);
|
||||
else if (o.command == "provision" && flag == "--retain-build" && value == "true")
|
||||
o.retain_build = true;
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
if (clone && o.target.key.region == 0)
|
||||
o.target.key.region = o.source.key.region;
|
||||
const bool needs_builds = o.command != "check-store";
|
||||
const bool needs_builds = o.command != "check-store" && o.command != "provision";
|
||||
if (o.command == "provision" && (o.opening.empty() || !o.build))
|
||||
return std::nullopt;
|
||||
if (!complete(o.source) || (needs_builds && o.retained.empty()) ||
|
||||
(clone && !complete(o.target)))
|
||||
return std::nullopt;
|
||||
@@ -274,6 +296,60 @@ std::vector<std::uint8_t> probe_bytes() {
|
||||
return out;
|
||||
}
|
||||
|
||||
int provision(const Options& o) {
|
||||
auto store = open_objects(o.source);
|
||||
if (!store) {
|
||||
std::puts("objects refused");
|
||||
return 4;
|
||||
}
|
||||
auto db = connect(o.source);
|
||||
if (!db) {
|
||||
std::puts("database refused");
|
||||
return 3;
|
||||
}
|
||||
if (!o.build)
|
||||
return 2; // Required by parse(); checked again for the reader.
|
||||
const auto& build = *o.build;
|
||||
if (o.retain_build) {
|
||||
const std::array<std::string, 1> p{"\\x" + text(build)};
|
||||
if (!db->query("INSERT INTO evolution.retained_builds(build_identity) VALUES ($1::bytea) "
|
||||
"ON CONFLICT DO NOTHING",
|
||||
p, timeout)) {
|
||||
std::puts("retain-build refused");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
const auto report = [&](const char* what, const persistence::RegionHead& head) {
|
||||
std::printf("%s world=%llu region=%llu sequence=%llu tick=%llu\n", what,
|
||||
static_cast<unsigned long long>(o.source.key.world),
|
||||
static_cast<unsigned long long>(o.source.key.region),
|
||||
static_cast<unsigned long long>(head.sequence),
|
||||
static_cast<unsigned long long>(head.end_tick));
|
||||
return 0;
|
||||
};
|
||||
// Never re-provision: an existing region, whatever its state, is left alone.
|
||||
auto existing = persistence::load_region_head(*db, o.source.key, timeout);
|
||||
if (existing)
|
||||
return report("already-provisioned", *existing);
|
||||
if (existing.error().kind != persistence::LeaseStoreError::not_provisioned) {
|
||||
std::puts("database refused");
|
||||
return 3;
|
||||
}
|
||||
auto opening = processes::development_opening(o.source.key.world);
|
||||
persistence::Uuid commit{};
|
||||
if (!opening ||
|
||||
::getrandom(commit.data(), commit.size(), 0) != static_cast<ssize_t>(commit.size()))
|
||||
return 4;
|
||||
auto made = persistence::provision_lineage_region(
|
||||
*db, *store, o.source.key, processes::development_opening_frame, **opening, commit, build,
|
||||
restore_budget, timeout);
|
||||
if (!made) {
|
||||
std::printf("provision refused %u\n", static_cast<unsigned>(made.error().kind));
|
||||
return 4;
|
||||
}
|
||||
return report("provisioned", made->head);
|
||||
}
|
||||
|
||||
int check_store(const Options& o) {
|
||||
auto store = persistence::FilesystemObjectStore::open(o.source.objects, o.source.key,
|
||||
persistence::max_lineage_payload_bytes,
|
||||
@@ -441,5 +517,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
if (options->command == "check-store")
|
||||
return check_store(*options);
|
||||
if (options->command == "provision")
|
||||
return provision(*options);
|
||||
return options->command == "clone" ? clone(*options) : audit(*options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user