From 4f5356d062bb62b4216245104b4e300aa41301ba Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Fri, 4 Aug 2023 06:48:41 -0500 Subject: [PATCH] osd: formatters for PastIntervals and its subclasses Signed-off-by: Ronen Friedman --- src/osd/osd_types.cc | 68 ++++++++++++++++++++++++----------------- src/osd/osd_types.h | 7 +++++ src/osd/osd_types_fmt.h | 1 - 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index b30af53ecee..1f78e767e8f 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -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& 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 & 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 { diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index a3417ff1d11..8f99cdfbdf6 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -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& 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 &)> &&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 & 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, diff --git a/src/osd/osd_types_fmt.h b/src/osd/osd_types_fmt.h index 246626c9983..729baf01a57 100644 --- a/src/osd/osd_types_fmt.h +++ b/src/osd/osd_types_fmt.h @@ -329,7 +329,6 @@ struct fmt::formatter { }; #if FMT_VERSION >= 90000 -template <> struct fmt::formatter : fmt::ostream_formatter {}; template <> struct fmt::formatter : fmt::ostream_formatter {}; template <> struct fmt::formatter : fmt::ostream_formatter {}; template struct fmt::formatter> : fmt::ostream_formatter {}; -- 2.39.5