Publish mutation choices atomically with their checkpoint
ADR-0121, schema v35. A checkpoint whose trace carries mutation selections publishes with its canonical mutation block and one result byte per choice. SQL checks the block's order, matches each record to one reserved choice of this region and to its trace selection (tick, life, offer, operator, successor identity), binds it to the commit with its result, refuses a choice already bound elsewhere and checks exact retries. The four-argument publisher becomes an internal helper behind a wrapper that refuses traces with selections. C++ publication takes the results from its own replay rather than a caller, prepared commits carry block and results through retry and resolution, and recovery rebuilds the bound choices and requires the replay's results to match. A PostgreSQL test feeds a v4 cell to its first offer, publishes a reserved choice, recovers it and restarts a host. Host and session admission follow in 11.4c-2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -356,6 +356,48 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
|
||||
std::expected<std::unique_ptr<CellularLives>, CellularBatchError>
|
||||
replay_cellular_batch(const CellularLives& base, const CellularBatch& batch) {
|
||||
std::vector<CellularMutationOutcome> ignored;
|
||||
return replay_cellular_batch(base, batch, ignored);
|
||||
}
|
||||
|
||||
std::array<std::uint8_t, cellular_mutation_input_bytes>
|
||||
encode_cellular_mutation_input(const CellularMutationActionRecord& action) {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
bytes.reserve(cellular_mutation_input_bytes);
|
||||
put(bytes, action.tick, 8);
|
||||
put(bytes, action.input.life_id, 8);
|
||||
put(bytes, action.input.event_index, 8);
|
||||
put(bytes, action.input.offer_tick, 8);
|
||||
put(bytes, action.input.operator_id, 2);
|
||||
std::array<std::uint8_t, cellular_mutation_input_bytes> out{};
|
||||
std::ranges::copy(bytes, out.begin());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::optional<CellularMutationActionRecord>
|
||||
decode_cellular_mutation_input(const std::array<std::uint8_t, 16>& account, std::uint64_t action_id,
|
||||
std::span<const std::uint8_t> input) {
|
||||
if (input.size() != cellular_mutation_input_bytes)
|
||||
return std::nullopt;
|
||||
CellularMutationActionRecord action;
|
||||
action.account = account;
|
||||
action.action_id = action_id;
|
||||
action.tick = get(input, 0, 8);
|
||||
action.input.life_id = get(input, 8, 8);
|
||||
action.input.event_index = get(input, 16, 8);
|
||||
action.input.offer_tick = get(input, 24, 8);
|
||||
action.input.operator_id = static_cast<std::uint16_t>(get(input, 32, 2));
|
||||
if (action_id == 0 || action.tick == 0 || action.input.life_id == 0 ||
|
||||
action.input.event_index == 0 || action.input.offer_tick == 0 ||
|
||||
action.input.offer_tick >= action.tick || action.input.operator_id == 0)
|
||||
return std::nullopt;
|
||||
return action;
|
||||
}
|
||||
|
||||
std::expected<std::unique_ptr<CellularLives>, CellularBatchError>
|
||||
replay_cellular_batch(const CellularLives& base, const CellularBatch& batch,
|
||||
std::vector<CellularMutationOutcome>& mutation_outcomes) {
|
||||
mutation_outcomes.clear();
|
||||
const auto& h = batch.header;
|
||||
if (!valid_header(h, batch.ticks.size()) || !valid_ticks(batch.ticks))
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
@@ -367,8 +409,12 @@ replay_cellular_batch(const CellularLives& base, const CellularBatch& batch) {
|
||||
if (!replay)
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
for (const auto& tick : batch.ticks) {
|
||||
if (!(*replay)->advance_tick_with_mutations(tick.lives, tick.mutations))
|
||||
const auto executed = (*replay)->advance_tick_with_mutations(tick.lives, tick.mutations);
|
||||
if (!executed)
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
for (const auto& mutation : executed->mutations)
|
||||
mutation_outcomes.push_back(
|
||||
{(*replay)->tick(), mutation.life_id, mutation.successor_id, mutation.result});
|
||||
for (const auto& birth : tick.births) {
|
||||
const LifeRequest request{birth.account, birth.request};
|
||||
const LifeAllocation allocation{birth.identity,
|
||||
|
||||
Reference in New Issue
Block a user