diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index e40ed05..400ff0f 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -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. diff --git a/src/server/primitive_region_host.cpp b/src/server/primitive_region_host.cpp index e821d22..20d51ee 100644 --- a/src/server/primitive_region_host.cpp +++ b/src/server/primitive_region_host.cpp @@ -28,7 +28,7 @@ bool valid(const PrimitiveHostConfig& c) { } PrimitiveHostReply reply(PrimitiveHostReplyKind kind, persistence::LifeReservation reservation, std::optional 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 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((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();