]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: Enhance dump_tree performance by traversing the tree directly
authordongdong tao <tdd21151186@gmail.com>
Mon, 22 Jan 2018 05:58:05 +0000 (13:58 +0800)
committerdongdong tao <tdd21151186@gmail.com>
Fri, 16 Feb 2018 14:35:25 +0000 (22:35 +0800)
Signed-off-by: dongdong tao <tdd21151186@gmail.com>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDSRank.cc
src/mds/MDSRank.h

index de600c84f02bb87146d49a9967b4a2b4c8cbaec6..fd53f51d6b4529b3d108342a9c16757ceb0274c9 100644 (file)
@@ -11946,6 +11946,28 @@ int MDCache::cache_status(Formatter *f)
   return 0;
 }
 
+void MDCache::dump_tree(CInode *in, const int cur_depth, const int max_depth, Formatter *f) 
+{
+  assert(in);
+  if ((max_depth >= 0) && (cur_depth > max_depth)) {
+    return;
+  }
+  list<CDir*> ls;
+  in->get_dirfrags(ls);
+  for (const auto &subdir : ls) {
+    for (const auto &p : subdir->items) {
+      CDentry *dn = p.second;
+      CInode *in = dn->get_linkage()->get_inode();
+      if (in) {
+        dump_tree(in, cur_depth + 1, max_depth, f);
+      }
+    }
+  }
+  f->open_object_section("inode");
+  in->dump(f);
+  f->close_section();
+}
+
 int MDCache::dump_cache(std::string_view file_name)
 {
   return dump_cache(file_name, NULL);
@@ -11956,17 +11978,11 @@ int MDCache::dump_cache(Formatter *f)
   return dump_cache(std::string_view(""), f);
 }
 
-int MDCache::dump_cache(std::string_view dump_root, int depth, Formatter *f)
-{
-  return dump_cache(std::string_view(""), f, dump_root, depth);
-}
-
 /**
  * Dump the metadata cache, either to a Formatter, if
  * provided, else to a plain text file.
  */
-int MDCache::dump_cache(std::string_view fn, Formatter *f,
-                        std::string_view dump_root, int depth)
+int MDCache::dump_cache(const char *fn, Formatter *f)
 {
   int r = 0;
   int fd = -1;
@@ -11990,24 +12006,8 @@ int MDCache::dump_cache(std::string_view fn, Formatter *f,
     }
   }
 
-  auto dump_func = [fd, f, depth, &dump_root](CInode *in) {
+  auto dump_func = [fd, f](CInode *in) {
     int r;
-    if (!dump_root.empty()) {
-      string ipath;
-      if (in->is_root())
-       ipath = "/";
-      else
-       in->make_path_string(ipath);
-
-      if (dump_root.length() > ipath.length() ||
-         !equal(dump_root.begin(), dump_root.end(), ipath.begin()))
-       return 0;
-
-      if (depth >= 0 &&
-         count(ipath.begin() + dump_root.length(), ipath.end(), '/') > depth)
-       return 0;
-    }
-
     if (f) {
       f->open_object_section("inode");
       in->dump(f);
index bc551a15c68e35c26ca12f4f7db309b815d446a1..9a8c1b9456f4da2b0fd06f309ac447c2b6370352 100644 (file)
@@ -1172,14 +1172,12 @@ public:
   void discard_delayed_expire(CDir *dir);
 
 protected:
-  int dump_cache(std::string_view fn, Formatter *f,
-                 std::string_view dump_root = "",
-                 int depth = -1);
+  int dump_cache(const char *fn, Formatter *f);
 public:
   int dump_cache() { return dump_cache(NULL, NULL); }
   int dump_cache(std::string_view filename);
   int dump_cache(Formatter *f);
-  int dump_cache(std::string_view dump_root, int depth, Formatter *f);
+  void dump_tree(CInode *in, const int cur_depth, const int max_depth, Formatter *f);
 
   int cache_status(Formatter *f);
 
index 91d4e31d3410c05fd334851395a6af994c82f2d6..e8d2d9e537317bf77cf9b1c8fdc3745e17d4c307 100644 (file)
@@ -1971,19 +1971,7 @@ bool MDSRankDispatcher::handle_asok_command(
       ss << "Failed to get cache status: " << cpp_strerror(r);
     }
   } else if (command == "dump tree") {
-    string root;
-    int64_t depth;
-    cmd_getval(g_ceph_context, cmdmap, "root", root);
-    if (!cmd_getval(g_ceph_context, cmdmap, "depth", depth))
-      depth = -1;
-    {
-      Mutex::Locker l(mds_lock);
-      int r = mdcache->dump_cache(root, depth, f);
-      if (r != 0) {
-        ss << "Failed to dump tree: " << cpp_strerror(r);
-        f->reset();
-      }
-    }
+    command_dump_tree(cmdmap, ss, f);
   } else if (command == "dump loads") {
     Mutex::Locker l(mds_lock);
     int r = balancer->dump_loads(f);
@@ -2359,6 +2347,24 @@ int MDSRank::_command_export_dir(
   return 0;
 }
 
+void MDSRank::command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f) 
+{
+  std::string root;
+  int64_t depth;
+  cmd_getval(g_ceph_context, cmdmap, "root", root);
+  if (!cmd_getval(g_ceph_context, cmdmap, "depth", depth))
+    depth = -1;
+  Mutex::Locker l(mds_lock);
+  CInode *in = mdcache->cache_traverse(filepath(root.c_str()));
+  if (!in) {
+    ss << "root inode is not in cache";
+    return;
+  }
+  f->open_array_section("inodes");
+  mdcache->dump_tree(in, 0, depth, f);
+  f->close_section();
+}
+
 CDir *MDSRank::_command_dirfrag_get(
     const cmdmap_t &cmdmap,
     std::ostream &ss)
index 39e09c7b0c0b3bc0ad1f6ee28ceacfb26a90e06d..d29eceb986b1423c3ddc7e92913d5d8aee549d5e 100644 (file)
@@ -441,6 +441,7 @@ class MDSRank {
         const cmdmap_t &cmdmap,
         std::ostream &ss);
     void command_openfiles_ls(Formatter *f);
+    void command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f);
 
   protected:
     Messenger    *messenger;