Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 2m1s
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 (postgres) (push) Canceled after 22s
Foundation / checks (network) (push) Canceled after 1m58s
Foundation / checks (client) (push) Canceled after 2m39s
39 lines
2.0 KiB
C++
39 lines
2.0 KiB
C++
#pragma once
|
|
#include "evo/network/session_control.hpp"
|
|
#include "evo/persistence/account_control_store.hpp"
|
|
#include "evo/persistence/life_reservation_store.hpp"
|
|
#include "evo/server/pg_slot.hpp"
|
|
#include <chrono>
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <utility>
|
|
|
|
// 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 its own connection slot. `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<std::optional<persistence::LeaseGrant>()>;
|
|
PostgresControlLedger(PgSlot& 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<network::ControlLease, network::ControlLedgerError>
|
|
claim(const network::AccountId& account, std::uint64_t serial, std::uint64_t session) override;
|
|
[[nodiscard]] std::expected<std::optional<std::uint64_t>, network::ControlLedgerError>
|
|
primitive_life_owner(const network::AccountId& account) override;
|
|
[[nodiscard]] std::expected<std::chrono::milliseconds, network::ControlLedgerError>
|
|
renew(const network::AccountId& account, std::uint64_t generation) override;
|
|
void release(const network::AccountId& account, std::uint64_t generation) override;
|
|
|
|
private:
|
|
PgSlot* db_;
|
|
persistence::RegionKey key_;
|
|
LeaseSource lease_;
|
|
std::chrono::milliseconds duration_, timeout_;
|
|
};
|
|
} // namespace evo::server
|