summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Mick <dan.mick@inktank.com>2013-07-19 18:04:29 -0700
committerDan Mick <dan.mick@inktank.com>2013-07-26 13:51:09 -0700
commitbcbb807c018f89d473a252d87e8d48b5220b3a61 (patch)
tree6ab4c21222c4ac15eecb50cf36002ac622023967
parent6e6ceffa1b36c4d1d6b6fc7885322c8000f7dd77 (diff)
downloadceph-bcbb807c018f89d473a252d87e8d48b5220b3a61.tar.gz
PG: add formatted output to pg <pgid> query, list_missing
Signed-off-by: Dan Mick <dan.mick@inktank.com>
-rw-r--r--src/osd/PG.h4
-rw-r--r--src/osd/ReplicatedPG.cc107
-rw-r--r--src/osd/ReplicatedPG.h4
3 files changed, 53 insertions, 62 deletions
diff --git a/src/osd/PG.h b/src/osd/PG.h
index 5525c7f46dd..10e9a2544a9 100644
--- a/src/osd/PG.h
+++ b/src/osd/PG.h
@@ -43,6 +43,7 @@
#include "msg/Messenger.h"
#include "messages/MOSDRepScrub.h"
#include "messages/MOSDPGLog.h"
+#include "common/cmdparse.h"
#include "common/tracked_int_ptr.hpp"
#include "common/WorkQueue.h"
#include "include/str_list.h"
@@ -109,7 +110,6 @@ struct PGRecoveryStats {
<< i.total_time << "\t"
<< i.min_time << "\t" << i.max_time << "\t"
<< p->first << "\n";
-
}
}
@@ -1814,7 +1814,7 @@ public:
virtual void do_push_reply(OpRequestRef op) = 0;
virtual void snap_trimmer() = 0;
- virtual int do_command(vector<string>& cmd, ostream& ss,
+ virtual int do_command(cmdmap_t cmdmap, ostream& ss,
bufferlist& idata, bufferlist& odata) = 0;
virtual bool same_for_read_since(epoch_t e) = 0;
diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc
index 298d38d6ace..4a59a23cdb7 100644
--- a/src/osd/ReplicatedPG.cc
+++ b/src/osd/ReplicatedPG.cc
@@ -268,23 +268,12 @@ int ReplicatedPG::get_pgls_filter(bufferlist::iterator& iter, PGLSFilter **pfilt
// ==========================================================
-int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
+int ReplicatedPG::do_command(cmdmap_t cmdmap, ostream& ss,
bufferlist& idata, bufferlist& odata)
{
const pg_missing_t &missing = pg_log.get_missing();
- map<string, cmd_vartype> cmdmap;
string prefix;
-
- if (cmd.empty()) {
- ss << "no command given";
- return -EINVAL;
- }
-
- stringstream ss2;
- if (!cmdmap_from_json(cmd, &cmdmap, ss2)) {
- ss << ss2.str();
- return -EINVAL;
- }
+ string format;
cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
if (prefix != "pg") {
@@ -292,33 +281,36 @@ int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
return -EINVAL;
}
+ cmd_getval(g_ceph_context, cmdmap, "format", format);
+ boost::scoped_ptr<Formatter> f(new_formatter(format));
+ // demand that we have a formatter
+ if (!f)
+ f.reset(new_formatter("json"));
+
string command;
cmd_getval(g_ceph_context, cmdmap, "cmd", command);
if (command == "query") {
- JSONFormatter jsf(true);
- jsf.open_object_section("pg");
- jsf.dump_string("state", pg_state_string(get_state()));
- jsf.dump_unsigned("epoch", get_osdmap()->get_epoch());
- jsf.open_array_section("up");
+ f->open_object_section("pg");
+ f->dump_string("state", pg_state_string(get_state()));
+ f->dump_unsigned("epoch", get_osdmap()->get_epoch());
+ f->open_array_section("up");
for (vector<int>::iterator p = up.begin(); p != up.end(); ++p)
- jsf.dump_unsigned("osd", *p);
- jsf.close_section();
- jsf.open_array_section("acting");
+ f->dump_unsigned("osd", *p);
+ f->close_section();
+ f->open_array_section("acting");
for (vector<int>::iterator p = acting.begin(); p != acting.end(); ++p)
- jsf.dump_unsigned("osd", *p);
- jsf.close_section();
- jsf.open_object_section("info");
- info.dump(&jsf);
- jsf.close_section();
-
- jsf.open_array_section("recovery_state");
- handle_query_state(&jsf);
- jsf.close_section();
-
- jsf.close_section();
- stringstream dss;
- jsf.flush(dss);
- odata.append(dss);
+ f->dump_unsigned("osd", *p);
+ f->close_section();
+ f->open_object_section("info");
+ info.dump(f.get());
+ f->close_section();
+
+ f->open_array_section("recovery_state");
+ handle_query_state(f.get());
+ f->close_section();
+
+ f->close_section();
+ f->flush(odata);
return 0;
}
else if (command == "mark_unfound_lost") {
@@ -352,7 +344,6 @@ int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
return 0;
}
else if (command == "list_missing") {
- JSONFormatter jf(true);
hobject_t offset;
string offset_json;
if (cmd_getval(g_ceph_context, cmdmap, "offset", offset_json)) {
@@ -366,50 +357,48 @@ int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
return -EINVAL;
}
}
- jf.open_object_section("missing");
+ f->open_object_section("missing");
{
- jf.open_object_section("offset");
- offset.dump(&jf);
- jf.close_section();
+ f->open_object_section("offset");
+ offset.dump(f.get());
+ f->close_section();
}
- jf.dump_int("num_missing", missing.num_missing());
- jf.dump_int("num_unfound", get_num_unfound());
+ f->dump_int("num_missing", missing.num_missing());
+ f->dump_int("num_unfound", get_num_unfound());
map<hobject_t,pg_missing_t::item>::const_iterator p = missing.missing.upper_bound(offset);
{
- jf.open_array_section("objects");
+ f->open_array_section("objects");
int32_t num = 0;
bufferlist bl;
while (p != missing.missing.end() && num < g_conf->osd_command_max_records) {
- jf.open_object_section("object");
+ f->open_object_section("object");
{
- jf.open_object_section("oid");
- p->first.dump(&jf);
- jf.close_section();
+ f->open_object_section("oid");
+ p->first.dump(f.get());
+ f->close_section();
}
- p->second.dump(&jf); // have, need keys
+ p->second.dump(f.get()); // have, need keys
{
- jf.open_array_section("locations");
+ f->open_array_section("locations");
map<hobject_t,set<int> >::iterator q = missing_loc.find(p->first);
if (q != missing_loc.end())
for (set<int>::iterator r = q->second.begin(); r != q->second.end(); ++r)
- jf.dump_int("osd", *r);
- jf.close_section();
+ f->dump_int("osd", *r);
+ f->close_section();
}
- jf.close_section();
+ f->close_section();
++p;
num++;
}
- jf.close_section();
+ f->close_section();
}
- jf.dump_int("more", p != missing.missing.end());
- jf.close_section();
- stringstream jss;
- jf.flush(jss);
- odata.append(jss);
+ f->dump_int("more", p != missing.missing.end());
+ f->close_section();
+ f->flush(odata);
return 0;
};
- ss << "unknown command " << cmd;
+ ss << "unknown pg command " << prefix;
return -EINVAL;
}
diff --git a/src/osd/ReplicatedPG.h b/src/osd/ReplicatedPG.h
index 9dafe23faa1..7b70b4381ea 100644
--- a/src/osd/ReplicatedPG.h
+++ b/src/osd/ReplicatedPG.h
@@ -17,6 +17,7 @@
#include <boost/optional.hpp>
#include "include/assert.h"
+#include "common/cmdparse.h"
#include "PG.h"
#include "OSD.h"
@@ -930,7 +931,8 @@ public:
const hobject_t& ioid);
~ReplicatedPG() {}
- int do_command(vector<string>& cmd, ostream& ss, bufferlist& idata, bufferlist& odata);
+ int do_command(cmdmap_t cmdmap, ostream& ss, bufferlist& idata,
+ bufferlist& odata);
void do_op(OpRequestRef op);
bool pg_op_must_wait(MOSDOp *op);