From 26e7d5fab6264c11ca8426ca3692420bea93ec66 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 5 Jan 2015 22:32:55 +0000 Subject: [PATCH] mds: add asok command for getting subtreemap For when we want to inspect this from a test or during debugging. Signed-off-by: John Spray --- src/mds/CDir.cc | 40 +++++++++++++++++++++++----------------- src/mds/MDS.cc | 35 +++++++++++++++++++++++++++++++++++ src/mds/MDS.h | 1 + 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 01b61b0d17a..c4f0713ea26 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -2694,26 +2694,32 @@ void CDir::dump(Formatter *f) const f->dump_int("snapid_first", first); f->dump_bool("auth", is_auth()); - // >> Only meaningful for auth - f->open_object_section("replica_map"); - for (std::map::const_iterator i = replica_map.begin(); - i != replica_map.end(); ++i) { - std::ostringstream rank_str; - rank_str << i->first; - f->dump_int(rank_str.str().c_str(), i->second); + // Fields only meaningful for auth + f->open_object_section("auth_state"); + { + f->open_object_section("replica_map"); + for (std::map::const_iterator i = replica_map.begin(); + i != replica_map.end(); ++i) { + std::ostringstream rank_str; + rank_str << i->first; + f->dump_int(rank_str.str().c_str(), i->second); + } + f->close_section(); + f->dump_stream("projected_version") << get_projected_version(); + f->dump_stream("version") << get_version(); + f->dump_stream("comitting_version") << get_committing_version(); + f->dump_stream("comitted_version") << get_committed_version(); } f->close_section(); - f->dump_stream("projected_version") << get_projected_version(); - f->dump_stream("version") << get_version(); - f->dump_stream("comitting_version") << get_committing_version(); - f->dump_stream("comitted_version") << get_committed_version(); - // << Only meaningful for auth - // >> Only meaningful for replica - f->dump_stream("authority_first") << authority().first; - f->dump_stream("authority_second") << authority().second; - f->dump_stream("replica_nonce") << get_replica_nonce(); - // << Only meaningful for replica + // Fields only meaningful for replica + f->open_object_section("replica_state"); + { + f->dump_stream("authority_first") << authority().first; + f->dump_stream("authority_second") << authority().second; + f->dump_stream("replica_nonce") << get_replica_nonce(); + } + f->close_section(); f->dump_bool("is_rep", is_rep()); diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 8c104c4a328..f1a9c719085 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -53,6 +53,7 @@ #include "common/Timer.h" #include "events/ESession.h" +#include "events/ESubtreeMap.h" #include "messages/MMDSMap.h" #include "messages/MMDSBeacon.h" @@ -331,6 +332,8 @@ bool MDS::asok_command(string command, cmdmap_t& cmdmap, string format, command_flush_path(f, path); } else if (command == "flush journal") { command_flush_journal(f); + } else if (command == "get subtrees") { + command_get_subtrees(f); } else if (command == "force_readonly") { mds_lock.Lock(); mdcache->force_readonly(); @@ -481,6 +484,33 @@ int MDS::_command_flush_journal(std::stringstream *ss) return 0; } + +void MDS::command_get_subtrees(Formatter *f) +{ + assert(f != NULL); + + std::list subtrees; + mdcache->list_subtrees(subtrees); + + f->open_array_section("subtrees"); + for (std::list::iterator i = subtrees.begin(); i != subtrees.end(); ++i) { + const CDir *dir = *i; + + f->open_object_section("subtree"); + { + f->dump_bool("is_auth", dir->is_auth()); + f->dump_int("auth_first", dir->get_dir_auth().first); + f->dump_int("auth_second", dir->get_dir_auth().second); + f->open_object_section("dir"); + dir->dump(f); + f->close_section(); + } + f->close_section(); + } + f->close_section(); +} + + void MDS::set_up_admin_socket() { int r; @@ -530,6 +560,11 @@ void MDS::set_up_admin_socket() asok_hook, "Force MDS to read-only mode"); assert(0 == r); + r = admin_socket->register_command("get subtrees", + "get subtrees", + asok_hook, + "Return the subtree map"); + assert(0 == r); } void MDS::clean_up_admin_socket() diff --git a/src/mds/MDS.h b/src/mds/MDS.h index f92be473249..73654f4fc2f 100644 --- a/src/mds/MDS.h +++ b/src/mds/MDS.h @@ -384,6 +384,7 @@ private: void command_scrub_path(Formatter *f, const string& path); void command_flush_path(Formatter *f, const string& path); void command_flush_journal(Formatter *f); + void command_get_subtrees(Formatter *f); private: int _command_flush_journal(std::stringstream *ss); public: