From 1770b177fc15209958644fb671799aedc374305a Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Tue, 15 Oct 2024 06:38:06 -0500 Subject: [PATCH] osd/scrub: improve scrub information conveyed in standard PG log line references When "mentioning" a PG in a log message, we include a set of data items, including some scrub related information. This commit improves the scrubber information conveyed, following changes to the scrub scheduler. Signed-off-by: Ronen Friedman --- src/osd/scrubber/pg_scrubber.cc | 50 +++++++++++++++++++++++++++++++-- src/osd/scrubber/pg_scrubber.h | 10 +++++-- src/osd/scrubber_common.h | 7 ++--- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/osd/scrubber/pg_scrubber.cc b/src/osd/scrubber/pg_scrubber.cc index 594ffb15e2b..c37f31d28dc 100644 --- a/src/osd/scrubber/pg_scrubber.cc +++ b/src/osd/scrubber/pg_scrubber.cc @@ -2687,9 +2687,53 @@ void PgScrubber::log_cluster_warning(const std::string& warning) const m_osds->clog->do_log(CLOG_WARN, warning); } -ostream& PgScrubber::show(ostream& out) const -{ - return out << " [ " << m_pg_id << ": " << m_flags << " ] "; + +ostream& PgScrubber::show_concise(ostream& out) const +{ + /* + * 'show_concise()' is only used when calling operator<< thru the ScrubPgIF, + * i.e. only by the PG when creating a standard log entry. + * + * desired outcome (only relevant for Primaries): + * + * if scrubbing: + * (urgency,flags) + * or (if blocked) + * (*blocked*,urgency,flags) + * + * if not scrubbing: + * either nothing (if only periodic scrubs are scheduled) + * or [next-scrub: effective-lvl, urgency] + */ + if (!is_primary()) { + return out; + } + + if (m_active) { + const auto flags_txt = fmt::format("{}", m_flags); + const std::string sep = (flags_txt.empty() ? "" : ","); + if (m_active_target) { + return out << fmt::format( + "({}{}{}{})", (m_scrub_job->blocked ? "*blocked*," : ""), + m_active_target->urgency(), sep, flags_txt); + } else { + // only expected in a couple of messages during scrub termination + return out << fmt::format( + "(teardown{}{}{})", (m_scrub_job->blocked ? "-*blocked*" : ""), + sep, flags_txt); + } + } + + // not actively scrubbing now. Show some info about the next scrub + const auto now_is = ceph_clock_now(); + const auto& next_scrub = m_scrub_job->earliest_target(now_is); + if (!next_scrub.is_high_priority()) { + // no interesting flags to report + return out; + } + return out << fmt::format( + "[next-scrub:{},{:10.10}]", (next_scrub.is_deep() ? "dp" : "sh"), + next_scrub.urgency()); } int PgScrubber::asok_debug(std::string_view cmd, diff --git a/src/osd/scrubber/pg_scrubber.h b/src/osd/scrubber/pg_scrubber.h index 1a5813bd923..3d7e16cd359 100644 --- a/src/osd/scrubber/pg_scrubber.h +++ b/src/osd/scrubber/pg_scrubber.h @@ -164,7 +164,7 @@ template <> struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template - auto format(scrub_flags_t& sf, FormatContext& ctx) const + auto format(const scrub_flags_t& sf, FormatContext& ctx) const { std::string txt; bool sep{false}; @@ -528,7 +528,7 @@ class PgScrubber : public ScrubPgIF, /// to complete (in order to perform an 'after-repair' scrub) bool m_after_repair_scrub_required{false}; - ostream& show(ostream& out) const override; + ostream& show_concise(ostream& out) const override; public: // ------------------ the I/F used by the ScrubBackend (ScrubBeListener) @@ -741,6 +741,12 @@ class PgScrubber : public ScrubPgIF, bool m_publish_sessions{false}; //< will the counter be part of 'query' //output? + /** + * the scrub operation flags. + * Set at scrub start. Checked in multiple locations - mostly + * at finish. + * Note: replicas only use the 'priority' field. + */ scrub_flags_t m_flags; bool m_active{false}; diff --git a/src/osd/scrubber_common.h b/src/osd/scrubber_common.h index d1a0fbdccb5..e3a076570b1 100644 --- a/src/osd/scrubber_common.h +++ b/src/osd/scrubber_common.h @@ -299,12 +299,11 @@ struct ScrubPgIF { virtual ~ScrubPgIF() = default; - friend std::ostream& operator<<(std::ostream& out, const ScrubPgIF& s) - { - return s.show(out); + friend std::ostream& operator<<(std::ostream& out, const ScrubPgIF& s) { + return s.show_concise(out); } - virtual std::ostream& show(std::ostream& out) const = 0; + virtual std::ostream& show_concise(std::ostream& out) const = 0; // --------------- triggering state-machine events: -- 2.39.5