#pragma once #include "evo/network/session_control.hpp" #include "evo/persistence/account_control_store.hpp" #include #include #include #include // M10.3c durable account control over the region's PostgreSQL lease (ADR-0091, schema v10). // Linux only. Owned by the region host's thread, on the host's own connection. `lease` // returns the host's current region lease, or nothing while it holds none (every call then // reports `fenced`). Store failures that may have executed or are undecided report // `unavailable`; the session layer then keeps or closes sessions by its own deadlines. namespace evo::server { class PostgresControlLedger final : public network::ControlLedger { public: using LeaseSource = std::function()>; PostgresControlLedger(persistence::Postgres& db, persistence::RegionKey key, LeaseSource lease, std::chrono::milliseconds duration = std::chrono::milliseconds{20000}, std::chrono::milliseconds timeout = std::chrono::milliseconds{2000}) : db_{&db}, key_{key}, lease_{std::move(lease)}, duration_{duration}, timeout_{timeout} {} [[nodiscard]] std::expected claim(const network::AccountId& account, std::uint64_t serial, std::uint64_t session) override; [[nodiscard]] std::expected renew(const network::AccountId& account, std::uint64_t generation) override; void release(const network::AccountId& account, std::uint64_t generation) override; private: persistence::Postgres* db_; persistence::RegionKey key_; LeaseSource lease_; std::chrono::milliseconds duration_, timeout_; }; } // namespace evo::server