feat: durable mutation queue (schema 59)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m24s
Foundation / postgres-tools (push) Successful in 1m31s
Foundation / server-image (push) Successful in 4m25s
Foundation / image (push) Successful in 4m50s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m24s
Foundation / postgres-tools (push) Successful in 1m31s
Foundation / server-image (push) Successful in 4m25s
Foundation / image (push) Successful in 4m50s
A mutation choice's reserved tick is now the earliest tick it may bind at, not the only one (ADR-0121 amendment). With write-behind commits, a choice reserved for head + 1 landed in ticks already being simulated or committed: the batch was refused, or the reservation was orphaned for a past tick and stalled the region. Schema 59: a bound record carries the tick it applied at and the rest of its input must equal the reservation's; the "omits a reserved mutation" refusals are removed. Existing rows are unchanged, so an orphaned reservation binds at the next commit that carries it. The host keeps every unbound reservation queued and the open batch binds those the commit in flight does not carry, at its next tick; the earlier hold on new choices is removed. A choice that outlives its life binds as life_died (owner, trace matching and recovery accept it when no life with that ID remains). Recovery takes a bound choice's tick from its trace. Tests: a choice skipped by one checkpoint binds a tick late and recovers; builder late binding, refusal before the earliest tick, and a departed life's life_died outcome. Full local PostgreSQL qualification passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,9 +6,12 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::persistence {
|
||||
namespace {
|
||||
@@ -64,9 +67,12 @@ mutation_results(const server::CellularLives& base,
|
||||
std::vector<std::uint8_t> results;
|
||||
results.reserve(actions.size());
|
||||
for (const auto& action : actions) {
|
||||
const auto life =
|
||||
std::ranges::find(base.lives(), action.account, &server::CellularOwnedLife::account);
|
||||
if (life == base.lives().end() || life->identity.life != action.input.life_id)
|
||||
// A life that ended before the batch (ADR-0121 amendment, schema 59) has no owner
|
||||
// entry; one still present must be the account's.
|
||||
const auto life = std::ranges::find(
|
||||
base.lives(), action.input.life_id,
|
||||
[](const server::CellularOwnedLife& value) { return value.identity.life; });
|
||||
if (life != base.lives().end() && life->account != action.account)
|
||||
return std::nullopt;
|
||||
const auto outcome = std::ranges::find_if(outcomes, [&](const auto& candidate) {
|
||||
return candidate.tick == action.tick && candidate.life_id == action.input.life_id;
|
||||
@@ -78,6 +84,23 @@ mutation_results(const server::CellularLives& base,
|
||||
return results;
|
||||
}
|
||||
|
||||
// The tick of the trace selection a bound choice names (its life, offer and operator).
|
||||
std::optional<std::uint64_t> applied_tick(const server::CellularBatch& trace,
|
||||
const server::CellularMutationActionRecord& action) {
|
||||
std::optional<std::uint64_t> found;
|
||||
for (std::size_t i = 0; i < trace.ticks.size(); ++i)
|
||||
for (const auto& selection : trace.ticks[i].mutations)
|
||||
if (selection.life_id == action.input.life_id &&
|
||||
selection.event_index == action.input.event_index &&
|
||||
selection.offer_tick == action.input.offer_tick &&
|
||||
selection.operator_id == action.input.operator_id) {
|
||||
if (found)
|
||||
return std::nullopt;
|
||||
found = trace.header.begin_tick + i + 1;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
std::size_t selection_count(const server::CellularBatch& trace) {
|
||||
std::size_t count{};
|
||||
for (const auto& tick : trace.ticks)
|
||||
@@ -844,9 +867,34 @@ recover_cellular_loaded(Postgres& db, const FilesystemObjectStore& objects, Regi
|
||||
server::decode_cellular_mutation_input(row.account, row.action_id, row.input);
|
||||
if (!action)
|
||||
return fail_with(RecoveryError::history);
|
||||
// The stored input names the earliest tick; the choice bound at its selection's.
|
||||
const auto bound = applied_tick(*trace, *action);
|
||||
if (!bound || *bound < action->tick)
|
||||
return fail_with(RecoveryError::history);
|
||||
action->tick = *bound;
|
||||
mutation_actions.push_back(*action);
|
||||
stored_results.push_back(row.result);
|
||||
}
|
||||
// Results follow the block's canonical (tick, account, action) order.
|
||||
std::vector<std::size_t> order(mutation_actions.size());
|
||||
for (std::size_t i = 0; i < order.size(); ++i)
|
||||
order[i] = i;
|
||||
std::ranges::sort(order, [&](std::size_t left, std::size_t right) {
|
||||
const auto& a = mutation_actions[left];
|
||||
const auto& b = mutation_actions[right];
|
||||
return std::tie(a.tick, a.account, a.action_id) <
|
||||
std::tie(b.tick, b.account, b.action_id);
|
||||
});
|
||||
{
|
||||
std::vector<server::CellularMutationActionRecord> sorted_actions;
|
||||
std::vector<std::uint8_t> sorted_results;
|
||||
for (const auto i : order) {
|
||||
sorted_actions.push_back(mutation_actions[i]);
|
||||
sorted_results.push_back(stored_results[i]);
|
||||
}
|
||||
mutation_actions = std::move(sorted_actions);
|
||||
stored_results = std::move(sorted_results);
|
||||
}
|
||||
if (mutation_actions.size() != selection_count(*trace) ||
|
||||
(!mutation_actions.empty() &&
|
||||
(!server::encode_cellular_mutation_action_block(mutation_actions, manifest->begin_tick,
|
||||
|
||||
Reference in New Issue
Block a user