From 91fbc687ebc595aa376e4a378f72af183e8c7e91 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 23 Feb 2012 20:30:44 -0800 Subject: [PATCH] osd: 'pg list_missing ' Dump missing objects in json. If more key is non-zero, user should ask for more by passing the last object as the offset for the next request. Signed-off-by: Sage Weil --- src/osd/ReplicatedPG.cc | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 6eaf0f2585082..929452d9f30e1 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -41,6 +41,9 @@ #include "common/config.h" #include "include/compat.h" +#include "json_spirit/json_spirit_value.h" +#include "json_spirit/json_spirit_reader.h" + #define DOUT_SUBSYS osd #define DOUT_PREFIX_ARGS this, osd->whoami, get_osdmap() #undef dout_prefix @@ -312,6 +315,55 @@ int ReplicatedPG::do_command(vector& cmd, ostream& ss, mark_all_unfound_lost(mode); return 0; } + else if (cmd.size() >= 1 && cmd[0] == "list_missing") { + JSONFormatter jf(true); + hobject_t offset; + if (cmd.size() > 1) { + json_spirit::Value v; + try { + if (!json_spirit::read(cmd[1], v)) + throw std::runtime_error("bad json"); + offset.decode(v); + } catch (std::runtime_error& e) { + ss << "error parsing offset: " << e.what(); + return -EINVAL; + } + } + jf.open_object_section("missing"); + jf.open_object_section("offset"); + offset.dump(&jf); + jf.close_section(); + jf.dump_int("num_missing", missing.num_missing()); + jf.dump_int("num_unfound", get_num_unfound()); + jf.open_array_section("objects"); + map::iterator p = missing.missing.upper_bound(offset); + uint32_t num = 0; + set empty; + bufferlist bl; + while (p != missing.missing.end() && num < 5) { + jf.open_object_section("object"); + jf.open_object_section("oid"); + p->first.dump(&jf); + jf.close_section(); + p->second.dump(&jf); // have, need keys + jf.open_array_section("locations"); + map >::iterator q = missing_loc.find(p->first); + if (q != missing_loc.end()) + for (set::iterator r = q->second.begin(); r != q->second.end(); ++r) + jf.dump_int("osd", *r); + jf.close_section(); + jf.close_section(); + ++p; + num++; + } + jf.close_section(); + jf.dump_int("more", p != missing.missing.end()); + jf.close_section(); + stringstream jss; + jf.flush(jss); + odata.append(jss); + return 0; + }; ss << "unknown command " << cmd; return -EINVAL; -- 2.39.5