M12.4: retain and settle owned population intervals
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m28s
Foundation / checks (tsan) (push) Failing after 18m22s
Foundation / checks (network) (push) Successful in 20m38s
Foundation / checks (client) (push) Failing after 21m6s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 46m54s
Foundation / checks (checks) (push) Canceled after 47m3s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m28s
Foundation / checks (tsan) (push) Failing after 18m22s
Foundation / checks (network) (push) Successful in 20m38s
Foundation / checks (client) (push) Failing after 21m6s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 46m54s
Foundation / checks (checks) (push) Canceled after 47m3s
This commit is contained in:
@@ -74,6 +74,13 @@ class Reader {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
bool population_interval_safe(const CellularLives& state) noexcept {
|
||||
return state.rules_version() == cellular_lives_foraging_rules &&
|
||||
std::ranges::all_of(state.lives(), [](const auto& life) {
|
||||
return life.account == LifeAccount{} || life.presence == CellularPresence::suspended;
|
||||
});
|
||||
}
|
||||
|
||||
std::expected<CellularBatch, CellularPopulationError>
|
||||
unattended_population_inputs(const CellularLives& base, const CellularBatchHeader& header) {
|
||||
if (header.world != base.world() || header.region != base.region() ||
|
||||
@@ -178,6 +185,8 @@ execute_population_batch(const CellularPopulation& base, CellularPopulationBatch
|
||||
|
||||
std::expected<CellularPopulationExecution, CellularPopulationError>
|
||||
prepare_population_batch(const CellularPopulation& base, CellularBatch biology) {
|
||||
if (!population_interval_safe(base.state()))
|
||||
return std::unexpected(CellularPopulationError::ineligible);
|
||||
CellularPopulationBatch batch{biology.header, std::move(biology), {}, {}};
|
||||
auto state = execute_population_batch(base, batch, true);
|
||||
if (!state)
|
||||
|
||||
@@ -16,7 +16,11 @@ bool cellular_unattended_tick_needed(const CellularLives& state) noexcept {
|
||||
|
||||
std::expected<CellularScheduleStatus, CellularScheduleError>
|
||||
CellularTickSchedule::observe(std::uint64_t now_us, std::uint64_t epoch,
|
||||
std::uint64_t committed_tick, bool needed, bool authoritative) {
|
||||
std::uint64_t committed_tick, bool needed, bool authoritative,
|
||||
std::uint64_t previously_admitted_ticks) {
|
||||
if (previously_admitted_ticks > 64 ||
|
||||
previously_admitted_ticks > std::numeric_limits<std::uint64_t>::max() - committed_tick)
|
||||
return std::unexpected(CellularScheduleError::admission);
|
||||
if (observed_ && now_us < last_us_)
|
||||
return std::unexpected(CellularScheduleError::clock_regression);
|
||||
if (authoritative && epoch == 0)
|
||||
@@ -35,27 +39,30 @@ CellularTickSchedule::observe(std::uint64_t now_us, std::uint64_t epoch,
|
||||
was_authoritative_ = authoritative;
|
||||
status_.head_age_us = have_receipt_ ? now_us - receipt_us_ : 0;
|
||||
status_.due = false;
|
||||
status_.retry_ready = now_us >= retry_us_;
|
||||
status_.debt = 0;
|
||||
if (!authoritative || !needed) {
|
||||
anchored_ = false;
|
||||
retry_us_ = 0;
|
||||
status_.retry_ready = true;
|
||||
return status_;
|
||||
}
|
||||
if (!anchored_ || epoch != epoch_) {
|
||||
anchored_ = true;
|
||||
origin_us_ = now_us;
|
||||
origin_tick_ = committed_tick;
|
||||
origin_tick_ = committed_tick + previously_admitted_ticks;
|
||||
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 completed_ticks = committed_tick > origin_tick_ ? committed_tick - origin_tick_ : 0;
|
||||
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_;
|
||||
status_.retry_ready = now_us >= retry_us_;
|
||||
status_.due = status_.debt > 0 && status_.retry_ready;
|
||||
return status_;
|
||||
}
|
||||
void CellularTickSchedule::defer(std::uint64_t now_us) noexcept {
|
||||
@@ -64,6 +71,7 @@ void CellularTickSchedule::defer(std::uint64_t now_us) noexcept {
|
||||
? maximum
|
||||
: now_us + biology::cellular_motion_tick_microseconds;
|
||||
status_.due = false;
|
||||
status_.retry_ready = false;
|
||||
}
|
||||
CellularScheduleStatus CellularTickSchedule::status() const noexcept {
|
||||
return status_;
|
||||
|
||||
Reference in New Issue
Block a user