Add M10.3c durable per-world account control (schema v10)
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m50s
Foundation / checks (network) (push) Successful in 9m8s
Foundation / checks (client) (push) Successful in 12m10s
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 7m33s
Foundation / checks (checks) (push) Canceled after 18m49s
Foundation / checks (tsan) (push) Canceled after 6m38s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m50s
Foundation / checks (network) (push) Successful in 9m8s
Foundation / checks (client) (push) Successful in 12m10s
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 7m33s
Foundation / checks (checks) (push) Canceled after 18m49s
Foundation / checks (tsan) (push) Canceled after 6m38s
Migration v10 keeps, per world and account, the highest accepted grant serial and the region session in control with a fencing generation and database-time expiry, reachable only through claim/renew/release functions under the caller's region lease. Serials survive restarts and apply across regions; a cross-region takeover returns a wait so control never overlaps. RegionSessions takes durable control via a ControlLedger before admitting a session, delays Welcome by the wait, renews, and closes sessions whose control is fenced or cannot be confirmed in time. PostgresControlLedger implements the ledger. ADR-0091. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+103
-1
@@ -9,6 +9,7 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
@@ -104,7 +105,7 @@ struct Issuer {
|
||||
|
||||
struct Harness {
|
||||
explicit Harness(const Files& f, std::size_t max_sessions = 4,
|
||||
std::uint32_t region_attempts = 64)
|
||||
std::uint32_t region_attempts = 64, ControlLedger* ledger = nullptr)
|
||||
: files{f} {
|
||||
server::RegionSessionsConfig c;
|
||||
c.transport.certificate_pem_file = f.certificate.string();
|
||||
@@ -119,6 +120,9 @@ struct Harness {
|
||||
c.issuer_keys.push_back({1, *issuer.key.public_key()});
|
||||
c.hello_deadline = std::chrono::milliseconds{500};
|
||||
c.close_flush = std::chrono::milliseconds{300};
|
||||
c.ledger = ledger;
|
||||
c.renew_interval = std::chrono::milliseconds{100};
|
||||
c.safety_margin = std::chrono::milliseconds{50};
|
||||
auto made = RegionSessions::create(std::move(c));
|
||||
CHECK(made.has_value());
|
||||
server = std::move(*made);
|
||||
@@ -336,12 +340,110 @@ void limits(const Files& f) {
|
||||
CHECK(refused_with(h, h.issuer.grant(account(1), 4), Reason::rate_limited));
|
||||
}
|
||||
}
|
||||
// Scripted durable control (10.3c): records calls, answers as configured.
|
||||
struct FakeLedger final : ControlLedger {
|
||||
struct Claim {
|
||||
AccountId account;
|
||||
std::uint64_t serial{}, session{};
|
||||
};
|
||||
std::expected<ControlLease, ControlLedgerError>
|
||||
claim(const AccountId& account, std::uint64_t serial, std::uint64_t session) override {
|
||||
if (claim_error)
|
||||
return std::unexpected(*claim_error);
|
||||
claims.push_back({account, serial, session});
|
||||
return ControlLease{next_generation++, wait, granted};
|
||||
}
|
||||
std::expected<std::chrono::milliseconds, ControlLedgerError>
|
||||
renew(const AccountId& /*account*/, std::uint64_t generation) override {
|
||||
renewed.push_back(generation);
|
||||
if (renew_error)
|
||||
return std::unexpected(*renew_error);
|
||||
return granted;
|
||||
}
|
||||
void release(const AccountId& /*account*/, std::uint64_t generation) override {
|
||||
released.push_back(generation);
|
||||
}
|
||||
std::optional<ControlLedgerError> claim_error, renew_error;
|
||||
std::chrono::milliseconds wait{}, granted{std::chrono::milliseconds{20000}};
|
||||
std::uint64_t next_generation{1};
|
||||
std::vector<Claim> claims;
|
||||
std::vector<std::uint64_t> renewed, released;
|
||||
};
|
||||
|
||||
void durable_control(const Files& f) {
|
||||
FakeLedger ledger;
|
||||
Harness h{f, 4, 64, &ledger};
|
||||
const auto alice = account(1), bob = account(2), carol = account(3);
|
||||
// Durable refusals: nothing is admitted and the grant stays usable locally.
|
||||
ledger.claim_error = ControlLedgerError::stale_grant;
|
||||
CHECK(refused_with(h, h.issuer.grant(alice, 1), Reason::stale_grant));
|
||||
ledger.claim_error = ControlLedgerError::fenced;
|
||||
CHECK(refused_with(h, h.issuer.grant(alice, 1), Reason::shutdown));
|
||||
ledger.claim_error = ControlLedgerError::unavailable;
|
||||
CHECK(refused_with(h, h.issuer.grant(alice, 1), Reason::capacity));
|
||||
CHECK(!h.server->holder(alice) && ledger.claims.empty());
|
||||
ledger.claim_error.reset();
|
||||
// The claim names the account, serial and the session that Welcome then reports.
|
||||
auto a = h.connect(h.issuer.grant(alice, 1));
|
||||
CHECK(h.settled(*a) && a->state() == RegionSessionState::established);
|
||||
CHECK(ledger.claims.size() == 1 && ledger.claims[0].account == alice &&
|
||||
ledger.claims[0].serial == 1 && ledger.claims[0].session == must(a->welcome()).session);
|
||||
CHECK(h.until([&] { return ledger.renewed.size() >= 2; })); // Renewed every 100 ms.
|
||||
// Refresh records the newer serial for the same session.
|
||||
CHECK(a->refresh(h.issuer.grant(alice, 2)));
|
||||
std::optional<SessionRefreshResult> r;
|
||||
CHECK(h.until([&] { return (r = a->take_refresh_result()).has_value(); }));
|
||||
CHECK(must(r).status == 0 && ledger.claims.size() == 2 && ledger.claims[1].serial == 2 &&
|
||||
ledger.claims[1].session == must(a->welcome()).session);
|
||||
// Another region took control: the renewal is fenced and the session is superseded,
|
||||
// without releasing control it no longer holds.
|
||||
ledger.renew_error = ControlLedgerError::fenced;
|
||||
CHECK(h.until([&] { return a->state() == RegionSessionState::closed; }));
|
||||
CHECK(a->close_reason() == Reason::superseded && ledger.released.empty());
|
||||
CHECK(!h.server->holder(alice));
|
||||
// Control held by another region: Welcome waits it out.
|
||||
ledger.renew_error.reset();
|
||||
ledger.wait = std::chrono::milliseconds{400};
|
||||
const auto sent = Clock::now();
|
||||
auto b = h.connect(h.issuer.grant(bob, 1));
|
||||
CHECK(h.until([&] { return h.server->holder(bob).has_value(); }));
|
||||
CHECK(b->state() != RegionSessionState::established);
|
||||
CHECK(h.settled(*b) && b->state() == RegionSessionState::established);
|
||||
CHECK(Clock::now() - sent >= std::chrono::milliseconds{400});
|
||||
// Undecided renewals: the session closes before its control could lapse, and releases.
|
||||
ledger.wait = {};
|
||||
ledger.granted = std::chrono::milliseconds{300};
|
||||
auto c = h.connect(h.issuer.grant(carol, 1));
|
||||
CHECK(h.settled(*c) && c->state() == RegionSessionState::established);
|
||||
const auto carol_generation = ledger.next_generation - 1;
|
||||
ledger.renew_error = ControlLedgerError::unavailable;
|
||||
CHECK(h.until([&] { return c->state() == RegionSessionState::closed; }));
|
||||
CHECK(c->close_reason() == Reason::shutdown);
|
||||
CHECK(std::ranges::find(ledger.released, carol_generation) != ledger.released.end());
|
||||
// A refresh that finds a newer grant elsewhere closes the session as superseded.
|
||||
ledger.renew_error.reset();
|
||||
ledger.granted = std::chrono::milliseconds{20000};
|
||||
ledger.claim_error = ControlLedgerError::stale_grant;
|
||||
CHECK(b->refresh(h.issuer.grant(bob, 2)));
|
||||
CHECK(h.until([&] { return b->state() == RegionSessionState::closed; }));
|
||||
CHECK(b->close_reason() == Reason::superseded && !b->take_refresh_result());
|
||||
// Client close releases durable control.
|
||||
ledger.claim_error.reset();
|
||||
auto d = h.connect(h.issuer.grant(alice, 3));
|
||||
CHECK(h.settled(*d) && d->state() == RegionSessionState::established);
|
||||
const auto alice_generation = ledger.next_generation - 1;
|
||||
d->close();
|
||||
CHECK(h.until([&] {
|
||||
return std::ranges::find(ledger.released, alice_generation) != ledger.released.end();
|
||||
}));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
const auto files = credentials();
|
||||
login_rules(files);
|
||||
limits(files);
|
||||
durable_control(files);
|
||||
std::filesystem::remove_all(files.dir);
|
||||
std::puts("quic session tests passed");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user