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:
@@ -105,6 +105,9 @@ struct CellularPreparedCommit {
|
||||
RegionKey key{};
|
||||
Uuid commit{};
|
||||
std::vector<std::uint8_t> manifest, trace, actions;
|
||||
// ADR-0121: the canonical mutation block and one result byte per record; both empty
|
||||
// when the trace carries no selections.
|
||||
std::vector<std::uint8_t> mutations, results;
|
||||
};
|
||||
struct CellularPublicationFailure {
|
||||
PublicationError kind{};
|
||||
@@ -125,12 +128,16 @@ struct CellularProfileMigrationFailure {
|
||||
};
|
||||
struct PublishedCellularBatch {
|
||||
CommittedCheckpoint committed;
|
||||
// Each published mutation action's final result, in action-block order.
|
||||
std::vector<server::CellularMutationResult> mutation_results;
|
||||
};
|
||||
struct RecoveredCellularCheckpoint {
|
||||
CommittedCheckpoint committed;
|
||||
CheckpointManifest manifest;
|
||||
std::unique_ptr<server::CellularLives> state;
|
||||
std::vector<server::CellularActionRecord> actions;
|
||||
std::vector<server::CellularMutationActionRecord> mutation_actions;
|
||||
std::vector<server::CellularMutationResult> mutation_results;
|
||||
};
|
||||
|
||||
// Owner/operator connection only: uploads a tick-0 state and records genesis.
|
||||
@@ -220,7 +227,8 @@ publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const
|
||||
const server::CellularLives& candidate, Uuid commit,
|
||||
const Sha256Digest& build, std::chrono::milliseconds timeout,
|
||||
const PublishHooks& hooks = {},
|
||||
std::span<const server::CellularActionRecord> actions = {});
|
||||
std::span<const server::CellularActionRecord> actions = {},
|
||||
std::span<const server::CellularMutationActionRecord> mutation_actions = {});
|
||||
[[nodiscard]] std::expected<CommittedCheckpoint, CellularPublicationFailure>
|
||||
retry_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
std::chrono::milliseconds timeout);
|
||||
|
||||
@@ -143,6 +143,31 @@ struct CellularBirthBinding {
|
||||
[[nodiscard]] std::expected<std::vector<CellularBirthBinding>, LeaseStoreFailure>
|
||||
load_cellular_publication_births(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const Uuid& commit, std::chrono::milliseconds timeout);
|
||||
// Schema v35 (ADR-0121): a checkpoint whose trace carries mutation selections publishes
|
||||
// with its canonical mutation block (64-byte records) and one result byte per record.
|
||||
[[nodiscard]] std::expected<RegionHead, LeaseStoreFailure> publish_cellular_mutation_checkpoint(
|
||||
Postgres& db, std::span<const std::uint8_t> manifest, std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions, std::span<const std::uint8_t> trace,
|
||||
std::span<const std::uint8_t> mutations, std::span<const std::uint8_t> results,
|
||||
std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<ResolvedCommit, LeaseStoreFailure> resolve_cellular_mutation_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,
|
||||
std::span<const std::uint8_t> trace, std::span<const std::uint8_t> mutations,
|
||||
std::span<const std::uint8_t> results, std::chrono::milliseconds timeout);
|
||||
// The mutation choices bound to one commit, ordered (tick, account, action): the 16-byte
|
||||
// account, action id, 34-byte reserved input and final result.
|
||||
struct CellularMutationPublication {
|
||||
std::array<std::uint8_t, 16> account{};
|
||||
std::uint64_t action_id{};
|
||||
std::array<std::uint8_t, 34> input{};
|
||||
std::uint8_t result{};
|
||||
friend bool operator==(const CellularMutationPublication&,
|
||||
const CellularMutationPublication&) = default;
|
||||
};
|
||||
[[nodiscard]] std::expected<std::vector<CellularMutationPublication>, LeaseStoreFailure>
|
||||
load_cellular_mutation_publications(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const Uuid& commit, std::chrono::milliseconds timeout);
|
||||
// The committed record of an account's action in the lease's world (schema v11), under the
|
||||
// caller's exact lease. Nothing when the action was never committed.
|
||||
struct CommittedAction {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
@@ -93,6 +94,25 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes);
|
||||
// Every tick must cover its living set; the caller compares the returned snapshot.
|
||||
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularBatchError>
|
||||
replay_cellular_batch(const CellularLives& base, const CellularBatch& batch);
|
||||
// The same replay, also reporting every mutation selection's final result in trace order
|
||||
// (ADR-0121): the authority for the results a publication binds and recovery compares.
|
||||
struct CellularMutationOutcome {
|
||||
std::uint64_t tick{}, life_id{}, successor_id{};
|
||||
CellularMutationResult result{};
|
||||
friend bool operator==(const CellularMutationOutcome&,
|
||||
const CellularMutationOutcome&) = default;
|
||||
};
|
||||
[[nodiscard]] std::expected<std::unique_ptr<CellularLives>, CellularBatchError>
|
||||
replay_cellular_batch(const CellularLives& base, const CellularBatch& batch,
|
||||
std::vector<CellularMutationOutcome>& mutation_outcomes);
|
||||
// The canonical 34-byte reserved choice (schema v29): tick, life, event and offer tick as
|
||||
// u64 and the operator as u16, little-endian.
|
||||
inline constexpr std::size_t cellular_mutation_input_bytes = 34;
|
||||
[[nodiscard]] std::array<std::uint8_t, cellular_mutation_input_bytes>
|
||||
encode_cellular_mutation_input(const CellularMutationActionRecord& action);
|
||||
[[nodiscard]] 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);
|
||||
[[nodiscard]] std::expected<std::vector<std::uint8_t>, CellularActionBlockError>
|
||||
encode_cellular_action_block(std::span<const CellularActionRecord> actions,
|
||||
std::uint64_t begin_tick, std::uint64_t end_tick);
|
||||
|
||||
Reference in New Issue
Block a user