]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/: move ostream<< and dump logic into PeeringState
authorSamuel Just <sjust@redhat.com>
Wed, 3 Apr 2019 23:58:15 +0000 (16:58 -0700)
committersjust@redhat.com <sjust@redhat.com>
Wed, 1 May 2019 18:22:25 +0000 (11:22 -0700)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/osd/MissingLoc.h
src/osd/PG.cc
src/osd/PeeringState.cc
src/osd/PeeringState.h
src/osd/PrimaryLogPG.cc

index 4ebc5520c7615b1e7d6f69e1a26861cde35bdaa7..73d45b505fd038d1c023ded021b969e71c44b3d4 100644 (file)
@@ -43,6 +43,7 @@ class MissingLoc {
   };
 
 
+  using missing_by_count_t = map < shard_id_t, map<loc_count_t,int> >;
  private:
   loc_count_t _get_count(const set<pg_shard_t> &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<loc_count_t,int> > missing_by_count;
+  missing_by_count_t missing_by_count;
 
   void pgs_by_shard_id(
     const set<pg_shard_t>& s,
@@ -341,7 +342,8 @@ class MissingLoc {
   const map<hobject_t, pg_missing_item> &get_needs_recovery() const {
     return needs_recovery_map;
   }
-  const map < shard_id_t, map<loc_count_t,int> > &get_missing_by_count() const {
+
+  const missing_by_count_t &get_missing_by_count() const {
     return missing_by_count;
   }
 };
index 1c5b02ec332624d9f5ae683d65d4b751e9e6fd64..31053eb5e84916f31fb4b5c4e037d4b8f9057c80 100644 (file)
@@ -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;
     }
   }
 
index fc92ba4ffb189fc858b8c9138283f54e3c005dc6..6be60577410fcf4f91e8946a9336c8c4b84c82a3 100644 (file)
@@ -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<int>::const_iterator p = up.begin(); p != up.end(); ++p)
+    f->dump_unsigned("osd", *p);
+  f->close_section();
+  f->open_array_section("acting");
+  for (vector<int>::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<pg_shard_t>::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<pg_shard_t>::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<pg_shard_t>::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<pg_shard_t, pg_info_t>::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;
+}
index 050f6df0fbfa2355c4731223e59885f20bd5d442..8c1adbe6db9023a296015abba2db36bb7470630f 100644 (file)
@@ -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);
index a1a020b381f6ed9201b2d0369db8c05f7a37a451..794a8bd58aeebc2713ee77b4b230533db349d90a 100644 (file)
@@ -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<int>::iterator p = up.begin(); p != up.end(); ++p)
-      f->dump_unsigned("osd", *p);
-    f->close_section();
-    f->open_array_section("acting");
-    for (vector<int>::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<pg_shard_t>::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<pg_shard_t>::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<pg_shard_t>::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<pg_shard_t, pg_info_t>::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");