From: Samuel Just Date: Wed, 3 Apr 2019 23:58:15 +0000 (-0700) Subject: osd/: move ostream<< and dump logic into PeeringState X-Git-Tag: v15.1.0~2774^2~29 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2e06118f4936c8cd6495e77da0576f03cfc251d5;p=ceph-ci.git osd/: move ostream<< and dump logic into PeeringState Signed-off-by: Samuel Just --- diff --git a/src/osd/MissingLoc.h b/src/osd/MissingLoc.h index 4ebc5520c76..73d45b505fd 100644 --- a/src/osd/MissingLoc.h +++ b/src/osd/MissingLoc.h @@ -43,6 +43,7 @@ class MissingLoc { }; + using missing_by_count_t = map < shard_id_t, map >; private: loc_count_t _get_count(const set &shards) { loc_count_t r; @@ -63,7 +64,7 @@ class MissingLoc { // for every entry in missing_loc, we count how many of each type of shard we have, // and maintain totals here. The sum of the values for this map will always equal // missing_loc.size(). - map < shard_id_t, map > missing_by_count; + missing_by_count_t missing_by_count; void pgs_by_shard_id( const set& s, @@ -341,7 +342,8 @@ class MissingLoc { const map &get_needs_recovery() const { return needs_recovery_map; } - const map < shard_id_t, map > &get_missing_by_count() const { + + const missing_by_count_t &get_missing_by_count() const { return missing_by_count; } }; diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 1c5b02ec332..31053eb5e84 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -3622,63 +3622,7 @@ bool PG::try_flush_or_schedule_async() ostream& operator<<(ostream& out, const PG& pg) { - out << "pg[" << pg.info - << " " << pg.up; - if (pg.acting != pg.up) - out << "/" << pg.acting; - if (pg.is_ec_pg()) - out << "p" << pg.get_primary(); - if (!pg.async_recovery_targets.empty()) - out << " async=[" << pg.async_recovery_targets << "]"; - if (!pg.backfill_targets.empty()) - out << " backfill=[" << pg.backfill_targets << "]"; - out << " r=" << pg.get_role(); - out << " lpr=" << pg.get_last_peering_reset(); - - if (pg.deleting) - out << " DELETING"; - - if (!pg.past_intervals.empty()) { - out << " pi=[" << pg.past_intervals.get_bounds() - << ")/" << pg.past_intervals.size(); - } - - if (pg.is_peered()) { - if (pg.last_update_ondisk != pg.info.last_update) - out << " luod=" << pg.last_update_ondisk; - if (pg.last_update_applied != pg.info.last_update) - out << " lua=" << pg.last_update_applied; - } - - if (pg.recovery_ops_active) - out << " rops=" << pg.recovery_ops_active; - - if (pg.pg_log.get_tail() != pg.info.log_tail || - pg.pg_log.get_head() != pg.info.last_update) - out << " (info mismatch, " << pg.pg_log.get_log() << ")"; - - if (!pg.pg_log.get_log().empty()) { - if ((pg.pg_log.get_log().log.begin()->version <= pg.pg_log.get_tail())) { - out << " (log bound mismatch, actual=[" - << pg.pg_log.get_log().log.begin()->version << "," - << pg.pg_log.get_log().log.rbegin()->version << "]"; - out << ")"; - } - } - - out << " crt=" << pg.pg_log.get_can_rollback_to(); - - if (pg.last_complete_ondisk != pg.info.last_complete) - out << " lcod " << pg.last_complete_ondisk; - - if (pg.is_primary()) { - out << " mlcod " << pg.min_last_complete_ondisk; - } - - out << " " << pg_state_string(pg.get_state()); - if (pg.should_send_notify()) - out << " NOTIFY"; - + out << pg.recovery_state; if (pg.scrubber.must_repair) out << " MUST_REPAIR"; if (pg.scrubber.auto_repair) @@ -3692,17 +3636,20 @@ ostream& operator<<(ostream& out, const PG& pg) if (pg.scrubber.must_scrub) out << " MUST_SCRUB"; + if (pg.recovery_ops_active) + out << " rops=" << pg.recovery_ops_active; + //out << " (" << pg.pg_log.get_tail() << "," << pg.pg_log.get_head() << "]"; - if (pg.pg_log.get_missing().num_missing()) { - out << " m=" << pg.pg_log.get_missing().num_missing(); + if (pg.recovery_state.have_missing()) { + out << " m=" << pg.recovery_state.get_num_missing(); if (pg.is_primary()) { - uint64_t unfound = pg.get_num_unfound(); + uint64_t unfound = pg.recovery_state.get_num_unfound(); if (unfound) out << " u=" << unfound; } } if (!pg.is_clean()) { - out << " mbc=" << pg.missing_loc.get_missing_by_count(); + out << " mbc=" << pg.recovery_state.get_missing_by_count(); } if (!pg.snap_trimq.empty()) { out << " trimq="; @@ -3713,12 +3660,12 @@ ostream& operator<<(ostream& out, const PG& pg) out << pg.snap_trimq; } } - if (!pg.info.purged_snaps.empty()) { + if (!pg.recovery_state.get_info().purged_snaps.empty()) { out << " ps="; // snap trim queue / purged snaps - if (pg.info.purged_snaps.num_intervals() > 16) { - out << pg.info.purged_snaps.size(); + if (pg.recovery_state.get_info().purged_snaps.num_intervals() > 16) { + out << pg.recovery_state.get_info().purged_snaps.size(); } else { - out << pg.info.purged_snaps; + out << pg.recovery_state.get_info().purged_snaps; } } diff --git a/src/osd/PeeringState.cc b/src/osd/PeeringState.cc index fc92ba4ffb1..6be60577410 100644 --- a/src/osd/PeeringState.cc +++ b/src/osd/PeeringState.cc @@ -3341,6 +3341,58 @@ void PeeringState::init( write_if_dirty(*t); } +void PeeringState::dump_peering_state(Formatter *f) +{ + f->dump_string("state", get_pg_state_string()); + f->dump_unsigned("epoch", get_osdmap_epoch()); + f->open_array_section("up"); + for (vector::const_iterator p = up.begin(); p != up.end(); ++p) + f->dump_unsigned("osd", *p); + f->close_section(); + f->open_array_section("acting"); + for (vector::const_iterator p = acting.begin(); p != acting.end(); ++p) + f->dump_unsigned("osd", *p); + f->close_section(); + if (!backfill_targets.empty()) { + f->open_array_section("backfill_targets"); + for (set::iterator p = backfill_targets.begin(); + p != backfill_targets.end(); + ++p) + f->dump_stream("shard") << *p; + f->close_section(); + } + if (!async_recovery_targets.empty()) { + f->open_array_section("async_recovery_targets"); + for (set::iterator p = async_recovery_targets.begin(); + p != async_recovery_targets.end(); + ++p) + f->dump_stream("shard") << *p; + f->close_section(); + } + if (!acting_recovery_backfill.empty()) { + f->open_array_section("acting_recovery_backfill"); + for (set::iterator p = acting_recovery_backfill.begin(); + p != acting_recovery_backfill.end(); + ++p) + f->dump_stream("shard") << *p; + f->close_section(); + } + f->open_object_section("info"); + update_calc_stats(); + info.dump(f); + f->close_section(); + + f->open_array_section("peer_info"); + for (map::const_iterator p = peer_info.begin(); + p != peer_info.end(); + ++p) { + f->open_object_section("info"); + f->dump_stream("peer") << p->first; + p->second.dump(f); + f->close_section(); + } +} + /*------------ Peering State Machine----------------*/ #undef dout_prefix #define dout_prefix (context< PeeringMachine >().dpp->gen_prefix(*_dout) \ @@ -6004,3 +6056,59 @@ void PeeringState::PeeringMachine::log_exit(const char *state_name, utime_t ente event_time = utime_t(); } +ostream &operator<<(ostream &out, const PeeringState &ps) { + out << "pg[" << ps.info + << " " << ps.up; + if (ps.acting != ps.up) + out << "/" << ps.acting; + if (ps.is_ec_pg()) + out << "p" << ps.get_primary(); + if (!ps.async_recovery_targets.empty()) + out << " async=[" << ps.async_recovery_targets << "]"; + if (!ps.backfill_targets.empty()) + out << " backfill=[" << ps.backfill_targets << "]"; + out << " r=" << ps.get_role(); + out << " lpr=" << ps.get_last_peering_reset(); + + if (ps.deleting) + out << " DELETING"; + + if (!ps.past_intervals.empty()) { + out << " pi=[" << ps.past_intervals.get_bounds() + << ")/" << ps.past_intervals.size(); + } + + if (ps.is_peered()) { + if (ps.last_update_ondisk != ps.info.last_update) + out << " luod=" << ps.last_update_ondisk; + if (ps.last_update_applied != ps.info.last_update) + out << " lua=" << ps.last_update_applied; + } + + if (ps.pg_log.get_tail() != ps.info.log_tail || + ps.pg_log.get_head() != ps.info.last_update) + out << " (info mismatch, " << ps.pg_log.get_log() << ")"; + + if (!ps.pg_log.get_log().empty()) { + if ((ps.pg_log.get_log().log.begin()->version <= ps.pg_log.get_tail())) { + out << " (log bound mismatch, actual=[" + << ps.pg_log.get_log().log.begin()->version << "," + << ps.pg_log.get_log().log.rbegin()->version << "]"; + out << ")"; + } + } + + out << " crt=" << ps.pg_log.get_can_rollback_to(); + + if (ps.last_complete_ondisk != ps.info.last_complete) + out << " lcod " << ps.last_complete_ondisk; + + if (ps.is_primary()) { + out << " mlcod " << ps.min_last_complete_ondisk; + } + + out << " " << pg_state_string(ps.get_state()); + if (ps.should_send_notify()) + out << " NOTIFY"; + return out; +} diff --git a/src/osd/PeeringState.h b/src/osd/PeeringState.h index 050f6df0fbf..8c1adbe6db9 100644 --- a/src/osd/PeeringState.h +++ b/src/osd/PeeringState.h @@ -1678,10 +1678,32 @@ public: return missing_loc.num_unfound(); } + bool have_missing() const { + return pg_log.get_missing().num_missing() > 0; + } + bool get_num_missing() const { + return pg_log.get_missing().num_missing() > 0; + } + + const MissingLoc::missing_by_count_t &get_missing_by_count() const { + return missing_loc.get_missing_by_count(); + } + eversion_t get_min_last_complete_ondisk() const { return min_last_complete_ondisk; } + std::string get_pg_state_string() const { + return pg_state_string(state); + } + + void print_past_intervals(ostream &out) const { + out << "[" << past_intervals.get_bounds() + << ")/" << past_intervals.size(); + } + + void dump_peering_state(Formatter *f); + private: void apply_peer_features(uint64_t f) { peer_features &= f; } void reset_min_peer_features() { @@ -1704,4 +1726,8 @@ public: return flushes_in_progress > 0; } void complete_flush(); + + friend ostream &operator<<(ostream &out, const PeeringState &ps); }; + +ostream &operator<<(ostream &out, const PeeringState &ps); diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index a1a020b381f..794a8bd58ae 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -996,56 +996,9 @@ int PrimaryLogPG::do_command( cmd_getval(cct, cmdmap, "cmd", command); if (command == "query") { f->open_object_section("pg"); - f->dump_string("state", pg_state_string(get_state())); f->dump_stream("snap_trimq") << snap_trimq; f->dump_unsigned("snap_trimq_len", snap_trimq.size()); - f->dump_unsigned("epoch", get_osdmap_epoch()); - f->open_array_section("up"); - for (vector::iterator p = up.begin(); p != up.end(); ++p) - f->dump_unsigned("osd", *p); - f->close_section(); - f->open_array_section("acting"); - for (vector::iterator p = acting.begin(); p != acting.end(); ++p) - f->dump_unsigned("osd", *p); - f->close_section(); - if (!backfill_targets.empty()) { - f->open_array_section("backfill_targets"); - for (set::iterator p = backfill_targets.begin(); - p != backfill_targets.end(); - ++p) - f->dump_stream("shard") << *p; - f->close_section(); - } - if (!async_recovery_targets.empty()) { - f->open_array_section("async_recovery_targets"); - for (set::iterator p = async_recovery_targets.begin(); - p != async_recovery_targets.end(); - ++p) - f->dump_stream("shard") << *p; - f->close_section(); - } - if (!acting_recovery_backfill.empty()) { - f->open_array_section("acting_recovery_backfill"); - for (set::iterator p = acting_recovery_backfill.begin(); - p != acting_recovery_backfill.end(); - ++p) - f->dump_stream("shard") << *p; - f->close_section(); - } - f->open_object_section("info"); - _update_calc_stats(); - info.dump(f.get()); - f->close_section(); - - f->open_array_section("peer_info"); - for (map::iterator p = peer_info.begin(); - p != peer_info.end(); - ++p) { - f->open_object_section("info"); - f->dump_stream("peer") << p->first; - p->second.dump(f.get()); - f->close_section(); - } + recovery_state.dump_peering_state(f.get()); f->close_section(); f->open_array_section("recovery_state");