]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/scrub: move scrub_sleep_time() to OsdScrub
authorRonen Friedman <rfriedma@redhat.com>
Mon, 18 Sep 2023 15:11:21 +0000 (10:11 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 20 Sep 2023 06:39:10 +0000 (01:39 -0500)
also scrub_time_permit().

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

index 5533f3bd6c3dd2697b5209ce793a9246ef1900eb..75aa360a260a26108cfd968f198a7b22c21a3a0d 100644 (file)
@@ -483,55 +483,53 @@ static inline bool isbetween_modulo(int64_t from, int64_t till, int p)
 
 bool OsdScrub::scrub_time_permit(utime_t now) const
 {
-  return m_queue.scrub_time_permit(now);
-}
-
-bool ScrubQueue::scrub_time_permit(utime_t now) const
-{
+  const time_t tt = now.sec();
   tm bdt;
-  time_t tt = now.sec();
   localtime_r(&tt, &bdt);
 
-  bool day_permit = isbetween_modulo(conf()->osd_scrub_begin_week_day,
-                                    conf()->osd_scrub_end_week_day,
-                                    bdt.tm_wday);
-  if (!day_permit) {
-    dout(20) << "should run between week day "
-            << conf()->osd_scrub_begin_week_day << " - "
-            << conf()->osd_scrub_end_week_day << " now " << bdt.tm_wday
-            << " - no" << dendl;
+  bool day_permits = isbetween_modulo(
+      conf->osd_scrub_begin_week_day, conf->osd_scrub_end_week_day,
+      bdt.tm_wday);
+  if (!day_permits) {
+    dout(20) << fmt::format(
+                   "should run between week day {} - {} now {} - no",
+                   conf->osd_scrub_begin_week_day,
+                   conf->osd_scrub_end_week_day, bdt.tm_wday)
+            << dendl;
     return false;
   }
 
-  bool time_permit = isbetween_modulo(conf()->osd_scrub_begin_hour,
-                                     conf()->osd_scrub_end_hour,
-                                     bdt.tm_hour);
-  dout(20) << "should run between " << conf()->osd_scrub_begin_hour << " - "
-          << conf()->osd_scrub_end_hour << " now (" << bdt.tm_hour
-          << ") = " << (time_permit ? "yes" : "no") << dendl;
-  return time_permit;
+  bool time_permits = isbetween_modulo(
+      conf->osd_scrub_begin_hour, conf->osd_scrub_end_hour, bdt.tm_hour);
+  dout(20) << fmt::format(
+                 "{}: should run between {} - {} now {} = {}", __func__,
+                 conf->osd_scrub_begin_hour, conf->osd_scrub_end_hour,
+                 bdt.tm_hour, (time_permits ? "yes" : "no"))
+          << dendl;
+  return time_permits;
 }
 
-std::chrono::milliseconds OsdScrub::scrub_sleep_time(bool must_scrub) const
-{
-  return m_queue.scrub_sleep_time(must_scrub);
-}
 
-std::chrono::milliseconds ScrubQueue::scrub_sleep_time(bool must_scrub) const
+std::chrono::milliseconds OsdScrub::scrub_sleep_time(
+    utime_t t,
+    bool high_priority_scrub) const
 {
-  std::chrono::milliseconds regular_sleep_period{
-    uint64_t(std::max(0.0, conf()->osd_scrub_sleep) * 1000)};
+  const milliseconds regular_sleep_period =
+      milliseconds{int64_t(std::max(0.0, 1'000 * conf->osd_scrub_sleep))};
 
-  if (must_scrub || scrub_time_permit(time_now())) {
+  if (high_priority_scrub || scrub_time_permit(t)) {
     return regular_sleep_period;
   }
 
   // relevant if scrubbing started during allowed time, but continued into
   // forbidden hours
-  std::chrono::milliseconds extended_sleep{
-    uint64_t(std::max(0.0, conf()->osd_scrub_extended_sleep) * 1000)};
-  dout(20) << "w/ extended sleep (" << extended_sleep << ")" << dendl;
-
+  const milliseconds extended_sleep =
+      milliseconds{int64_t(1'000 * conf->osd_scrub_extended_sleep)};
+  dout(20) << fmt::format(
+                 "scrubbing started during allowed time, but continued into "
+                 "forbidden hours. regular_sleep_period {} extended_sleep {}",
+                 regular_sleep_period, extended_sleep)
+          << dendl;
   return std::max(extended_sleep, regular_sleep_period);
 }
 
index 5792514ea7900f081a294a5e7579f9cc1041bd06..586eada034b9743d27270075bab70a9b5c168097 100644 (file)
@@ -125,7 +125,9 @@ class OsdScrub {
    * osd_scrub_extended_sleep, depending on must_scrub_param and time
    * of day (see configs osd_scrub_begin*)
    */
-  std::chrono::milliseconds scrub_sleep_time(bool high_priority_scrub) const;
+  std::chrono::milliseconds scrub_sleep_time(
+      utime_t t,
+      bool high_priority_scrub) const;
 
   /**
    * No new scrub session will start while a scrub was initiated on a PG,
index 6efec6fd5696fb9b20e785ebfede85df451a7683..16f3fd9360ea53a02772c6b2b3cd1d88179ee930 100644 (file)
@@ -282,18 +282,6 @@ class ScrubQueue {
   void clear_pg_scrub_blocked(spg_t blocked_pg);
   int get_blocked_pgs_count() const;
 
-  /**
-   * scrub_sleep_time
-   *
-   * Returns std::chrono::milliseconds indicating how long to wait between
-   * chunks.
-   *
-   * Implementation Note: Returned value will either osd_scrub_sleep or
-   * osd_scrub_extended_sleep depending on must_scrub_param and time
-   * of day (see configs osd_scrub_begin*)
-   */
-  std::chrono::milliseconds scrub_sleep_time(bool must_scrub) const;
-
  private:
   CephContext* cct;
   Scrub::ScrubSchedListener& osd_service;
@@ -365,8 +353,6 @@ class ScrubQueue {
 
   std::atomic_bool a_pg_is_reserving{false};
 
-  [[nodiscard]] bool scrub_time_permit(utime_t now) const;
-
   /**
    * If the scrub job was not explicitly requested, we postpone it by some
    * random length of time.
index 6a40f2bb1179c926c25c47e4020cf6f631425dc8..22f5606d454b991e0d5058d79644d5a2f8d89a89 100644 (file)
@@ -2264,7 +2264,7 @@ void PgScrubber::replica_handling_done()
 std::chrono::milliseconds PgScrubber::get_scrub_sleep_time() const
 {
   return m_osds->get_scrub_services().scrub_sleep_time(
-    m_flags.required);
+    ceph_clock_now(), m_flags.required);
 }
 
 void PgScrubber::queue_for_scrub_resched(Scrub::scrub_prio_t prio)