]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd: formatters for PastIntervals and its subclasses
authorRonen Friedman <rfriedma@redhat.com>
Fri, 4 Aug 2023 11:48:41 +0000 (06:48 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Tue, 15 Aug 2023 12:32:46 +0000 (07:32 -0500)
Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/osd/osd_types.cc
src/osd/osd_types.h
src/osd/osd_types_fmt.h

index b30af53ecee02973e2ce9c14b347190b1f55b703..1f78e767e8f2b7169fb3cf372a6f2d820ba9a6e4 100644 (file)
@@ -3788,6 +3788,18 @@ void PastIntervals::pg_interval_t::dump(Formatter *f) const
   f->dump_int("up_primary", up_primary);
 }
 
+ostream& operator<<(ostream& out, const PastIntervals::pg_interval_t& i)
+{
+  return out << i.fmt_print();
+}
+
+std::string PastIntervals::pg_interval_t::fmt_print() const
+{
+  return fmt::format(
+      "interval({}-{} up {}({}) acting {}({}){})", first, last, up, up_primary,
+      acting, primary, maybe_went_rw ? " maybe_went_rw" : "");
+}
+
 void PastIntervals::pg_interval_t::generate_test_instances(list<pg_interval_t*>& o)
 {
   o.push_back(new pg_interval_t);
@@ -3852,14 +3864,16 @@ struct compact_interval_t {
     decode(acting, bl);
     DECODE_FINISH(bl);
   }
+  std::string fmt_print() const {
+    return fmt::format("([{},{}] acting={})", first, last, acting);
+  }
   static void generate_test_instances(list<compact_interval_t*> & o) {
     /* Not going to be used, we'll generate pi_compact_rep directly */
   }
 };
 ostream &operator<<(ostream &o, const compact_interval_t &rhs)
 {
-  return o << "([" << rhs.first << "," << rhs.last
-          << "] acting " << rhs.acting << ")";
+  return o << rhs.fmt_print();
 }
 WRITE_CLASS_ENCODER(compact_interval_t)
 
@@ -3937,6 +3951,10 @@ public:
               << "] all_participants=" << all_participants
               << " intervals=" << intervals << ")";
   }
+  std::string print() const override {
+    return fmt::format("([{},{}] all_participants={} intervals={})",
+                       first, last, all_participants, intervals);
+  }
   void encode(ceph::buffer::list &bl) const override {
     ENCODE_START(1, 1, bl);
     encode(first, bl);
@@ -4029,22 +4047,29 @@ PastIntervals &PastIntervals::operator=(const PastIntervals &rhs)
 
 ostream& operator<<(ostream& out, const PastIntervals &i)
 {
-  if (i.past_intervals) {
-    return i.past_intervals->print(out);
-  } else {
-    return out << "(empty)";
-  }
+  return out << i.fmt_print();
+}
+
+std::string PastIntervals::fmt_print() const {
+  return past_intervals ? past_intervals->print() : "(empty)";
 }
 
-ostream& operator<<(ostream& out, const PastIntervals::PriorSet &i)
+
+std::string PastIntervals::PriorSet::fmt_print() const
 {
-  return out << "PriorSet("
-            << "ec_pool: " << i.ec_pool
-            << ", probe: " << i.probe
-            << ", down: " << i.down
-            << ", blocked_by: " << i.blocked_by
-            << ", pg_down: " << i.pg_down
-            << ")";
+  return fmt::format(
+      "PriorSet("
+      "ec_pool: {}, "
+      "probe: {}, "
+      "down: {}, "
+      "blocked_by: {}, "
+      "pg_down: {})",
+      ec_pool, probe, down, blocked_by, pg_down);
+}
+
+ostream& operator<<(ostream& out, const PastIntervals::PriorSet &pset)
+{
+  return out << pset.fmt_print();
 }
 
 void PastIntervals::decode(ceph::buffer::list::const_iterator &bl)
@@ -4390,19 +4415,6 @@ bool PastIntervals::PriorSet::affected_by_map(
   return false;
 }
 
-ostream& operator<<(ostream& out, const PastIntervals::pg_interval_t& i)
-{
-  out << "interval(" << i.first << "-" << i.last
-      << " up " << i.up << "(" << i.up_primary << ")"
-      << " acting " << i.acting << "(" << i.primary << ")";
-  if (i.maybe_went_rw)
-    out << " maybe_went_rw";
-  out << ")";
-  return out;
-}
-
-
-
 // -- pg_query_t --
 
 void pg_query_t::encode(ceph::buffer::list &bl, uint64_t features) const {
index a3417ff1d11097a553d9011e9f4648a5ecdac3f3..8f99cdfbdf6aecc189fc320f05383bb944e42b82 100644 (file)
@@ -3231,6 +3231,7 @@ public:
     void encode(ceph::buffer::list& bl) const;
     void decode(ceph::buffer::list::const_iterator& bl);
     void dump(ceph::Formatter *f) const;
+    std::string fmt_print() const;
     static void generate_test_instances(std::list<pg_interval_t*>& o);
   };
 
@@ -3255,6 +3256,7 @@ public:
     virtual void encode(ceph::buffer::list &bl) const = 0;
     virtual void decode(ceph::buffer::list::const_iterator &bl) = 0;
     virtual void dump(ceph::Formatter *f) const = 0;
+    virtual std::string print() const = 0;
     virtual void iterate_mayberw_back_to(
       epoch_t les,
       std::function<void(epoch_t, const std::set<pg_shard_t> &)> &&f) const = 0;
@@ -3300,6 +3302,9 @@ public:
     ceph_assert(past_intervals);
     past_intervals->dump(f);
   }
+
+  std::string fmt_print() const;
+
   static void generate_test_instances(std::list<PastIntervals *> & o);
 
   /**
@@ -3509,6 +3514,8 @@ public:
       const OSDMap &osdmap,
       const DoutPrefixProvider *dpp) const;
 
+    std::string fmt_print() const;
+
     // For verifying tests
     PriorSet(
       bool ec_pool,
index 246626c9983e485e2965ff73682e219a149e1fdf..729baf01a57f61709b3ecba0026a6d29cf2ece33 100644 (file)
@@ -329,7 +329,6 @@ struct fmt::formatter<ScrubMap> {
 };
 
 #if FMT_VERSION >= 90000
-template <> struct fmt::formatter<PastIntervals> : fmt::ostream_formatter {};
 template <> struct fmt::formatter<pg_log_op_return_item_t> : fmt::ostream_formatter {};
 template <> struct fmt::formatter<watch_info_t> : fmt::ostream_formatter {};
 template <bool TrackChanges> struct fmt::formatter<pg_missing_set<TrackChanges>> : fmt::ostream_formatter {};