From: Ronen Friedman Date: Mon, 18 Sep 2023 15:11:21 +0000 (-0500) Subject: osd/scrub: move scrub_sleep_time() to OsdScrub X-Git-Tag: v19.0.0~438^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4959d4691bc756f6350cc71829bc75ec46913111;p=ceph-ci.git osd/scrub: move scrub_sleep_time() to OsdScrub also scrub_time_permit(). Signed-off-by: Ronen Friedman --- diff --git a/src/osd/scrubber/osd_scrub.cc b/src/osd/scrubber/osd_scrub.cc index 5533f3bd6c3..75aa360a260 100644 --- a/src/osd/scrubber/osd_scrub.cc +++ b/src/osd/scrubber/osd_scrub.cc @@ -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); } diff --git a/src/osd/scrubber/osd_scrub.h b/src/osd/scrubber/osd_scrub.h index 5792514ea79..586eada034b 100644 --- a/src/osd/scrubber/osd_scrub.h +++ b/src/osd/scrubber/osd_scrub.h @@ -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, diff --git a/src/osd/scrubber/osd_scrub_sched.h b/src/osd/scrubber/osd_scrub_sched.h index 6efec6fd569..16f3fd9360e 100644 --- a/src/osd/scrubber/osd_scrub_sched.h +++ b/src/osd/scrubber/osd_scrub_sched.h @@ -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. diff --git a/src/osd/scrubber/pg_scrubber.cc b/src/osd/scrubber/pg_scrubber.cc index 6a40f2bb117..22f5606d454 100644 --- a/src/osd/scrubber/pg_scrubber.cc +++ b/src/osd/scrubber/pg_scrubber.cc @@ -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)