M12.4: keep cellular wildlife ticking and retain scheduling debt
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m35s
Foundation / checks (tsan) (push) Failing after 17m51s
Foundation / checks (network) (push) Successful in 21m13s
Foundation / checks (client) (push) Successful in 22m19s
Foundation / checks (postgres) (push) Successful in 48m25s
Foundation / checks (checks) (push) Failing after 50m8s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m35s
Foundation / checks (tsan) (push) Failing after 17m51s
Foundation / checks (network) (push) Successful in 21m13s
Foundation / checks (client) (push) Successful in 22m19s
Foundation / checks (postgres) (push) Successful in 48m25s
Foundation / checks (checks) (push) Failing after 50m8s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#include "evo/server/lifecycle/cellular_schedule.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
namespace evo::server {
|
||||
bool cellular_unattended_tick_needed(const CellularLives& state) noexcept {
|
||||
// Historical trial profiles lack the offline freeze. Do not opt them into
|
||||
// unattended stepping and accidentally advance disconnected controlled cells.
|
||||
if (state.rules_version() < cellular_lives_presence_rules)
|
||||
return false;
|
||||
return std::ranges::any_of(state.lives(), [](const auto& life) {
|
||||
return life.account == LifeAccount{} || life.presence != CellularPresence::suspended;
|
||||
});
|
||||
}
|
||||
|
||||
std::expected<CellularScheduleStatus, CellularScheduleError>
|
||||
CellularTickSchedule::observe(std::uint64_t now_us, std::uint64_t epoch,
|
||||
std::uint64_t committed_tick, bool needed, bool authoritative) {
|
||||
if (observed_ && now_us < last_us_)
|
||||
return std::unexpected(CellularScheduleError::clock_regression);
|
||||
if (authoritative && epoch == 0)
|
||||
return std::unexpected(CellularScheduleError::authority);
|
||||
if (anchored_ && authoritative && epoch == epoch_ && committed_tick < head_)
|
||||
return std::unexpected(CellularScheduleError::head_regression);
|
||||
observed_ = true;
|
||||
last_us_ = now_us;
|
||||
if (authoritative &&
|
||||
(!was_authoritative_ || epoch != receipt_epoch_ || committed_tick != receipt_tick_)) {
|
||||
have_receipt_ = true;
|
||||
receipt_us_ = now_us;
|
||||
receipt_tick_ = committed_tick;
|
||||
receipt_epoch_ = epoch;
|
||||
}
|
||||
was_authoritative_ = authoritative;
|
||||
status_.head_age_us = have_receipt_ ? now_us - receipt_us_ : 0;
|
||||
status_.due = false;
|
||||
status_.debt = 0;
|
||||
if (!authoritative || !needed) {
|
||||
anchored_ = false;
|
||||
retry_us_ = 0;
|
||||
return status_;
|
||||
}
|
||||
if (!anchored_ || epoch != epoch_) {
|
||||
anchored_ = true;
|
||||
origin_us_ = now_us;
|
||||
origin_tick_ = committed_tick;
|
||||
epoch_ = epoch;
|
||||
retry_us_ = 0;
|
||||
}
|
||||
head_ = committed_tick;
|
||||
const auto elapsed_ticks = (now_us - origin_us_) / biology::cellular_motion_tick_microseconds;
|
||||
const auto completed_ticks = committed_tick - origin_tick_;
|
||||
const auto remaining = std::numeric_limits<std::uint64_t>::max() - committed_tick;
|
||||
status_.debt =
|
||||
elapsed_ticks > completed_ticks ? std::min(elapsed_ticks - completed_ticks, remaining) : 0;
|
||||
status_.max_debt = std::max(status_.max_debt, status_.debt);
|
||||
status_.due = status_.debt > 0 && now_us >= retry_us_;
|
||||
return status_;
|
||||
}
|
||||
void CellularTickSchedule::defer(std::uint64_t now_us) noexcept {
|
||||
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
||||
retry_us_ = now_us > maximum - biology::cellular_motion_tick_microseconds
|
||||
? maximum
|
||||
: now_us + biology::cellular_motion_tick_microseconds;
|
||||
status_.due = false;
|
||||
}
|
||||
CellularScheduleStatus CellularTickSchedule::status() const noexcept {
|
||||
return status_;
|
||||
}
|
||||
} // namespace evo::server
|
||||
Reference in New Issue
Block a user