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:
@@ -2,6 +2,7 @@
|
||||
#include "evo/network/admission.hpp"
|
||||
#include "evo/world/chunks.hpp"
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
@@ -94,6 +95,14 @@ class SessionControl {
|
||||
[[nodiscard]] static std::expected<SessionControl, ControlError> create(ControlConfig config);
|
||||
// Region-wide attempt limit, checked before any signature work. Counts the attempt.
|
||||
[[nodiscard]] std::expected<void, ControlError> attempt(std::uint64_t now_seconds);
|
||||
// Whether open() would accept the grant now, without changing anything (no attempt is
|
||||
// counted). Lets the host take durable control before admitting the session locally.
|
||||
[[nodiscard]] std::expected<void, ControlError> check(const VerifiedSessionGrant& grant,
|
||||
std::uint64_t now_seconds) const;
|
||||
// The id the next successful open() assigns.
|
||||
[[nodiscard]] std::uint64_t next_session() const noexcept {
|
||||
return next_session_;
|
||||
}
|
||||
// A newer grant for an account that already holds a session takes control: the old
|
||||
// session is closed first and reported as superseded. Control is never shared.
|
||||
[[nodiscard]] std::expected<OpenedSession, ControlError> open(const VerifiedSessionGrant& grant,
|
||||
@@ -125,6 +134,9 @@ class SessionControl {
|
||||
std::uint32_t attempts{};
|
||||
};
|
||||
explicit SessionControl(ControlConfig config) : config_{config} {}
|
||||
[[nodiscard]] std::optional<ControlError> claims_error(const VerifiedSessionGrant& grant,
|
||||
std::uint64_t now_seconds) const;
|
||||
[[nodiscard]] bool forgettable(const Account& account, std::uint64_t now_seconds) const;
|
||||
[[nodiscard]] std::expected<Account*, ControlError> admit(const VerifiedSessionGrant& grant,
|
||||
std::uint64_t now_seconds);
|
||||
void accept(Account& account, const GrantClaims& claims);
|
||||
@@ -135,4 +147,34 @@ class SessionControl {
|
||||
std::uint32_t region_attempts_{};
|
||||
std::vector<Account> accounts_;
|
||||
};
|
||||
|
||||
// Durable per-world account control (10.3c, schema v10). The region host implements it
|
||||
// over its database lease; tests use fakes. Calls block for one statement each.
|
||||
enum class ControlLedgerError : std::uint8_t {
|
||||
stale_grant, // The world already accepted this or a newer serial for the account.
|
||||
fenced, // This region's lease or this control generation is no longer current.
|
||||
unavailable // Not decided (database unreachable, timeout, or an unknown outcome).
|
||||
};
|
||||
struct ControlLease {
|
||||
std::uint64_t generation{};
|
||||
// Another region still held control: do not act for the account before this passes.
|
||||
std::chrono::milliseconds wait{};
|
||||
std::chrono::milliseconds granted{}; // From the request send, after the wait.
|
||||
};
|
||||
class ControlLedger {
|
||||
public:
|
||||
ControlLedger() = default;
|
||||
ControlLedger(const ControlLedger&) = delete;
|
||||
ControlLedger& operator=(const ControlLedger&) = delete;
|
||||
virtual ~ControlLedger() = default;
|
||||
[[nodiscard]] virtual std::expected<ControlLease, ControlLedgerError>
|
||||
claim(const AccountId& account, std::uint64_t serial, std::uint64_t session) = 0;
|
||||
[[nodiscard]] virtual std::expected<std::chrono::milliseconds, ControlLedgerError>
|
||||
renew(const AccountId& account, std::uint64_t generation) = 0;
|
||||
virtual void release(const AccountId& account, std::uint64_t generation) = 0;
|
||||
|
||||
protected:
|
||||
ControlLedger(ControlLedger&&) = default;
|
||||
ControlLedger& operator=(ControlLedger&&) = default;
|
||||
};
|
||||
} // namespace evo::network
|
||||
|
||||
Reference in New Issue
Block a user