Fix primitive host clang-tidy findings
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (client) (push) Successful in 12m16s
Foundation / checks (network) (push) Successful in 13m43s
Foundation / checks (tsan) (push) Successful in 8m11s
Foundation / checks (postgres) (push) Failing after 20m58s
Foundation / checks (checks) (push) Successful in 33m53s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-10 15:53:21 -04:00
parent 67f3545d5b
commit be1177cc03
2 changed files with 43 additions and 21 deletions
+8
View File
@@ -5698,3 +5698,11 @@ the `performance-move-const-arg` clang-tidy warning on the v17 outcome adapter.
Both were corrected. clang-format 19.1.5 dry-run and clang-tidy 19.1.5 on
`region_lease_store.cpp` pass locally. Awaiting CI rerun for the database,
migration, host test and repository checks; no local runtime pass is claimed.
The subsequent CI build found one more `performance-move-const-arg` and eight
`bugprone-unchecked-optional-access` errors in `primitive_region_host.cpp`.
Removed the ineffective move and made lease grants and nested optional values
explicitly checked before access. clang-format 19.1.5 dry-run, clang-tidy 19.1.5
with warnings-as-errors, GCC 13.2 Release/NDEBUG compilation with warnings-as-
errors, and `git diff --check` pass locally. PostgreSQL integration remains
unavailable in this Windows environment; awaiting CI rerun.
+35 -21
View File
@@ -28,7 +28,7 @@ bool valid(const PrimitiveHostConfig& c) {
}
PrimitiveHostReply reply(PrimitiveHostReplyKind kind, persistence::LifeReservation reservation,
std::optional<persistence::PrimitiveLifeBinding> published = {}) {
return {kind, reservation, std::move(published)};
return {kind, reservation, published};
}
} // namespace
@@ -108,7 +108,15 @@ void PrimitiveRegionHost::acquire() {
state_ = std::move(recovered->state);
committed_ = std::move(recovered->committed);
pending_.reset();
status_.epoch = authority_.grant()->epoch;
const auto grant = authority_.grant();
if (!grant) {
authority_.fence();
status_.phase = HostPhase::quarantined;
state_.reset();
committed_.reset();
return;
}
status_.epoch = grant->epoch;
status_.committed_tick = committed_->head.end_tick;
status_.simulated_tick = committed_->head.end_tick;
status_.committed_sequence = committed_->head.sequence;
@@ -220,11 +228,13 @@ std::optional<persistence::LeaseGrant> PrimitiveRegionHost::authority() const {
PrimitiveHostReply PrimitiveRegionHost::query(const persistence::Uuid& account,
std::uint64_t generation, std::uint64_t request) {
if (!database() || !authority_.grant())
if (!database())
return reply(PrimitiveHostReplyKind::unavailable, {});
auto outcome =
persistence::query_primitive_life(*db_, config_.key, *authority_.grant(), account,
generation, request, config_.lease.commit_timeout);
const auto grant = authority_.grant();
if (!grant)
return reply(PrimitiveHostReplyKind::unavailable, {});
auto outcome = persistence::query_primitive_life(*db_, config_.key, *grant, account, generation,
request, config_.lease.commit_timeout);
if (!outcome) {
if (outcome.error().kind == persistence::LifeReservationError::unknown ||
outcome.error().kind == persistence::LifeReservationError::store)
@@ -233,9 +243,10 @@ PrimitiveHostReply PrimitiveRegionHost::query(const persistence::Uuid& account,
status_.ready = false;
return reply(PrimitiveHostReplyKind::unknown, {});
}
if (!*outcome)
const auto& maybe_value = outcome.value();
if (!maybe_value.has_value())
return reply(PrimitiveHostReplyKind::unknown, {});
const auto& value = **outcome;
const auto& value = maybe_value.value();
if (value.published)
return reply(PrimitiveHostReplyKind::born, value.reservation, value.published);
if (value.reservation.region != config_.key.region)
@@ -250,6 +261,9 @@ PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& accoun
std::uint32_t rules) {
if (!status_.ready || !state_ || !committed_ || !authority_.may_begin_commit(LeaseClock::now()))
return reply(PrimitiveHostReplyKind::unavailable, {});
const auto grant = authority_.grant();
if (!grant)
return reply(PrimitiveHostReplyKind::unavailable, {});
if (account == persistence::Uuid{} || generation == 0 || request == 0 || rules == 0)
return reply(PrimitiveHostReplyKind::refused, {});
if (pending_) {
@@ -262,15 +276,15 @@ PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& accoun
return reply(PrimitiveHostReplyKind::unknown, pending_->reservation);
}
persistence::PrimitivePreparedCommit prepared;
if (pending_->prepared) {
prepared = *pending_->prepared;
const auto prepared_value = pending_->prepared;
if (prepared_value.has_value()) {
prepared = prepared_value.value();
} else {
// Re-entering the adapter with the same predecessor, trace and commit recreates
// the exact canonical bytes when the earlier failure happened before SQL.
auto published = persistence::publish_primitive_batch(
*db_, *objects_, *authority_.grant(), *committed_, pending_->batch,
*pending_->candidate, pending_->commit, config_.build,
config_.lease.commit_timeout);
*db_, *objects_, *grant, *committed_, pending_->batch, *pending_->candidate,
pending_->commit, config_.build, config_.lease.commit_timeout);
if (published) {
state_ = std::move(pending_->candidate);
committed_ = published->committed;
@@ -340,9 +354,9 @@ PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& accoun
if (existing.kind != PrimitiveHostReplyKind::unknown &&
existing.kind != PrimitiveHostReplyKind::pending)
return existing;
auto reserved = persistence::reserve_primitive_life(*db_, config_.key, *authority_.grant(),
account, generation, request, rules,
config_.lease.commit_timeout);
auto reserved =
persistence::reserve_primitive_life(*db_, config_.key, *grant, account, generation, request,
rules, config_.lease.commit_timeout);
if (!reserved) {
if (reserved.error().kind == persistence::LifeReservationError::unknown) {
db_.reset();
@@ -362,9 +376,9 @@ PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& accoun
if (reserved->refusal != persistence::LifeRefusal::none)
return reply(PrimitiveHostReplyKind::refused, *reserved);
const auto refuse = [&](persistence::LifeRefusal reason) {
const auto recorded = persistence::reject_primitive_life(
*db_, config_.key, *authority_.grant(), account, generation, request, reason,
config_.lease.commit_timeout);
const auto recorded =
persistence::reject_primitive_life(*db_, config_.key, *grant, account, generation,
request, reason, config_.lease.commit_timeout);
if (!recorded) {
if (recorded.error().kind == persistence::LifeReservationError::unknown)
db_.reset();
@@ -428,7 +442,7 @@ PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& accoun
authority_.fence();
return reply(PrimitiveHostReplyKind::unavailable, *reserved);
}
auto commit = authority_.grant()->holder;
auto commit = grant->holder;
const auto sequence = committed_->head.sequence + 1;
for (unsigned i = 0; i < 8; ++i)
commit[8 + i] = static_cast<std::uint8_t>((sequence >> (i * 8U)) & 0xffU);
@@ -441,7 +455,7 @@ PrimitiveHostReply PrimitiveRegionHost::new_life(const persistence::Uuid& accoun
commit,
{}});
auto published = persistence::publish_primitive_batch(
*db_, *objects_, *authority_.grant(), *committed_, pending_->batch, *pending_->candidate,
*db_, *objects_, *grant, *committed_, pending_->batch, *pending_->candidate,
pending_->commit, config_.build, config_.lease.commit_timeout);
if (!published) {
const auto& failure = published.error();