}
else if (prefix == "debug dump_missing") {
- string file_name;
- cmd_getval(cct, cmdmap, "filename", file_name);
- std::ofstream fout(file_name.c_str());
- if (!fout.is_open()) {
- ss << "failed to open file '" << file_name << "'";
- r = -EINVAL;
- goto out;
+ if (!f) {
+ f.reset(new JSONFormatter(true));
}
-
- fout << "*** osd " << whoami << ": dump_missing ***" << std::endl;
+ f->open_array_section("pgs");
RWLock::RLocker l(pg_map_lock);
for (ceph::unordered_map<spg_t, PG*>::const_iterator pg_map_e = pg_map.begin();
pg_map_e != pg_map.end(); ++pg_map_e) {
PG *pg = pg_map_e->second;
+ string s = stringify(pg->pg_id);
+ f->open_array_section(s.c_str());
pg->lock();
-
- fout << *pg << std::endl;
- std::map<hobject_t, pg_missing_item>::const_iterator mend =
- pg->pg_log.get_missing().get_items().end();
- std::map<hobject_t, pg_missing_item>::const_iterator mi =
- pg->pg_log.get_missing().get_items().begin();
- for (; mi != mend; ++mi) {
- fout << mi->first << " -> " << mi->second << std::endl;
- if (!pg->missing_loc.needs_recovery(mi->first))
- continue;
- if (pg->missing_loc.is_unfound(mi->first))
- fout << " unfound ";
- const set<pg_shard_t> &mls(pg->missing_loc.get_locations(mi->first));
- if (mls.empty())
- continue;
- fout << "missing_loc: " << mls << std::endl;
- }
+ pg->dump_missing(f.get());
pg->unlock();
- fout << std::endl;
+ f->close_section();
}
-
- fout.close();
+ f->close_section();
+ f->flush(ss);
}
else if (prefix == "debug kick_recovery_wq") {
int64_t delay;
unlock();
}
+void PG::dump_missing(Formatter *f)
+{
+ for (auto& i : pg_log.get_missing().get_items()) {
+ f->open_object_section("object");
+ f->dump_object("oid", i.first);
+ f->dump_object("missing_info", i.second);
+ if (missing_loc.needs_recovery(i.first)) {
+ f->dump_bool("unfound", missing_loc.is_unfound(i.first));
+ f->open_array_section("locations");
+ for (auto l : missing_loc.get_locations(i.first)) {
+ f->dump_object("shard", l);
+ }
+ f->close_section();
+ }
+ f->close_section();
+ }
+}
+
void PG::get_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)> f)
{
pg_stats_publish_lock.Lock();
virtual void get_watchers(std::list<obj_watch_item_t> *ls) = 0;
void dump_pgstate_history(Formatter *f);
+ void dump_missing(Formatter *f);
void get_pg_stats(std::function<void(const pg_stat_t&, epoch_t lec)> f);
void with_heartbeat_peers(std::function<void(int)> f);