From: Ronen Friedman Date: Wed, 25 Mar 2026 15:31:38 +0000 (+0000) Subject: osd/scrub: extract stats update code from scrub_finish() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fd60474cfbd3cfd21af145218e233150210089fc;p=ceph.git osd/scrub: extract stats update code from scrub_finish() on the way to adopting Crimson pg_scrubber's way of handling stats verification & update. Signed-off-by: Ronen Friedman --- diff --git a/src/osd/scrubber/pg_scrubber.cc b/src/osd/scrubber/pg_scrubber.cc index 0b5898d07d3d..be89d60b4ab3 100644 --- a/src/osd/scrubber/pg_scrubber.cc +++ b/src/osd/scrubber/pg_scrubber.cc @@ -1028,7 +1028,7 @@ std::optional PgScrubber::select_range() if (objects.empty()) { ceph_assert(0 == "Somehow we got more than 2 objects which" - "have the same head but are not clones"); + " have the same head but are not clones"); } back = objects.back(); } @@ -2048,65 +2048,7 @@ void PgScrubber::scrub_finish() } } - { - // finish up - ObjectStore::Transaction t; - m_pg->recovery_state.update_stats( - [this](auto& history, auto& stats) { - dout(10) << "m_pg->recovery_state.update_stats() errors:" - << m_shallow_errors << "/" << m_deep_errors << " deep? " - << m_is_deep << dendl; - utime_t now = ceph_clock_now(); - history.last_scrub = m_pg->recovery_state.get_info().last_update; - history.last_scrub_stamp = now; - if (m_is_deep) { - history.last_deep_scrub = m_pg->recovery_state.get_info().last_update; - history.last_deep_scrub_stamp = now; - } - - if (m_is_deep) { - if ((m_shallow_errors == 0) && (m_deep_errors == 0)) { - history.last_clean_scrub_stamp = now; - } - stats.stats.sum.num_shallow_scrub_errors = m_shallow_errors; - stats.stats.sum.num_deep_scrub_errors = m_deep_errors; - auto omap_stats = m_be->this_scrub_omapstats(); - stats.stats.sum.num_large_omap_objects = - omap_stats.large_omap_objects; - stats.stats.sum.num_omap_bytes = omap_stats.omap_bytes; - stats.stats.sum.num_omap_keys = omap_stats.omap_keys; - dout(19) << "scrub_finish shard " << m_pg_whoami - << " num_omap_bytes = " << stats.stats.sum.num_omap_bytes - << " num_omap_keys = " << stats.stats.sum.num_omap_keys - << dendl; - } else { - stats.stats.sum.num_shallow_scrub_errors = m_shallow_errors; - // XXX: last_clean_scrub_stamp doesn't mean the pg is not inconsistent - // because of deep-scrub errors - if (m_shallow_errors == 0) { - history.last_clean_scrub_stamp = now; - } - } - - stats.stats.sum.num_scrub_errors = - stats.stats.sum.num_shallow_scrub_errors + - stats.stats.sum.num_deep_scrub_errors; - - if (m_flags.check_repair) { - m_flags.check_repair = false; - if (m_pg->info.stats.stats.sum.num_scrub_errors) { - state_set(PG_STATE_FAILED_REPAIR); - dout(10) << "scrub_finish " - << m_pg->info.stats.stats.sum.num_scrub_errors - << " error(s) still present after re-scrub" << dendl; - } - } - return true; - }, - &t); - int tr = m_osds->store->queue_transaction(m_pg->ch, std::move(t), nullptr); - ceph_assert(tr == 0); - } + emit_scrub_result(); if (has_error) { m_pg->queue_peering_event(PGPeeringEventRef( @@ -2132,6 +2074,66 @@ void PgScrubber::scrub_finish() } } +void +PgScrubber::emit_scrub_result() +{ + ObjectStore::Transaction t; + m_pg->recovery_state.update_stats( + [this](auto& history, auto& stats) { + dout(10) << "m_pg->recovery_state.update_stats() errors:" + << m_shallow_errors << "/" << m_deep_errors << " deep? " + << m_is_deep << dendl; + utime_t now = ceph_clock_now(); + history.last_scrub = m_pg->recovery_state.get_info().last_update; + history.last_scrub_stamp = now; + if (m_is_deep) { + history.last_deep_scrub = m_pg->recovery_state.get_info().last_update; + history.last_deep_scrub_stamp = now; + } + + if (m_is_deep) { + if ((m_shallow_errors == 0) && (m_deep_errors == 0)) { + history.last_clean_scrub_stamp = now; + } + stats.stats.sum.num_shallow_scrub_errors = m_shallow_errors; + stats.stats.sum.num_deep_scrub_errors = m_deep_errors; + auto omap_stats = m_be->this_scrub_omapstats(); + stats.stats.sum.num_large_omap_objects = omap_stats.large_omap_objects; + stats.stats.sum.num_omap_bytes = omap_stats.omap_bytes; + stats.stats.sum.num_omap_keys = omap_stats.omap_keys; + dout(19) << "scrub_finish shard " << m_pg_whoami + << " num_omap_bytes = " << stats.stats.sum.num_omap_bytes + << " num_omap_keys = " << stats.stats.sum.num_omap_keys + << dendl; + } else { + stats.stats.sum.num_shallow_scrub_errors = m_shallow_errors; + // XXX: last_clean_scrub_stamp doesn't mean the pg is not inconsistent + // because of deep-scrub errors + if (m_shallow_errors == 0) { + history.last_clean_scrub_stamp = now; + } + } + + stats.stats.sum.num_scrub_errors = + stats.stats.sum.num_shallow_scrub_errors + + stats.stats.sum.num_deep_scrub_errors; + + if (m_flags.check_repair) { + m_flags.check_repair = false; + if (m_pg->info.stats.stats.sum.num_scrub_errors) { + state_set(PG_STATE_FAILED_REPAIR); + dout(10) << "scrub_finish " + << m_pg->info.stats.stats.sum.num_scrub_errors + << " error(s) still present after re-scrub" << dendl; + } + } + return true; + }, + &t); + int tr = m_osds->store->queue_transaction(m_pg->ch, std::move(t), nullptr); + ceph_assert(tr == 0); +} + void PgScrubber::on_digest_updates() { diff --git a/src/osd/scrubber/pg_scrubber.h b/src/osd/scrubber/pg_scrubber.h index abf0a726ee4f..9ee7d69e4c71 100644 --- a/src/osd/scrubber/pg_scrubber.h +++ b/src/osd/scrubber/pg_scrubber.h @@ -755,6 +755,11 @@ class PgScrubber : public ScrubPgIF, */ virtual void _scrub_finish() {} + /** + * update the PG's state and stats + */ + void emit_scrub_result(); + // common code used by build_primary_map_chunk() and // build_replica_map_chunk(): int build_scrub_map_chunk(ScrubMap& map, // primary or replica?