M10.9d: batch durable action lookups (one per poll, one per commit)
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (client) (push) Successful in 12m41s
Foundation / checks (network) (push) Successful in 13m33s
Foundation / checks (tsan) (push) Successful in 7m54s
Foundation / checks (checks) (push) Successful in 32m56s
Foundation / checks (postgres) (push) Successful in 46m10s
Foundation / postgres-tools (push) Successful in 18s
Foundation / image (push) Successful in 2m33s
Foundation / server-image (push) Successful in 4m24s
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (client) (push) Successful in 12m41s
Foundation / checks (network) (push) Successful in 13m33s
Foundation / checks (tsan) (push) Successful in 7m54s
Foundation / checks (checks) (push) Successful in 32m56s
Foundation / checks (postgres) (push) Successful in 46m10s
Foundation / postgres-tools (push) Successful in 18s
Foundation / image (push) Successful in 2m33s
Foundation / server-image (push) Successful in 4m24s
The fourth dev drill showed a synchronous PostgreSQL round trip per action on the simulation thread: at admission (uniqueness) and again at commit (first-record rule). About 12 lookups landed on each commit tick (commit ticks 58-70 ms, session p99 30-39 ms). - ActionLedger::find_all; persistence::find_region_actions applies the schema v11 find_region_action to many pairs in one statement (no migration). - IntentAdmission::admit/verify: actions only the ledger can refuse wait for one verify per poll; receipts still go out in the same poll. committed() asks once per commit. - Tests: deferred_actions (network_control), find_region_actions and find_all (Postgres). - ADR-0097 fourth run, ADR-0092 amendment, VALIDATION; refresh the dev session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,8 +54,14 @@ struct AccountOutcome {
|
||||
enum class IntentConfigError : std::uint8_t { invalid };
|
||||
// Durable action records (10.4b): the region host implements it over its lease (schema v11);
|
||||
// tests use fakes. `find` answers with the committed outcome, nothing when the action was
|
||||
// never committed, or `unavailable` when it cannot decide.
|
||||
// never committed, or `unavailable` when it cannot decide. `find_all` answers several in
|
||||
// order, all or nothing (M10.9d, ADR-0097: one store round trip instead of one per action);
|
||||
// the default asks `find` for each.
|
||||
enum class ActionLedgerError : std::uint8_t { unavailable };
|
||||
struct ActionKey {
|
||||
AccountId account;
|
||||
std::uint64_t action_id{};
|
||||
};
|
||||
class ActionLedger {
|
||||
public:
|
||||
ActionLedger() = default;
|
||||
@@ -64,6 +70,9 @@ class ActionLedger {
|
||||
virtual ~ActionLedger() = default;
|
||||
[[nodiscard]] virtual std::expected<std::optional<ActionOutcome>, ActionLedgerError>
|
||||
find(const AccountId& account, std::uint64_t action_id) = 0;
|
||||
[[nodiscard]] virtual std::expected<std::vector<std::optional<ActionOutcome>>,
|
||||
ActionLedgerError>
|
||||
find_all(std::span<const ActionKey> keys);
|
||||
|
||||
protected:
|
||||
ActionLedger(ActionLedger&&) = default;
|
||||
@@ -87,6 +96,13 @@ class IntentAdmission {
|
||||
const AdmissionFacts& facts);
|
||||
[[nodiscard]] ActionReceipt action(std::uint64_t session, const SessionAction& m,
|
||||
const AdmissionFacts& facts);
|
||||
// The same admission with the durable uniqueness check deferred (M10.9d): nothing when the
|
||||
// action awaits `verify`, which confirms every waiting action with one ledger request and
|
||||
// returns their receipts by session. Without a ledger, `admit` always answers at once.
|
||||
[[nodiscard]] std::optional<ActionReceipt> admit(std::uint64_t session, const SessionAction& m,
|
||||
const AdmissionFacts& facts);
|
||||
[[nodiscard]] std::vector<std::pair<std::uint64_t, ActionReceipt>>
|
||||
verify(const AdmissionFacts& facts);
|
||||
// An action of the session's account: final, pending or unknown. With a ledger, an action
|
||||
// whose batch outcome was unknown is decided from its durable record once this authority
|
||||
// is ready, and an action no longer in memory is looked up.
|
||||
@@ -101,7 +117,7 @@ class IntentAdmission {
|
||||
// Scheduled actions whose tick is <= `tick`: they ride that tick's batch from now on.
|
||||
[[nodiscard]] std::vector<CarriedAction> carry(std::uint64_t tick);
|
||||
// These carried actions are durable in `commit_sequence`; `tick` is the tick each rode.
|
||||
// With a ledger, each outcome is taken from the action's durable record.
|
||||
// With a ledger, each outcome is taken from the action's durable record (one request).
|
||||
[[nodiscard]] std::vector<AccountOutcome> committed(std::span<const CarriedAction> actions,
|
||||
std::uint64_t commit_sequence);
|
||||
// The host dropped these carried actions. Final: never committed. Otherwise their batch's
|
||||
@@ -127,11 +143,14 @@ class IntentAdmission {
|
||||
std::deque<Pending> pending;
|
||||
std::uint64_t watermark{}, sent_watermark{}, sent_at_tick{};
|
||||
};
|
||||
enum class Stage : std::uint8_t { scheduled, carried };
|
||||
// verifying: admitted in memory, awaiting the durable uniqueness check (`verify`).
|
||||
enum class Stage : std::uint8_t { verifying, scheduled, carried };
|
||||
struct Action {
|
||||
CarriedAction carried;
|
||||
Stage stage{};
|
||||
bool unknown{}; // Carried in a batch whose outcome was unknown when authority was lost.
|
||||
// While verifying: the admitting session, and the epoch and tick of its admission.
|
||||
std::uint64_t session{}, epoch{}, admitted_at{};
|
||||
};
|
||||
explicit IntentAdmission(IntentLimits limits) : limits_{limits} {}
|
||||
// A ledger answer flattened: unavailable (or no ledger), absent, or committed.
|
||||
@@ -141,6 +160,12 @@ class IntentAdmission {
|
||||
ActionOutcome outcome;
|
||||
};
|
||||
[[nodiscard]] Found lookup(const AccountId& account, std::uint64_t action_id) const;
|
||||
// The in-memory checks of an action; `check` is set when only the ledger can still
|
||||
// refuse it.
|
||||
[[nodiscard]] ActionReceipt screen(Session& s, const SessionAction& m,
|
||||
const AdmissionFacts& facts, bool& check);
|
||||
// Applies a durable answer to a receipt that passed `screen`.
|
||||
void decide(const AccountId& account, ActionReceipt& r, const Found& found);
|
||||
Session* find(std::uint64_t session);
|
||||
const Session* find(std::uint64_t session) const;
|
||||
void count_window(Session& s, std::uint64_t server_tick) const;
|
||||
|
||||
@@ -105,6 +105,15 @@ struct CommittedAction {
|
||||
[[nodiscard]] std::expected<std::optional<CommittedAction>, LeaseStoreFailure>
|
||||
find_region_action(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
||||
std::uint64_t action_id, std::chrono::milliseconds timeout);
|
||||
// The same for several (account, action) pairs in one statement, answered in order
|
||||
// (M10.9d, ADR-0097). Empty asks nothing.
|
||||
struct ActionRef {
|
||||
Uuid account{};
|
||||
std::uint64_t action_id{};
|
||||
};
|
||||
[[nodiscard]] std::expected<std::vector<std::optional<CommittedAction>>, LeaseStoreFailure>
|
||||
find_region_actions(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
std::span<const ActionRef> actions, std::chrono::milliseconds timeout);
|
||||
|
||||
struct CommittedDecision {
|
||||
std::uint64_t commit_sequence{};
|
||||
|
||||
@@ -20,6 +20,9 @@ class PostgresActionLedger final : public network::ActionLedger {
|
||||
: db_{&db}, key_{key}, lease_{std::move(lease)}, timeout_{timeout} {}
|
||||
[[nodiscard]] std::expected<std::optional<network::ActionOutcome>, network::ActionLedgerError>
|
||||
find(const network::AccountId& account, std::uint64_t action_id) override;
|
||||
[[nodiscard]] std::expected<std::vector<std::optional<network::ActionOutcome>>,
|
||||
network::ActionLedgerError>
|
||||
find_all(std::span<const network::ActionKey> keys) override; // One statement.
|
||||
|
||||
private:
|
||||
PgSlot* db_;
|
||||
|
||||
Reference in New Issue
Block a user