Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mon: move 'pg map' to OSDMonitor #14559

Merged
merged 3 commits into from Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions qa/tasks/ceph_manager.py
Expand Up @@ -1297,24 +1297,20 @@ def get_pg_replica(self, pool, pgnum):
"""
get replica for pool, pgnum (e.g. (data, 0)->0
"""
output = self.raw_cluster_cmd("pg", "dump", '--format=json')
j = json.loads('\n'.join(output.split('\n')[1:]))
pg_str = self.get_pgid(pool, pgnum)
for pg in j['pg_stats']:
if pg['pgid'] == pg_str:
return int(pg['acting'][-1])
output = self.raw_cluster_cmd("pg", "map", pg_str, '--format=json')
j = json.loads('\n'.join(output.split('\n')[1:]))
return int(j['acting'][-1])
assert False

def get_pg_primary(self, pool, pgnum):
"""
get primary for pool, pgnum (e.g. (data, 0)->0
"""
output = self.raw_cluster_cmd("pg", "dump", '--format=json')
j = json.loads('\n'.join(output.split('\n')[1:]))
pg_str = self.get_pgid(pool, pgnum)
for pg in j['pg_stats']:
if pg['pgid'] == pg_str:
return int(pg['acting'][0])
output = self.raw_cluster_cmd("pg", "map", pg_str, '--format=json')
j = json.loads('\n'.join(output.split('\n')[1:]))
return int(j['acting'][0])
assert False

def get_pool_num(self, pool):
Expand Down
2 changes: 0 additions & 2 deletions src/mgr/MgrCommands.h
Expand Up @@ -37,8 +37,6 @@ COMMAND("pg ls " \
"name=pool,type=CephInt,req=false " \
"name=states,type=CephChoices,strings=active|clean|down|scrubbing|degraded|inconsistent|peering|repair|recovering|backfill_wait|incomplete|stale|remapped|deep_scrub|backfill|backfill_toofull|recovery_wait|undersized|activating|peered,n=N,req=false ", \
"list pg with specific pool, osd, state", "pg", "r", "cli,rest")
COMMAND("pg map name=pgid,type=CephPgid", "show mapping of pg to osds", \
"pg", "r", "cli,rest")
COMMAND("pg dump_stuck " \
"name=stuckops,type=CephChoices,strings=inactive|unclean|stale|undersized|degraded,n=N,req=false " \
"name=threshold,type=CephInt,req=false",
Expand Down
3 changes: 3 additions & 0 deletions src/mon/MonCommands.h
Expand Up @@ -131,6 +131,9 @@ COMMAND("pg set_nearfull_ratio name=ratio,type=CephFloat,range=0.0|1.0", \
"set ratio at which pgs are considered nearly full", \
"pg", "rw", "cli,rest")

COMMAND("pg map name=pgid,type=CephPgid", "show mapping of pg to osds", \
"pg", "r", "cli,rest")

/*
* auth commands AuthMonitor.cc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/mon/Monitor.cc
Expand Up @@ -2920,7 +2920,7 @@ void Monitor::handle_command(MonOpRequestRef op)
mdsmon()->dispatch(op);
return;
}
if (module == "osd") {
if (module == "osd" || prefix == "pg map") {
osdmon()->dispatch(op);
return;
}
Expand Down
43 changes: 43 additions & 0 deletions src/mon/OSDMonitor.cc
Expand Up @@ -3823,6 +3823,49 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
<< pg_vector_string(acting) << ", p" << acting_p << ")";
rdata.append(ds);
}

} else if (prefix == "pg map") {
pg_t pgid;
string pgidstr;
cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr);
if (!pgid.parse(pgidstr.c_str())) {
ss << "invalid pgid '" << pgidstr << "'";
r = -EINVAL;
goto reply;
}
vector<int> up, acting;
if (!osdmap.have_pg_pool(pgid.pool())) {
ss << "pg '" << pgidstr << "' does not exist";
r = -ENOENT;
goto reply;
}
pg_t mpgid = osdmap.raw_pg_to_pg(pgid);
osdmap.pg_to_up_acting_osds(pgid, up, acting);
if (f) {
f->open_object_section("pg_map");
f->dump_unsigned("epoch", osdmap.get_epoch());
f->dump_stream("raw_pgid") << pgid;
f->dump_stream("pgid") << mpgid;
f->open_array_section("up");
for (auto osd : up) {
f->dump_int("up_osd", osd);
}
f->close_section();
f->open_array_section("acting");
for (auto osd : acting) {
f->dump_int("acting_osd", osd);
}
f->close_section();
f->close_section();
f->flush(rdata);
} else {
ds << "osdmap e" << osdmap.get_epoch()
<< " pg " << pgid << " (" << mpgid << ")"
<< " -> up " << up << " acting " << acting;
rdata.append(ds);
}
goto reply;

} else if ((prefix == "osd scrub" ||
prefix == "osd deep-scrub" ||
prefix == "osd repair")) {
Expand Down
42 changes: 0 additions & 42 deletions src/mon/PGMap.cc
Expand Up @@ -2315,48 +2315,6 @@ int process_pg_map_command(
return 0;
}

if (prefix == "pg map") {
pg_t pgid;
string pgidstr;
cmd_getval(g_ceph_context, cmdmap, "pgid", pgidstr);
if (!pgid.parse(pgidstr.c_str())) {
*ss << "invalid pgid '" << pgidstr << "'";
return -EINVAL;
}
vector<int> up, acting;
if (!osdmap.have_pg_pool(pgid.pool())) {
*ss << "pg '" << pgidstr << "' does not exist";
return -ENOENT;
}
pg_t mpgid = osdmap.raw_pg_to_pg(pgid);
osdmap.pg_to_up_acting_osds(pgid, up, acting);
if (f) {
f->open_object_section("pg_map");
f->dump_unsigned("epoch", osdmap.get_epoch());
f->dump_stream("raw_pgid") << pgid;
f->dump_stream("pgid") << mpgid;

f->open_array_section("up");
for (vector<int>::iterator it = up.begin(); it != up.end(); ++it)
f->dump_int("up_osd", *it);
f->close_section();

f->open_array_section("acting");
for (vector<int>::iterator it = acting.begin(); it != acting.end(); ++it)
f->dump_int("acting_osd", *it);
f->close_section();

f->close_section();
f->flush(*odata);
} else {
ds << "osdmap e" << osdmap.get_epoch()
<< " pg " << pgid << " (" << mpgid << ")"
<< " -> up " << up << " acting " << acting;
odata->append(ds);
}
return 0;
}

if (prefix == "pg debug") {
string debugop;
cmd_getval(g_ceph_context, cmdmap, "debugop", debugop,
Expand Down