ADR 0127
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m23s
Foundation / checks (tsan) (push) Successful in 10m11s
Foundation / checks (client) (push) Failing after 14m26s
Foundation / checks (network) (push) Successful in 18m54s
Foundation / checks (checks) (push) Successful in 42m9s
Foundation / checks (postgres) (push) Successful in 43m51s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m23s
Foundation / checks (tsan) (push) Successful in 10m11s
Foundation / checks (client) (push) Failing after 14m26s
Foundation / checks (network) (push) Successful in 18m54s
Foundation / checks (checks) (push) Successful in 42m9s
Foundation / checks (postgres) (push) Successful in 43m51s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -612,6 +612,10 @@ CellularRegionHost::publish(const CellularBatch& batch,
|
||||
}
|
||||
|
||||
void CellularRegionHost::queue_birth(const CellularTickIntents::Birth& birth) {
|
||||
if (std::ranges::any_of(pending_birth_refusals_, [&](const auto& refusal) {
|
||||
return refusal.birth.account == birth.account && refusal.birth.request == birth.request;
|
||||
}))
|
||||
return;
|
||||
const auto found = std::ranges::find_if(queued_births_, [&](const auto& queued) {
|
||||
return queued.account == birth.account && queued.request == birth.request;
|
||||
});
|
||||
@@ -627,6 +631,27 @@ void CellularRegionHost::finalize_births(std::span<const CellularTickIntents::Bi
|
||||
});
|
||||
}
|
||||
|
||||
void CellularRegionHost::refuse_births(std::span<const CellularBirthRefusal> refusals) {
|
||||
for (const auto& refusal : refusals) {
|
||||
if (refusal.reason != CellularLivesError::insufficient_funding &&
|
||||
refusal.reason != CellularLivesError::no_placement &&
|
||||
refusal.reason != CellularLivesError::life_exists)
|
||||
continue;
|
||||
if (std::ranges::find(queued_births_, refusal.birth) == queued_births_.end())
|
||||
continue;
|
||||
// Remove before the database call: an uncertain refusal must never race a spawn.
|
||||
std::erase(queued_births_, refusal.birth);
|
||||
std::erase_if(pending_birth_refusals_, [&](const auto& previous) {
|
||||
return previous.birth.account == refusal.birth.account;
|
||||
});
|
||||
if (pending_birth_refusals_.size() == biology::max_cellular_tick_lives)
|
||||
pending_birth_refusals_.erase(pending_birth_refusals_.begin());
|
||||
pending_birth_refusals_.push_back(refusal);
|
||||
static_cast<void>(query_birth(refusal.birth.account, refusal.birth.generation,
|
||||
refusal.birth.request, false));
|
||||
}
|
||||
}
|
||||
|
||||
network::PrimitiveLifeOutcome CellularRegionHost::query_birth(const persistence::Uuid& account,
|
||||
std::uint64_t generation,
|
||||
std::uint64_t request, bool enqueue) {
|
||||
@@ -661,6 +686,30 @@ network::PrimitiveLifeOutcome CellularRegionHost::query_birth(const persistence:
|
||||
if (outcome.reservation.region != config_.key.region)
|
||||
return unknown();
|
||||
const auto result = life_result(outcome.reservation.refusal);
|
||||
const auto refused = std::ranges::find_if(pending_birth_refusals_, [&](const auto& entry) {
|
||||
return entry.birth.account == account && entry.birth.request == request;
|
||||
});
|
||||
if (refused != pending_birth_refusals_.end()) {
|
||||
if (result != PrimitiveLifeResult::pending) {
|
||||
pending_birth_refusals_.erase(refused);
|
||||
} else {
|
||||
const auto reason = refused->reason == CellularLivesError::insufficient_funding
|
||||
? persistence::LifeRefusal::insufficient_funding
|
||||
: refused->reason == CellularLivesError::no_placement
|
||||
? persistence::LifeRefusal::no_placement
|
||||
: persistence::LifeRefusal::existing_life;
|
||||
const auto recorded =
|
||||
persistence::reject_primitive_life(*db_, config_.key, *grant, account, generation,
|
||||
request, reason, config_.lease.commit_timeout);
|
||||
if (!recorded) {
|
||||
db_.reset();
|
||||
++status_.store_failures;
|
||||
return unknown();
|
||||
}
|
||||
pending_birth_refusals_.erase(refused);
|
||||
return {request, life_result(*recorded), outcome.reservation.identity, 0};
|
||||
}
|
||||
}
|
||||
if (result == PrimitiveLifeResult::pending && enqueue)
|
||||
queue_birth({account, request, generation, outcome.reservation.identity});
|
||||
return {request, result, outcome.reservation.identity, 0};
|
||||
|
||||
@@ -170,6 +170,21 @@ std::expected<void, CellularSessionBatchError> CellularSessionBatchBuilder::appe
|
||||
std::span<const network::CarriedAction> actions,
|
||||
std::span<const CellularTickIntents::Birth> births,
|
||||
std::span<const persistence::CellularMutationReservation> mutations) {
|
||||
return append_impl(tick, baseline, actions, births, mutations, false);
|
||||
}
|
||||
std::expected<void, CellularSessionBatchError>
|
||||
CellularSessionBatchBuilder::append_with_birth_refusals(
|
||||
std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
|
||||
std::span<const network::CarriedAction> actions,
|
||||
std::span<const CellularTickIntents::Birth> births,
|
||||
std::span<const persistence::CellularMutationReservation> mutations) {
|
||||
return append_impl(tick, baseline, actions, births, mutations, true);
|
||||
}
|
||||
std::expected<void, CellularSessionBatchError> CellularSessionBatchBuilder::append_impl(
|
||||
std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
|
||||
std::span<const network::CarriedAction> actions,
|
||||
std::span<const CellularTickIntents::Birth> births,
|
||||
std::span<const persistence::CellularMutationReservation> mutations, bool allow_refusals) {
|
||||
if (batch_.ticks.size() >= max_cellular_batch_ticks)
|
||||
return std::unexpected{CellularSessionBatchError::batch_full};
|
||||
if (actions_.size() + actions.size() > max_cellular_action_records)
|
||||
@@ -204,6 +219,11 @@ std::expected<void, CellularSessionBatchError> CellularSessionBatchBuilder::appe
|
||||
return std::unexpected{CellularSessionBatchError::invalid_birth};
|
||||
if (i > 0 && prepared->intents.births[i - 1].account == birth.account)
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_birth};
|
||||
if (std::ranges::any_of(refused_births_, [&](const auto& previous) {
|
||||
return previous.birth.account == birth.account ||
|
||||
previous.birth.identity == birth.identity;
|
||||
}))
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_birth};
|
||||
for (const auto& previous_tick : batch_.ticks)
|
||||
if (std::ranges::any_of(previous_tick.births, [&](const auto& previous) {
|
||||
return previous.account == birth.account || previous.identity == birth.identity;
|
||||
@@ -217,15 +237,26 @@ std::expected<void, CellularSessionBatchError> CellularSessionBatchBuilder::appe
|
||||
!(*next)->advance_tick_with_mutations(prepared->intents.lives, prepared->intents.mutations))
|
||||
return std::unexpected{CellularSessionBatchError::biology};
|
||||
|
||||
std::vector<CellularTickIntents::Birth> accepted_births;
|
||||
std::vector<CellularBirthRefusal> refused_births;
|
||||
for (const auto& birth : prepared->intents.births) {
|
||||
const LifeRequest request{birth.account, birth.request};
|
||||
const LifeAllocation allocation{
|
||||
birth.identity, birth.identity, birth.identity, birth.identity, {tick}};
|
||||
auto created = (*next)->birth_candidate(request, allocation);
|
||||
if (!created && allow_refusals &&
|
||||
(created.error() == CellularLivesError::insufficient_funding ||
|
||||
created.error() == CellularLivesError::no_placement ||
|
||||
created.error() == CellularLivesError::life_exists)) {
|
||||
refused_births.push_back({birth, created.error()});
|
||||
continue;
|
||||
}
|
||||
if (!created)
|
||||
return std::unexpected{CellularSessionBatchError::invalid_birth};
|
||||
*next = std::move(*created);
|
||||
accepted_births.push_back(birth);
|
||||
}
|
||||
prepared->intents.births = std::move(accepted_births);
|
||||
|
||||
auto next_batch = batch_;
|
||||
next_batch.ticks.push_back(std::move(prepared->intents));
|
||||
@@ -245,6 +276,7 @@ std::expected<void, CellularSessionBatchError> CellularSessionBatchBuilder::appe
|
||||
batch_ = std::move(next_batch);
|
||||
actions_.insert(actions_.end(), prepared->actions.begin(), prepared->actions.end());
|
||||
mutation_actions_ = next_mutation_actions;
|
||||
refused_births_.insert(refused_births_.end(), refused_births.begin(), refused_births.end());
|
||||
return {};
|
||||
}
|
||||
} // namespace evo::server
|
||||
|
||||
Reference in New Issue
Block a user