From ebccd68b97239d9923f08745ca6112bd2c2bfbee Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Wed, 19 Jul 2023 03:55:39 -0500 Subject: [PATCH] osd/scrub: fixing & improving ReservationTimeout handler messages Note: the use of the 'fmt' namespace is required due to a bug in gcc versions pre gcc-12. Signed-off-by: Ronen Friedman --- src/common/ceph_time.h | 49 +++++++++++++++++-- .../staged-fltree/stages/stage.h | 6 ++- src/msg/Message.h | 10 +++- src/osd/scrubber/scrub_machine.cc | 15 ++---- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index 292fa91ac24b5..c7d2bb96c769c 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -19,6 +19,7 @@ #include #include #include +#include #if FMT_VERSION >= 90000 #include #endif @@ -549,9 +550,49 @@ template ostream& operator<<(ostream& m, const chrono::duration& t); } -#if FMT_VERSION >= 90000 -template -struct fmt::formatter> : fmt::ostream_formatter {}; -#endif +// concept helpers for the formatters: + +template +concept SteadyTimepoint = TimeP::clock::is_steady; + +template +concept UnsteadyTimepoint = ! TimeP::clock::is_steady; + +namespace fmt { +template +struct formatter { + constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); } + template + auto format(const T& t, FormatContext& ctx) const + { + struct tm bdt; + time_t tt = T::clock::to_time_t(t); + localtime_r(&tt, &bdt); + char tz[32] = {0}; + strftime(tz, sizeof(tz), "%z", &bdt); + + return fmt::format_to( + ctx.out(), "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}:{:06}{}", + (bdt.tm_year + 1900), (bdt.tm_mon + 1), bdt.tm_mday, bdt.tm_hour, + bdt.tm_min, bdt.tm_sec, + duration_cast( + t.time_since_epoch() % std::chrono::seconds(1)) + .count(), + tz); + } +}; + +template +struct formatter { + constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); } + template + auto format(const T& t, FormatContext& ctx) const + { + return fmt::format_to( + ctx.out(), "{}s", + std::chrono::duration(t.time_since_epoch()).count()); + } +}; +} // namespace fmt #endif // COMMON_CEPH_TIME_H diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h index 7185b15eedc40..2cf67c90cbf49 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h @@ -2480,9 +2480,13 @@ template concept HasDoFormatTo = requires(T x, std::back_insert_iterator out) { { x.do_format_to(out, true) } -> std::same_as; }; -template struct fmt::formatter : fmt::formatter { +namespace fmt { +// placed in the fmt namespace due to an ADL bug in g++ < 12 +// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92944). +template struct formatter : formatter { template auto format(const T& staged_iterator, FormatContext& ctx) { return staged_iterator.do_format_to(ctx.out(), true); } }; +} diff --git a/src/msg/Message.h b/src/msg/Message.h index 7af72a8d74ce4..94ac56c93f882 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -591,9 +591,14 @@ MURef make_message(Args&&... args) { } } +namespace fmt { +// placed in the fmt namespace due to an ADL bug in g++ < 12 +// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92944). +// Specifically - gcc pre-12 can't handle two templated specializations of +// the formatter if in two different namespaces. template M> -struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } +struct formatter { + constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); } template auto format(const M& m, FormatContext& ctx) const { std::ostringstream oss; @@ -605,5 +610,6 @@ struct fmt::formatter { } } }; +} // namespace fmt #endif diff --git a/src/osd/scrubber/scrub_machine.cc b/src/osd/scrubber/scrub_machine.cc index 23fd08fef4a2c..c3bb89b4dad2c 100644 --- a/src/osd/scrubber/scrub_machine.cc +++ b/src/osd/scrubber/scrub_machine.cc @@ -144,16 +144,11 @@ sc::result ReservingReplicas::react(const ReservationTimeout&) DECLARE_LOCALS; // 'scrbr' & 'pg_id' aliases dout(10) << "ReservingReplicas::react(const ReservationTimeout&)" << dendl; - dout(10) - << "PgScrubber: " << scrbr->get_spgid() - << " timeout on reserving replicas (since " << entered_at - << ")" << dendl; - scrbr->get_clog()->warn() - << "osd." << scrbr->get_whoami() - << " PgScrubber: " << scrbr->get_spgid() - << " timeout on reserving replicsa (since " << entered_at - << ")"; - + const auto msg = fmt::format( + "PgScrubber: {} timeout on reserving replicas (since {})", + scrbr->get_spgid(), entered_at); + dout(5) << msg << dendl; + scrbr->get_clog()->warn() << "osd." << scrbr->get_whoami() << " " << msg; scrbr->on_replica_reservation_timeout(); return discard_event(); } -- 2.47.3