]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrub: extract stats update code from scrub_finish()
authorRonen Friedman <rfriedma@redhat.com>
Wed, 25 Mar 2026 15:31:38 +0000 (15:31 +0000)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 25 Mar 2026 17:43:16 +0000 (17:43 +0000)
on the way to adopting Crimson pg_scrubber's way
of handling stats verification & update.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/osd/scrubber/pg_scrubber.cc
src/osd/scrubber/pg_scrubber.h

index 0b5898d07d3dc2543877d8f7e8f02e7b7af88962..be89d60b4ab3f4552168094e0244b954839820c6 100644 (file)
@@ -1028,7 +1028,7 @@ std::optional<uint64_t> 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()
 {
index abf0a726ee4f8c37ea126dc2964c01e30f339cfb..9ee7d69e4c7161fc8b71cc51a53e8ded38514ed8 100644 (file)
@@ -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?