]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrub: expose a "scrub sessions" counter for test use
authorRonen Friedman <rfriedma@redhat.com>
Sun, 14 Nov 2021 08:34:33 +0000 (08:34 +0000)
committerRonen Friedman <rfriedma@redhat.com>
Tue, 23 Nov 2021 13:55:21 +0000 (13:55 +0000)
Add an opaque but ever-increasing counter that is incremented whenever
a scrub starts and whenever it completes. Expose the counter via
'pq query'.

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

index 83d1df5975498768e2ef232925598a90f49fcccc..8af7811178961f567c7400063ccf948604087cb2 100644 (file)
@@ -4147,7 +4147,7 @@ void OSD::final_init()
   r = admin_socket->register_command(
     "scrubdebug "                                              \
     "name=pgid,type=CephPgid "                                 \
-    "name=cmd,type=CephChoices,strings=block|unblock "          \
+    "name=cmd,type=CephChoices,strings=block|unblock|set|unset " \
     "name=value,type=CephString,req=false",
     asok_hook,
     "debug the scrubber");
index 3023b6376f1979f036b898869ba435df131e0729..b4b8f00ba8b1cb08c1c3bf34b295c62782e83703 100644 (file)
@@ -1189,7 +1189,8 @@ void PrimaryLogPG::do_command(
     outbl.append(ss.str());
   }
 
-  else if (prefix == "block" || prefix == "unblock") {
+  else if (prefix == "block" || prefix == "unblock" || prefix == "set" ||
+           prefix == "unset") {
     string value;
     cmd_getval(cmdmap, "value", value);
 
index fb58633a679a27999e4fc8d8b9f28cb95f47016a..fd3dc97fdea6351de95ad7bfc37d7ff9321e00b9 100644 (file)
@@ -968,12 +968,14 @@ void PgScrubber::on_init()
 
   m_start = m_pg->info.pgid.pgid.get_hobj_start();
   m_active = true;
+  ++m_sessions_counter;
   m_pg->publish_stats_to_osd();
 }
 
 void PgScrubber::on_replica_init()
 {
   m_active = true;
+  ++m_sessions_counter;
 }
 
 void PgScrubber::_scan_snaps(ScrubMap& smap)
@@ -1975,6 +1977,11 @@ void PgScrubber::dump_scrubber(ceph::Formatter* f,
     f->dump_string("schedule", sched_state);
   }
 
+  if (m_publish_sessions) {
+    f->dump_int("test_sequence",
+                m_sessions_counter);  // an ever-increasing number used by tests
+  }
+
   f->close_section();
 }
 
@@ -2241,6 +2248,7 @@ void PgScrubber::reset_internal_state()
 
   m_active = false;
   clear_queued_or_active();
+  ++m_sessions_counter;
 }
 
 // note that only applicable to the Replica:
@@ -2302,11 +2310,30 @@ int PgScrubber::asok_debug(std::string_view cmd,
   if (cmd == "block") {
     // set a flag that will cause the next 'select_range' to report a blocked object
     m_debug_blockrange = 1;
+
   } else if (cmd == "unblock") {
     // send an 'unblock' event, as if a blocked range was freed
     m_debug_blockrange = 0;
     m_fsm->process_event(Unblocked{});
+
+  } else if ((cmd == "set") || (cmd == "unset")) {
+
+    if (param == "sessions") {
+      // set/reset the inclusion of the scrub sessions counter in 'query' output
+      m_publish_sessions = (cmd == "set");
+
+    } else if (param == "block") {
+      if (cmd == "set") {
+        // set a flag that will cause the next 'select_range' to report a blocked object
+        m_debug_blockrange = 1;
+      } else {
+      // send an 'unblock' event, as if a blocked range was freed
+        m_debug_blockrange = 0;
+        m_fsm->process_event(Unblocked{});
+      }
+    }
   }
+
   return 0;
 }
 // ///////////////////// preemption_data_t //////////////////////////////////
index 1835310298f275bcd83b10c31f6d2f5e53ad7214..f32fb23191cd3e596ad1b7eceaa7d6d2ea1dae37 100644 (file)
@@ -86,7 +86,7 @@ class LocalReservation {
   bool m_holding_local_reservation{false};
 
  public:
-  LocalReservation(OSDService* osds);
+  explicit LocalReservation(OSDService* osds);
   ~LocalReservation();
   bool is_reserved() const { return m_holding_local_reservation; }
 };
@@ -613,6 +613,17 @@ class PgScrubber : public ScrubPgIF, public ScrubMachineListener {
    */
   Scrub::act_token_t m_current_token{1};
 
+  /**
+   *  (primary/replica) a test aid. A counter that is incremented whenever a scrub starts,
+   *  and again when it terminates. Exposed as part of the 'pg query' command, to be used
+   *  by test scripts.
+   *
+   *  @ATTN: not guaranteed to be accurate. To be only used for tests. This is why it
+   *  is initialized to a meaningless number;
+   */
+  int32_t m_sessions_counter{(int32_t)((int64_t)(this) & 0x0000'0000'00ff'fff0)};
+  bool m_publish_sessions{false}; //< will the counter be part of 'query' output?
+
   scrub_flags_t m_flags;
 
   bool m_active{false};