Format M11 cellular code with clang-format 19
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m52s
Foundation / checks (client) (push) Failing after 4m25s
Foundation / checks (network) (push) Failing after 3m2s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 5m47s
Foundation / checks (postgres) (push) Canceled after 1m24s

This commit is contained in:
dingo
2026-10-11 02:59:41 -04:00
parent b8a1288ee9
commit c81c1bfc56
25 changed files with 371 additions and 356 deletions
+44 -48
View File
@@ -51,8 +51,8 @@ std::vector<CellularTickIntents::Birth> births_in(const CellularBatch& batch) {
}
std::optional<persistence::Uuid> commit_id(const persistence::CommittedCheckpoint& previous,
std::span<const std::uint8_t> trace,
std::span<const std::uint8_t> actions) {
std::span<const std::uint8_t> trace,
std::span<const std::uint8_t> actions) {
std::vector<std::uint8_t> identity;
identity.reserve(previous.head.digest.size() + 16 + trace.size() + actions.size());
identity.insert(identity.end(), previous.head.digest.begin(), previous.head.digest.end());
@@ -76,9 +76,8 @@ std::optional<persistence::Uuid> commit_id(const persistence::CommittedCheckpoin
}
} // namespace
CellularRegionHost::CellularRegionHost(
CellularHostConfig config, CellularConnect connect,
std::unique_ptr<persistence::FilesystemObjectStore> objects)
CellularRegionHost::CellularRegionHost(CellularHostConfig config, CellularConnect connect,
std::unique_ptr<persistence::FilesystemObjectStore> objects)
: config_{std::move(config)}, connect_{std::move(connect)}, objects_{std::move(objects)},
authority_{config_.lease} {}
@@ -109,9 +108,8 @@ void CellularRegionHost::acquire() {
if (!database())
return;
const auto sent = LeaseClock::now();
auto lease = persistence::acquire_region_lease(*db_, config_.key, config_.build,
config_.lease.duration,
config_.lease.renew_timeout);
auto lease = persistence::acquire_region_lease(
*db_, config_.key, config_.build, config_.lease.duration, config_.lease.renew_timeout);
if (!lease) {
if (lease.error().kind == LeaseStoreError::not_provisioned ||
lease.error().kind == LeaseStoreError::unsupported) {
@@ -122,14 +120,13 @@ void CellularRegionHost::acquire() {
}
return;
}
if (lease->frame != config_.frame ||
!authority_.acquired(*lease, sent, LeaseClock::now())) {
if (lease->frame != config_.frame || !authority_.acquired(*lease, sent, LeaseClock::now())) {
status_.phase = HostPhase::quarantined;
return;
}
auto recovered = persistence::recover_cellular_checkpoint(
*db_, *objects_, config_.key, *lease, config_.retained_builds,
config_.lease.commit_timeout);
auto recovered = persistence::recover_cellular_checkpoint(*db_, *objects_, config_.key, *lease,
config_.retained_builds,
config_.lease.commit_timeout);
if (!recovered) {
if (recovered.error().kind == persistence::RecoveryError::store) {
db_.reset();
@@ -204,8 +201,8 @@ void CellularRegionHost::resolve() {
++status_.fences;
return;
}
const auto resolved = persistence::resolve_cellular_prepared(
*db_, pending_->prepared, config_.lease.commit_timeout);
const auto resolved = persistence::resolve_cellular_prepared(*db_, pending_->prepared,
config_.lease.commit_timeout);
if (!resolved) {
if (resolved.error().kind == LeaseStoreError::fenced) {
authority_.fence();
@@ -233,8 +230,8 @@ void CellularRegionHost::resolve() {
if (resolved->status == persistence::Resolution::absent &&
!authority_.may_begin_commit(LeaseClock::now()))
return;
auto retried = persistence::retry_cellular_prepared(
*db_, pending_->prepared, config_.lease.commit_timeout);
auto retried = persistence::retry_cellular_prepared(*db_, pending_->prepared,
config_.lease.commit_timeout);
if (!retried) {
if (retried.error().kind == persistence::PublicationError::unknown) {
db_.reset();
@@ -278,11 +275,10 @@ void CellularRegionHost::refresh() {
authority_.may_originate(LeaseClock::now());
status_.epoch = grant ? grant->epoch : 0;
status_.lease_remaining_ms =
status_.ready
? static_cast<std::uint64_t>(std::chrono::duration_cast<milliseconds>(
authority_.deadline() - LeaseClock::now())
.count())
: 0;
status_.ready ? static_cast<std::uint64_t>(std::chrono::duration_cast<milliseconds>(
authority_.deadline() - LeaseClock::now())
.count())
: 0;
}
const HostStatus& CellularRegionHost::step() {
@@ -301,18 +297,16 @@ const HostStatus& CellularRegionHost::step() {
std::expected<persistence::PublishedCellularBatch, CellularHostError>
CellularRegionHost::publish(const CellularBatch& batch,
std::span<const CellularActionRecord> actions) {
if (!status_.ready || !state_ || !committed_ ||
!authority_.may_begin_commit(LeaseClock::now()))
if (!status_.ready || !state_ || !committed_ || !authority_.may_begin_commit(LeaseClock::now()))
return std::unexpected{CellularHostError::not_ready};
auto candidate = replay_cellular_batch(*state_, batch);
if (!candidate)
return std::unexpected{CellularHostError::invalid_batch};
auto trace = encode_cellular_batch(batch);
auto action_block = encode_cellular_action_block(actions, batch.header.begin_tick,
batch.header.end_tick);
const auto commit = trace && action_block
? commit_id(*committed_, *trace, *action_block)
: std::nullopt;
auto action_block =
encode_cellular_action_block(actions, batch.header.begin_tick, batch.header.end_tick);
const auto commit =
trace && action_block ? commit_id(*committed_, *trace, *action_block) : std::nullopt;
if (!commit)
return std::unexpected{CellularHostError::invalid_batch};
auto published = persistence::publish_cellular_batch(
@@ -320,9 +314,10 @@ CellularRegionHost::publish(const CellularBatch& batch,
config_.build, config_.lease.commit_timeout, {}, actions);
if (!published) {
if (published.error().kind == persistence::PublicationError::unknown) {
pending_ = std::make_unique<Pending>(
Pending{published.error().prepared, std::move(*candidate),
{actions.begin(), actions.end()}, births_in(batch)});
pending_ = std::make_unique<Pending>(Pending{published.error().prepared,
std::move(*candidate),
{actions.begin(), actions.end()},
births_in(batch)});
status_.phase = HostPhase::resolving;
status_.ready = false;
++status_.unknown_outcomes;
@@ -367,22 +362,21 @@ void CellularRegionHost::finalize_births(std::span<const CellularTickIntents::Bi
});
}
network::PrimitiveLifeOutcome CellularRegionHost::query_birth(
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request,
bool enqueue) {
network::PrimitiveLifeOutcome CellularRegionHost::query_birth(const persistence::Uuid& account,
std::uint64_t generation,
std::uint64_t request, bool enqueue) {
using network::PrimitiveLifeResult;
const auto unknown = [&] {
return network::PrimitiveLifeOutcome{request, PrimitiveLifeResult::unknown, 0, 0};
};
if (!status_.ready || !authority_.may_begin_commit(LeaseClock::now()) || account ==
persistence::Uuid{} || generation == 0 || request == 0 || !database())
if (!status_.ready || !authority_.may_begin_commit(LeaseClock::now()) ||
account == persistence::Uuid{} || generation == 0 || request == 0 || !database())
return unknown();
const auto grant = authority_.grant();
if (!grant)
return unknown();
auto queried = persistence::query_primitive_life(*db_, config_.key, *grant, account,
generation, request,
config_.lease.commit_timeout);
auto queried = persistence::query_primitive_life(*db_, config_.key, *grant, account, generation,
request, config_.lease.commit_timeout);
if (!queried) {
if (queried.error().kind == persistence::LifeReservationError::unknown ||
queried.error().kind == persistence::LifeReservationError::store)
@@ -407,8 +401,9 @@ network::PrimitiveLifeOutcome CellularRegionHost::query_birth(
return {request, result, outcome.reservation.identity, 0};
}
network::PrimitiveLifeOutcome CellularRegionHost::create_primitive_life(
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request) {
network::PrimitiveLifeOutcome
CellularRegionHost::create_primitive_life(const persistence::Uuid& account,
std::uint64_t generation, std::uint64_t request) {
using network::PrimitiveLifeResult;
const auto existing = query_birth(account, generation, request, true);
if (existing.result != PrimitiveLifeResult::unknown)
@@ -419,8 +414,8 @@ network::PrimitiveLifeOutcome CellularRegionHost::create_primitive_life(
if (!grant)
return {request, PrimitiveLifeResult::unknown, 0, 0};
auto reserved = persistence::reserve_primitive_life(
*db_, config_.key, *grant, account, generation, request,
biology::founder_life_rules, config_.lease.commit_timeout);
*db_, config_.key, *grant, account, generation, request, biology::founder_life_rules,
config_.lease.commit_timeout);
if (!reserved) {
if (reserved.error().kind == persistence::LifeReservationError::unknown ||
reserved.error().kind == persistence::LifeReservationError::store)
@@ -439,8 +434,9 @@ network::PrimitiveLifeOutcome CellularRegionHost::create_primitive_life(
return {request, result, reserved->identity, 0};
}
network::PrimitiveLifeOutcome CellularRegionHost::query_primitive_life(
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request) {
network::PrimitiveLifeOutcome
CellularRegionHost::query_primitive_life(const persistence::Uuid& account, std::uint64_t generation,
std::uint64_t request) {
return query_birth(account, generation, request, true);
}
@@ -454,8 +450,8 @@ void CellularRegionHost::drain() {
pending_.reset();
const auto grant = authority_.grant();
if (grant && authority_.may_originate(LeaseClock::now()) && database())
static_cast<void>(persistence::release_region_lease(
*db_, config_.key, *grant, config_.lease.renew_timeout));
static_cast<void>(persistence::release_region_lease(*db_, config_.key, *grant,
config_.lease.renew_timeout));
authority_.fence();
state_.reset();
committed_.reset();