]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrub: fixing & improving ReservationTimeout handler messages 52590/head
authorRonen Friedman <rfriedma@redhat.com>
Wed, 19 Jul 2023 08:55:39 +0000 (03:55 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Sat, 22 Jul 2023 12:17:38 +0000 (07:17 -0500)
Note: the use of the 'fmt' namespace is required due to a bug
in gcc versions pre gcc-12.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/ceph_time.h
src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage.h
src/msg/Message.h
src/osd/scrubber/scrub_machine.cc

index 292fa91ac24b594eb1d3f1420804c754d4fe5e66..c7d2bb96c769c5da60c8f7c16c53e2161ff1d0d9 100644 (file)
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <string>
 #include <optional>
+#include <fmt/chrono.h>
 #if FMT_VERSION >= 90000
 #include <fmt/ostream.h>
 #endif
@@ -549,9 +550,49 @@ template<typename Rep, typename Period>
 ostream& operator<<(ostream& m, const chrono::duration<Rep, Period>& t);
 }
 
-#if FMT_VERSION >= 90000
-template<typename Clock>
-struct fmt::formatter<std::chrono::time_point<Clock>> : fmt::ostream_formatter {};
-#endif
+// concept helpers for the formatters:
+
+template <typename TimeP>
+concept SteadyTimepoint = TimeP::clock::is_steady;
+
+template <typename TimeP>
+concept UnsteadyTimepoint = ! TimeP::clock::is_steady;
+
+namespace fmt {
+template <UnsteadyTimepoint T>
+struct formatter<T> {
+  constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
+  template <typename FormatContext>
+  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<std::chrono::microseconds>(
+           t.time_since_epoch() % std::chrono::seconds(1))
+           .count(),
+       tz);
+  }
+};
+
+template <SteadyTimepoint T>
+struct formatter<T> {
+  constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
+  template <typename FormatContext>
+  auto format(const T& t, FormatContext& ctx) const
+  {
+    return fmt::format_to(
+       ctx.out(), "{}s",
+       std::chrono::duration<double>(t.time_since_epoch()).count());
+  }
+};
+}  // namespace fmt
 
 #endif // COMMON_CEPH_TIME_H
index 7185b15eedc40a4a7f12df8e0627cd09d814c2ca..2cf67c90cbf49e6c877714d1073d7295cf5cf5f0 100644 (file)
@@ -2480,9 +2480,13 @@ template<typename T>
 concept HasDoFormatTo = requires(T x, std::back_insert_iterator<fmt::memory_buffer> out) {
   { x.do_format_to(out, true) } -> std::same_as<decltype(out)>;
 };
-template <HasDoFormatTo T> struct fmt::formatter<T> : fmt::formatter<std::string_view> {
+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 <HasDoFormatTo T> struct formatter<T> : formatter<std::string_view> {
   template <typename FormatContext>
   auto format(const T& staged_iterator, FormatContext& ctx) {
     return staged_iterator.do_format_to(ctx.out(), true);
   }
 };
+}
index 7af72a8d74ce4e8ff3eb94257a1c3c131496f108..94ac56c93f88215de0cf08b0b75fc1f173d170e8 100644 (file)
@@ -591,9 +591,14 @@ MURef<T> 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 <std::derived_from<Message> M>
-struct fmt::formatter<M> {
-  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+struct formatter<M> {
+  constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
   template <typename FormatContext>
   auto format(const M& m, FormatContext& ctx) const {
     std::ostringstream oss;
@@ -605,5 +610,6 @@ struct fmt::formatter<M> {
     }
   }
 };
+}  // namespace fmt
 
 #endif
index 23fd08fef4a2c8a577a5d022ec71ccb5c011e8bb..c3bb89b4dad2c6f8c0f0788d4bce9a7c2d0e0330 100644 (file)
@@ -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();
 }