Add M10.4b durable action records (schema v11)
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m47s
Foundation / checks (network) (push) Successful in 9m30s
Foundation / checks (client) (push) Successful in 12m19s
Foundation / checks (tsan) (push) Successful in 7m43s
Foundation / checks (checks) (push) Successful in 31m29s
Foundation / checks (postgres) (push) Successful in 36m39s
Foundation / postgres-tools (push) Successful in 19s
Foundation / image (push) Successful in 2m15s
Foundation / server-image (push) Successful in 20m37s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m47s
Foundation / checks (network) (push) Successful in 9m30s
Foundation / checks (client) (push) Successful in 12m19s
Foundation / checks (tsan) (push) Successful in 7m43s
Foundation / checks (checks) (push) Successful in 31m29s
Foundation / checks (postgres) (push) Successful in 36m39s
Foundation / postgres-tools (push) Successful in 19s
Foundation / image (push) Successful in 2m15s
Foundation / server-image (push) Successful in 20m37s
Each batch's actions are recorded in the same statement as its checkpoint: one region_actions row per (world, account, action id) and the block in an append-only table, compared on exact retries and resolution. The region host attaches actions to the ticks they ride and reports acknowledgements and drops, keeping unknown-outcome batches unresolved. Outcomes come from the durable record via ActionLedger, so crashes before or after a commit, unknown publications and cross-region moves all resolve to one answer; a repeated id keeps its first record instead of stalling a region. ADR-0092. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -145,28 +145,60 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const SessionAction
|
||||
r.status = AdmitStatus::outside_window;
|
||||
else if (unresolved_of(*s) >= limits_.max_unresolved)
|
||||
r.status = AdmitStatus::too_many_unresolved;
|
||||
else if (ledger_) {
|
||||
// Committed earlier (another epoch, process or region): never admitted again.
|
||||
const auto found = lookup(account, m.action_id);
|
||||
if (found.state == Record::unavailable) {
|
||||
r.status = AdmitStatus::not_ready; // Uniqueness cannot be confirmed now.
|
||||
} else if (found.state == Record::committed) {
|
||||
r.status = AdmitStatus::duplicate;
|
||||
r.tick = found.outcome.tick;
|
||||
remember(account, found.outcome);
|
||||
}
|
||||
}
|
||||
if (r.status == AdmitStatus::admitted)
|
||||
actions_.push_back({{account, m.action_id, m.tick, ActionKind::probe}, Stage::scheduled});
|
||||
return r;
|
||||
}
|
||||
|
||||
ActionOutcome IntentAdmission::query(std::uint64_t session, const ActionQuery& m) const {
|
||||
ActionOutcome IntentAdmission::query(std::uint64_t session, const ActionQuery& m,
|
||||
const AdmissionFacts& facts) {
|
||||
ActionOutcome o{m.action_id, ActionResult::unknown, 0, 0};
|
||||
const auto* s = find(session);
|
||||
if (!s)
|
||||
return o;
|
||||
const auto account = s->account;
|
||||
const auto pending = std::ranges::find_if(actions_, [&](const Action& a) {
|
||||
return a.carried.account == s->account && a.carried.action_id == m.action_id;
|
||||
return a.carried.account == account && a.carried.action_id == m.action_id;
|
||||
});
|
||||
if (pending != actions_.end()) {
|
||||
o.result = ActionResult::pending;
|
||||
o.tick = pending->carried.tick;
|
||||
// A batch outcome left unknown by a lost authority is decided by the durable record
|
||||
// once this authority is ready: every earlier epoch's commits are then final.
|
||||
if (pending->unknown && ledger_ && facts.ready)
|
||||
if (const auto found = lookup(account, m.action_id);
|
||||
found.state != Record::unavailable) {
|
||||
o = found.state == Record::committed
|
||||
? found.outcome
|
||||
: ActionOutcome{m.action_id, ActionResult::not_committed, 0, 0};
|
||||
actions_.erase(pending);
|
||||
remember(account, o);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
const auto final = std::ranges::find_if(finals_, [&](const AccountOutcome& f) {
|
||||
return f.account == s->account && f.outcome.action_id == m.action_id;
|
||||
return f.account == account && f.outcome.action_id == m.action_id;
|
||||
});
|
||||
return final != finals_.end() ? final->outcome : o;
|
||||
if (final != finals_.end())
|
||||
return final->outcome;
|
||||
// No longer in memory: a committed action is still on record.
|
||||
if (ledger_ && facts.ready)
|
||||
if (const auto found = lookup(account, m.action_id); found.state == Record::committed) {
|
||||
remember(account, found.outcome);
|
||||
return found.outcome;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::uint64_t, SimulatedThrough>>
|
||||
@@ -206,23 +238,51 @@ void IntentAdmission::remember(const AccountId& account, const ActionOutcome& ou
|
||||
finals_.pop_front();
|
||||
}
|
||||
|
||||
std::vector<AccountOutcome> IntentAdmission::committed(std::uint64_t end_tick,
|
||||
std::vector<AccountOutcome> IntentAdmission::committed(std::span<const CarriedAction> actions,
|
||||
std::uint64_t commit_sequence) {
|
||||
std::vector<AccountOutcome> out;
|
||||
std::erase_if(actions_, [&](const Action& a) {
|
||||
if (a.stage != Stage::carried || a.carried.tick > end_tick)
|
||||
return false;
|
||||
const ActionOutcome o{a.carried.action_id, ActionResult::committed_no_effect,
|
||||
a.carried.tick, commit_sequence};
|
||||
out.push_back({a.carried.account, o});
|
||||
remember(a.carried.account, o);
|
||||
return true;
|
||||
});
|
||||
for (const auto& c : actions) {
|
||||
ActionOutcome o{c.action_id, ActionResult::committed_no_effect, c.tick, commit_sequence};
|
||||
// The durable record is the authority: an id carried by two batches (an account that
|
||||
// moved regions with the action pending) keeps the record of the first commit.
|
||||
if (ledger_)
|
||||
if (const auto found = lookup(c.account, c.action_id); found.state == Record::committed)
|
||||
o = found.outcome;
|
||||
std::erase_if(actions_, [&](const Action& a) {
|
||||
return a.carried.account == c.account && a.carried.action_id == c.action_id;
|
||||
});
|
||||
out.push_back({c.account, o});
|
||||
remember(c.account, o);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<AccountOutcome> IntentAdmission::dropped(std::span<const CarriedAction> actions,
|
||||
bool final) {
|
||||
std::vector<AccountOutcome> out;
|
||||
for (const auto& c : actions) {
|
||||
const auto it = std::ranges::find_if(actions_, [&](const Action& a) {
|
||||
return a.carried.account == c.account && a.carried.action_id == c.action_id;
|
||||
});
|
||||
if (!final) {
|
||||
if (it != actions_.end())
|
||||
it->unknown = true;
|
||||
continue;
|
||||
}
|
||||
if (it != actions_.end())
|
||||
actions_.erase(it);
|
||||
const ActionOutcome o{c.action_id, ActionResult::not_committed, 0, 0};
|
||||
out.push_back({c.account, o});
|
||||
remember(c.account, o);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<AccountOutcome> IntentAdmission::abandon() {
|
||||
std::vector<AccountOutcome> out;
|
||||
for (auto& a : actions_)
|
||||
if (a.stage == Stage::carried)
|
||||
a.unknown = true; // Decided by a commit report, a drop report or its record.
|
||||
std::erase_if(actions_, [&](const Action& a) {
|
||||
if (a.stage != Stage::scheduled)
|
||||
return false;
|
||||
@@ -236,6 +296,21 @@ std::vector<AccountOutcome> IntentAdmission::abandon() {
|
||||
return out;
|
||||
}
|
||||
|
||||
IntentAdmission::Found IntentAdmission::lookup(const AccountId& account,
|
||||
std::uint64_t action_id) const {
|
||||
Found f;
|
||||
if (!ledger_)
|
||||
return f;
|
||||
const auto answer = ledger_->find(account, action_id);
|
||||
if (!answer.has_value())
|
||||
return f;
|
||||
const auto& record = answer.value();
|
||||
f.state = record.has_value() ? Record::committed : Record::absent;
|
||||
if (record.has_value())
|
||||
f.outcome = record.value();
|
||||
return f;
|
||||
}
|
||||
|
||||
std::optional<std::uint64_t> IntentAdmission::session_of(const AccountId& account) const {
|
||||
const auto it =
|
||||
std::ranges::find_if(sessions_, [&](const Session& s) { return s.account == account; });
|
||||
|
||||
@@ -49,7 +49,7 @@ publish_batch(Postgres& db, const FilesystemObjectStore& objects, const LeaseGra
|
||||
const CommittedCheckpoint& predecessor,
|
||||
const RegionBatch<typename Codec::State>& batch, Uuid commit,
|
||||
const Sha256Digest& build, std::size_t budget, milliseconds timeout,
|
||||
const PublishHooks& hooks) {
|
||||
const PublishHooks& hooks, std::span<const ActionRecord> actions) {
|
||||
const auto previous = decode_manifest(predecessor.manifest);
|
||||
if (!previous || previous->profile != Codec::profile || !batch.sealed() ||
|
||||
batch.steps().empty() || batch.begin_tick() != previous->end_tick)
|
||||
@@ -81,7 +81,8 @@ publish_batch(Postgres& db, const FilesystemObjectStore& objects, const LeaseGra
|
||||
batch.begin_tick(),
|
||||
batch.end_tick()};
|
||||
auto trace = encode_trace(header, batch.steps());
|
||||
if (!decision_bytes || !trace)
|
||||
auto action_bytes = encode_actions(actions, batch.begin_tick(), batch.end_tick());
|
||||
if (!decision_bytes || !trace || !action_bytes)
|
||||
return std::unexpected{fail(PublicationError::candidate)};
|
||||
const auto payload_digest = sha256(*payload);
|
||||
const auto trace_digest = sha256(*trace);
|
||||
@@ -104,10 +105,10 @@ publish_batch(Postgres& db, const FilesystemObjectStore& objects, const LeaseGra
|
||||
if (auto stored = put_verified(objects, *trace, {*trace_digest, trace->size()}); !stored)
|
||||
return std::unexpected{stored.error()};
|
||||
|
||||
PreparedCommit prepared{previous->key, commit, *bytes, *decision_bytes};
|
||||
PreparedCommit prepared{previous->key, commit, *bytes, *decision_bytes, *action_bytes};
|
||||
if (hooks.before_transaction)
|
||||
hooks.before_transaction();
|
||||
auto published = publish_region_checkpoint(db, *bytes, *decision_bytes, timeout);
|
||||
auto published = retry_prepared(db, prepared, timeout);
|
||||
auto committed = confirm(published, std::move(*bytes), *manifest, std::move(prepared));
|
||||
if (!committed)
|
||||
return std::unexpected{committed.error()};
|
||||
@@ -128,9 +129,10 @@ publish_environmental_batch(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
|
||||
const RegionBatch<processes::EnvironmentalCommunity>& batch,
|
||||
Uuid commit, const Sha256Digest& build, std::size_t restore_budget,
|
||||
milliseconds timeout, const PublishHooks& hooks) {
|
||||
milliseconds timeout, const PublishHooks& hooks,
|
||||
std::span<const ActionRecord> actions) {
|
||||
return publish_batch<EnvironmentalCodec>(db, objects, lease, predecessor, batch, commit, build,
|
||||
restore_budget, timeout, hooks);
|
||||
restore_budget, timeout, hooks, actions);
|
||||
}
|
||||
std::expected<RecoveredCheckpoint, RecoveryFailure>
|
||||
recover_environmental_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
@@ -152,9 +154,9 @@ publish_lineage_batch(Postgres& db, const FilesystemObjectStore& objects, const
|
||||
const CommittedCheckpoint& predecessor,
|
||||
const RegionBatch<processes::LineageRegion>& batch, Uuid commit,
|
||||
const Sha256Digest& build, std::size_t restore_budget, milliseconds timeout,
|
||||
const PublishHooks& hooks) {
|
||||
const PublishHooks& hooks, std::span<const ActionRecord> actions) {
|
||||
return publish_batch<LineageCodec>(db, objects, lease, predecessor, batch, commit, build,
|
||||
restore_budget, timeout, hooks);
|
||||
restore_budget, timeout, hooks, actions);
|
||||
}
|
||||
std::expected<RecoveredLineageCheckpoint, RecoveryFailure>
|
||||
recover_lineage_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
@@ -165,11 +167,18 @@ recover_lineage_checkpoint(Postgres& db, const FilesystemObjectStore& objects, R
|
||||
|
||||
std::expected<ResolvedCommit, LeaseStoreFailure>
|
||||
resolve_prepared(Postgres& db, const PreparedCommit& prepared, milliseconds timeout) {
|
||||
if (!prepared.actions.empty())
|
||||
return resolve_region_commit(db, prepared.key, prepared.commit, prepared.manifest,
|
||||
prepared.decisions, prepared.actions, timeout);
|
||||
return resolve_region_commit(db, prepared.key, prepared.commit, prepared.manifest,
|
||||
prepared.decisions, timeout);
|
||||
}
|
||||
std::expected<RegionHead, LeaseStoreFailure>
|
||||
retry_prepared(Postgres& db, const PreparedCommit& prepared, milliseconds timeout) {
|
||||
// Without actions the schema v5 publication is used, exactly as before v11.
|
||||
if (!prepared.actions.empty())
|
||||
return publish_region_checkpoint(db, prepared.manifest, prepared.decisions,
|
||||
prepared.actions, timeout);
|
||||
return publish_region_checkpoint(db, prepared.manifest, prepared.decisions, timeout);
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "evo/persistence/region_batch.hpp"
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
namespace evo::persistence {
|
||||
namespace {
|
||||
@@ -223,4 +225,39 @@ std::vector<BatchDecision> derive_decisions(std::span<const TraceStep> steps,
|
||||
}
|
||||
return out;
|
||||
}
|
||||
std::expected<std::vector<std::uint8_t>, BatchError>
|
||||
encode_actions(std::span<const ActionRecord> actions, std::uint64_t begin_tick,
|
||||
std::uint64_t end_tick) {
|
||||
if (actions.size() > max_batch_actions)
|
||||
return std::unexpected{BatchError::format};
|
||||
std::vector<ActionRecord> sorted(actions.begin(), actions.end());
|
||||
const auto key = [](const ActionRecord& a) {
|
||||
return std::tuple{a.tick, a.account, a.action_id};
|
||||
};
|
||||
std::ranges::sort(sorted, {}, key);
|
||||
// An action id appears once, whatever its tick.
|
||||
std::vector<std::pair<Uuid, std::uint64_t>> ids;
|
||||
ids.reserve(sorted.size());
|
||||
for (const auto& a : sorted)
|
||||
ids.emplace_back(a.account, a.action_id);
|
||||
std::ranges::sort(ids);
|
||||
if (std::ranges::adjacent_find(ids) != ids.end())
|
||||
return std::unexpected{BatchError::format};
|
||||
std::vector<std::uint8_t> out;
|
||||
out.reserve(sorted.size() * action_record_bytes);
|
||||
for (std::size_t i = 0; i < sorted.size(); ++i) {
|
||||
const auto& a = sorted[i];
|
||||
if (a.account == Uuid{} || a.action_id == 0 || a.kind != 1 || a.tick <= begin_tick ||
|
||||
a.tick > end_tick || (i > 0 && key(sorted[i - 1]) == key(a)))
|
||||
return std::unexpected{BatchError::format};
|
||||
out.insert(out.end(), a.account.begin(), a.account.end());
|
||||
for (unsigned b = 0; b < 8; ++b)
|
||||
out.push_back(static_cast<std::uint8_t>(a.action_id >> (8U * b)));
|
||||
for (unsigned b = 0; b < 8; ++b)
|
||||
out.push_back(static_cast<std::uint8_t>(a.tick >> (8U * b)));
|
||||
out.push_back(static_cast<std::uint8_t>(a.kind));
|
||||
out.push_back(static_cast<std::uint8_t>(a.kind >> 8U));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
@@ -281,6 +281,77 @@ resolve_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
return ResolvedCommit{Resolution::committed, *head};
|
||||
}
|
||||
|
||||
std::expected<RegionHead, LeaseStoreFailure>
|
||||
publish_region_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions, milliseconds timeout) {
|
||||
const std::array<std::string, 3> p{bytea(manifest), bytea(decisions), bytea(actions)};
|
||||
auto rows = db.query(
|
||||
"SELECT * FROM evolution.publish_region_checkpoint($1::bytea, $2::bytea, $3::bytea)", p,
|
||||
timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{classify(rows.error())};
|
||||
auto head = parse_head(*rows);
|
||||
if (!head)
|
||||
return std::unexpected{malformed(true)};
|
||||
return *head;
|
||||
}
|
||||
|
||||
std::expected<ResolvedCommit, LeaseStoreFailure>
|
||||
resolve_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions, milliseconds timeout) {
|
||||
const std::array<std::string, 6> p{std::to_string(key.world), std::to_string(key.region),
|
||||
uuid_text(commit), bytea(manifest),
|
||||
bytea(decisions), bytea(actions)};
|
||||
auto rows = db.query("SELECT * FROM evolution.resolve_region_commit($1::evolution.u64, "
|
||||
"$2::evolution.u64, $3::uuid, $4::bytea, $5::bytea, $6::bytea)",
|
||||
p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{classify(rows.error())};
|
||||
if (rows->size() != 1 || (*rows)[0].size() != 6)
|
||||
return std::unexpected{malformed(false)};
|
||||
const auto& status_text = (*rows)[0][0];
|
||||
if (!status_text)
|
||||
return std::unexpected{malformed(false)};
|
||||
const auto status = *status_text;
|
||||
if (status == "absent")
|
||||
return ResolvedCommit{Resolution::absent, {}};
|
||||
if (status == "conflict")
|
||||
return ResolvedCommit{Resolution::conflict, {}};
|
||||
const PgRows receipt{
|
||||
std::vector<std::optional<std::string>>((*rows)[0].begin() + 1, (*rows)[0].end())};
|
||||
auto head = status == "committed" ? parse_head(receipt) : std::nullopt;
|
||||
if (!head)
|
||||
return std::unexpected{malformed(false)};
|
||||
return ResolvedCommit{Resolution::committed, *head};
|
||||
}
|
||||
|
||||
std::expected<std::optional<CommittedAction>, LeaseStoreFailure>
|
||||
find_region_action(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
||||
std::uint64_t action_id, milliseconds timeout) {
|
||||
const std::array<std::string, 6> p{std::to_string(key.world), std::to_string(key.region),
|
||||
uuid_text(lease.holder), std::to_string(lease.epoch),
|
||||
uuid_text(account), std::to_string(action_id)};
|
||||
auto rows = db.query("SELECT * FROM evolution.find_region_action($1::evolution.u64, "
|
||||
"$2::evolution.u64, $3::uuid, $4::evolution.u64, $5::uuid, "
|
||||
"$6::evolution.u64)",
|
||||
p, timeout);
|
||||
if (!rows)
|
||||
return std::unexpected{classify(rows.error())};
|
||||
if (rows->empty())
|
||||
return std::optional<CommittedAction>{};
|
||||
if (rows->size() != 1 || (*rows)[0].size() != 3)
|
||||
return std::unexpected{malformed(false)};
|
||||
const auto region = parse_integer<std::uint64_t>((*rows)[0][0]);
|
||||
const auto tick = parse_integer<std::uint64_t>((*rows)[0][1]);
|
||||
const auto sequence = parse_integer<std::uint64_t>((*rows)[0][2]);
|
||||
if (!region || !tick || !sequence)
|
||||
return std::unexpected{malformed(false)};
|
||||
return std::optional<CommittedAction>{CommittedAction{*region, *tick, *sequence}};
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::expected<std::vector<CommittedDecision>, LeaseStoreFailure>
|
||||
decisions_from(const PgRows& rows) {
|
||||
|
||||
@@ -100,6 +100,27 @@ std::expected<void, AdmissionError> RegionHost<State>::submit(const TickInput& i
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename State>
|
||||
std::expected<void, AdmissionError>
|
||||
RegionHost<State>::submit_action(const persistence::ActionRecord& record) {
|
||||
if (record.account == persistence::Uuid{} || record.action_id == 0 || record.kind != 1 ||
|
||||
record.tick == 0)
|
||||
return std::unexpected{AdmissionError::invalid};
|
||||
if (draining_)
|
||||
return std::unexpected{AdmissionError::draining};
|
||||
if (!status_.ready)
|
||||
return std::unexpected{AdmissionError::not_ready};
|
||||
const auto same = [&](const persistence::ActionRecord& a) {
|
||||
return a.account == record.account && a.action_id == record.action_id;
|
||||
};
|
||||
if (std::ranges::any_of(action_queue_, same) || std::ranges::any_of(batch_actions_, same))
|
||||
return std::unexpected{AdmissionError::duplicate};
|
||||
if (action_queue_.size() + batch_actions_.size() >= config_.max_queued_actions)
|
||||
return std::unexpected{AdmissionError::full};
|
||||
action_queue_.push_back(record);
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename State> bool RegionHost<State>::database() {
|
||||
if (db_)
|
||||
return true;
|
||||
@@ -118,6 +139,13 @@ void RegionHost<State>::lose_authority(Unacknowledged reason, HostPhase next) {
|
||||
dropped_.push_back({a.input, reason});
|
||||
for (auto& q : queue_)
|
||||
dropped_.push_back({q, reason});
|
||||
// Actions of a batch whose publication outcome is unknown may be durable: not final.
|
||||
for (const auto& a : batch_actions_)
|
||||
dropped_actions_.push_back({a, !prepared_.has_value(), reason});
|
||||
for (const auto& a : action_queue_)
|
||||
dropped_actions_.push_back({a, true, reason});
|
||||
batch_actions_.clear();
|
||||
action_queue_.clear();
|
||||
applied_.clear();
|
||||
queue_.clear();
|
||||
batch_.reset(); // References state_: reset first.
|
||||
@@ -248,6 +276,9 @@ void RegionHost<State>::confirmed(const persistence::PublishedBatch& published,
|
||||
applied_.clear();
|
||||
for (const auto& d : published.decisions)
|
||||
outcomes_.push_back({d, head.sequence});
|
||||
for (const auto& a : batch_actions_)
|
||||
action_acks_.push_back({a, head.sequence});
|
||||
batch_actions_.clear();
|
||||
prepared_.reset();
|
||||
batch_started_ = now;
|
||||
retry_at_ = {};
|
||||
@@ -272,9 +303,9 @@ template <typename State> void RegionHost<State>::commit(SchedulerTime now) {
|
||||
persistence::PublishHooks hooks;
|
||||
if (crash)
|
||||
hooks.before_transaction = [&crash] { crash(CrashPoint::before_transaction); };
|
||||
auto published =
|
||||
Ops<State>::publish(*db_, *objects_, *grant, *committed_, *batch_, commit_id, config_.build,
|
||||
config_.restore_budget, config_.lease.commit_timeout, hooks);
|
||||
auto published = Ops<State>::publish(*db_, *objects_, *grant, *committed_, *batch_, commit_id,
|
||||
config_.build, config_.restore_budget,
|
||||
config_.lease.commit_timeout, hooks, batch_actions_);
|
||||
if (published) {
|
||||
confirmed(*published, now);
|
||||
return;
|
||||
@@ -387,6 +418,14 @@ template <typename State> void RegionHost<State>::simulate(SchedulerTime now) {
|
||||
continue;
|
||||
}
|
||||
applied_.push_back({input, report->tick});
|
||||
// Actions due at or before this tick ride it (late ones ride the first tick run).
|
||||
std::erase_if(action_queue_, [&](persistence::ActionRecord action) {
|
||||
if (action.tick > report->tick)
|
||||
return false;
|
||||
action.tick = report->tick;
|
||||
batch_actions_.push_back(action);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,6 +521,9 @@ template <typename State> void RegionHost<State>::drain() {
|
||||
for (auto& q : queue_)
|
||||
dropped_.push_back({q, Unacknowledged::drained});
|
||||
queue_.clear();
|
||||
for (const auto& a : action_queue_)
|
||||
dropped_actions_.push_back({a, true, Unacknowledged::drained});
|
||||
action_queue_.clear();
|
||||
if (status_.phase == HostPhase::running)
|
||||
status_.phase = HostPhase::draining;
|
||||
else if (status_.phase == HostPhase::acquiring)
|
||||
@@ -498,6 +540,12 @@ template <typename State> std::vector<FinalOutcome> RegionHost<State>::take_outc
|
||||
template <typename State> std::vector<Dropped> RegionHost<State>::take_dropped() {
|
||||
return std::exchange(dropped_, {});
|
||||
}
|
||||
template <typename State> std::vector<ActionAck> RegionHost<State>::take_action_acks() {
|
||||
return std::exchange(action_acks_, {});
|
||||
}
|
||||
template <typename State> std::vector<DroppedAction> RegionHost<State>::take_dropped_actions() {
|
||||
return std::exchange(dropped_actions_, {});
|
||||
}
|
||||
|
||||
template class RegionHost<processes::EnvironmentalCommunity>;
|
||||
template class RegionHost<processes::LineageRegion>;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "evo/server/postgres_action_ledger.hpp"
|
||||
|
||||
namespace evo::server {
|
||||
std::expected<std::optional<network::ActionOutcome>, network::ActionLedgerError>
|
||||
PostgresActionLedger::find(const network::AccountId& account, std::uint64_t action_id) {
|
||||
const auto lease = lease_();
|
||||
if (!lease)
|
||||
return std::unexpected(network::ActionLedgerError::unavailable);
|
||||
const auto found =
|
||||
persistence::find_region_action(*db_, key_, *lease, account.bytes, action_id, timeout_);
|
||||
if (!found.has_value())
|
||||
return std::unexpected(network::ActionLedgerError::unavailable);
|
||||
const auto& record = found.value();
|
||||
if (!record.has_value())
|
||||
return std::optional<network::ActionOutcome>{};
|
||||
return std::optional<network::ActionOutcome>{
|
||||
network::ActionOutcome{action_id, network::ActionResult::committed_no_effect,
|
||||
record.value().tick, record.value().commit_sequence}};
|
||||
}
|
||||
} // namespace evo::server
|
||||
@@ -282,14 +282,14 @@ struct RegionSessions::Impl {
|
||||
send(c, receipt);
|
||||
// A duplicate of a final action: answer with the outcome as well.
|
||||
if (receipt.status == network::AdmitStatus::duplicate)
|
||||
if (const auto o = intents.query(c.session, {m->action_id});
|
||||
if (const auto o = intents.query(c.session, {m->action_id}, admission());
|
||||
o.result == network::ActionResult::committed_no_effect ||
|
||||
o.result == network::ActionResult::not_committed)
|
||||
send(c, o);
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::ActionQuery>(&*decoded))
|
||||
return send(c, intents.query(c.session, *m));
|
||||
return send(c, intents.query(c.session, *m, admission()));
|
||||
if (const auto* m = std::get_if<network::SessionClose>(&*decoded);
|
||||
m && m->reason == SessionCloseReason::client_closed) {
|
||||
close(c, SessionCloseReason::client_closed, now);
|
||||
@@ -324,6 +324,7 @@ RegionSessions::create(RegionSessionsConfig config) {
|
||||
auto intents = network::IntentAdmission::create(config.intents);
|
||||
if (!intents)
|
||||
return std::unexpected(RegionSessionsError::configuration);
|
||||
intents->attach(config.actions);
|
||||
auto endpoint = network::quic::Endpoint::serve(config.transport);
|
||||
if (!endpoint)
|
||||
return std::unexpected(RegionSessionsError::transport);
|
||||
@@ -407,8 +408,13 @@ std::vector<network::CarriedAction> RegionSessions::carry(std::uint64_t tick) {
|
||||
return impl_->intents.carry(tick);
|
||||
}
|
||||
|
||||
void RegionSessions::committed(std::uint64_t end_tick, std::uint64_t commit_sequence) {
|
||||
impl_->deliver(impl_->intents.committed(end_tick, commit_sequence));
|
||||
void RegionSessions::committed(std::span<const network::CarriedAction> actions,
|
||||
std::uint64_t commit_sequence) {
|
||||
impl_->deliver(impl_->intents.committed(actions, commit_sequence));
|
||||
}
|
||||
|
||||
void RegionSessions::dropped(std::span<const network::CarriedAction> actions, bool final) {
|
||||
impl_->deliver(impl_->intents.dropped(actions, final));
|
||||
}
|
||||
|
||||
void RegionSessions::shutdown(Clock::time_point now) {
|
||||
|
||||
Reference in New Issue
Block a user