Build bounded cellular session batches
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (postgres) (push) Failing after 53s
Foundation / checks (tsan) (push) Failing after 31s
Foundation / checks (network) (push) Failing after 3m1s
Foundation / checks (client) (push) Failing after 4m25s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (postgres) (push) Failing after 53s
Foundation / checks (tsan) (push) Failing after 31s
Foundation / checks (network) (push) Failing after 3m1s
Foundation / checks (client) (push) Failing after 4m25s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -67,4 +67,51 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
});
|
||||
return prepared;
|
||||
}
|
||||
|
||||
std::expected<CellularSessionBatchBuilder, CellularSessionBatchError>
|
||||
CellularSessionBatchBuilder::create(const CellularLives& committed_state,
|
||||
const persistence::RegionHead& committed_head) {
|
||||
if (committed_head.frame != committed_state.frame() ||
|
||||
committed_head.end_tick != committed_state.tick() ||
|
||||
std::ranges::all_of(committed_head.commit, [](std::uint8_t byte) { return byte == 0; }) ||
|
||||
std::ranges::all_of(committed_head.digest, [](std::uint8_t byte) { return byte == 0; }))
|
||||
return std::unexpected{CellularSessionBatchError::head};
|
||||
auto working = CellularLives::restore(committed_state.snapshot(), committed_state.world(),
|
||||
committed_state.region(), committed_state.frame(),
|
||||
committed_state.tick());
|
||||
if (!working)
|
||||
return std::unexpected{CellularSessionBatchError::biology};
|
||||
|
||||
CellularSessionBatchBuilder builder{std::move(*working)};
|
||||
builder.batch_.header = {committed_state.world(), committed_state.region(),
|
||||
committed_state.frame(), committed_head.commit,
|
||||
committed_head.digest, committed_state.tick(),
|
||||
committed_state.tick()};
|
||||
return builder;
|
||||
}
|
||||
|
||||
std::expected<void, CellularSessionBatchError>
|
||||
CellularSessionBatchBuilder::append(std::uint64_t tick,
|
||||
std::span<const CellularLifeIntent> baseline,
|
||||
std::span<const network::CarriedAction> actions) {
|
||||
if (batch_.ticks.size() >= max_cellular_batch_ticks)
|
||||
return std::unexpected{CellularSessionBatchError::batch_full};
|
||||
if (actions_.size() + actions.size() > max_cellular_action_records)
|
||||
return std::unexpected{CellularSessionBatchError::action_limit};
|
||||
auto prepared = prepare_cellular_session_tick(*working_, tick, baseline, actions);
|
||||
if (!prepared)
|
||||
return std::unexpected{prepared.error()};
|
||||
for (const auto& action : prepared->actions)
|
||||
if (std::ranges::find_if(actions_, [&](const CellularActionRecord& previous) {
|
||||
return previous.account == action.account &&
|
||||
previous.action_id == action.action_id;
|
||||
}) != actions_.end())
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_action};
|
||||
if (!working_->advance_tick(prepared->intents.lives))
|
||||
return std::unexpected{CellularSessionBatchError::biology};
|
||||
batch_.ticks.push_back(std::move(prepared->intents));
|
||||
batch_.header.end_tick = tick;
|
||||
actions_.insert(actions_.end(), prepared->actions.begin(), prepared->actions.end());
|
||||
return {};
|
||||
}
|
||||
} // namespace evo::server
|
||||
|
||||
Reference in New Issue
Block a user