]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: refactor subtree accessors
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 5 Mar 2019 15:51:04 +0000 (07:51 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 5 Mar 2019 21:40:17 +0000 (13:40 -0800)
Mostly avoiding inefficient use of std::set.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/mds/MDBalancer.cc
src/mds/MDCache.cc
src/mds/MDCache.h

index f770627035586924410c4d81ed1c3ad81092b2de..74a93a7723013254243ed78b0126d4e5e4c40afe 100644 (file)
@@ -148,9 +148,7 @@ void MDBalancer::handle_export_pins(void)
     }
   }
 
-  set<CDir *> authsubs;
-  mds->mdcache->get_auth_subtrees(authsubs);
-  for (auto &cd : authsubs) {
+  for (auto &cd : mds->mdcache->get_auth_subtrees()) {
     mds_rank_t export_pin = cd->inode->get_export_pin();
     dout(10) << "auth tree " << *cd << " export_pin=" << export_pin << dendl;
     if (export_pin >= 0 && export_pin != mds->get_nodeid()) {
@@ -366,12 +364,7 @@ void MDBalancer::send_heartbeat()
 
   // import_map -- how much do i import from whom
   map<mds_rank_t, float> import_map;
-  set<CDir*> authsubs;
-  mds->mdcache->get_auth_subtrees(authsubs);
-  for (set<CDir*>::iterator it = authsubs.begin();
-       it != authsubs.end();
-       ++it) {
-    CDir *im = *it;
+  for (auto& im : mds->mdcache->get_auth_subtrees()) {
     mds_rank_t from = im->inode->authority().first;
     if (from == mds->get_nodeid()) continue;
     if (im->get_inode()->is_stray()) continue;
@@ -838,10 +831,8 @@ void MDBalancer::try_rebalance(balance_state_t& state)
   // make a sorted list of my imports
   multimap<double, CDir*> import_pop_map;
   multimap<mds_rank_t, pair<CDir*, double> > import_from_map;
-  set<CDir*> fullauthsubs;
 
-  mds->mdcache->get_fullauth_subtrees(fullauthsubs);
-  for (auto dir : fullauthsubs) {
+  for (auto& dir : mds->mdcache->get_fullauth_subtrees()) {
     CInode *diri = dir->get_inode();
     if (diri->is_mdsdir())
       continue;
index a2f9a84c42bd717e49b94d8b7e1ca82fb9cf52a5..b57fe15f899e5f4c235186d25c5870f57901ac2e 100644 (file)
@@ -1414,64 +1414,6 @@ void MDCache::adjust_subtree_after_rename(CInode *diri, CDir *olddir, bool pop)
   show_subtrees();
 }
 
-
-void MDCache::get_fullauth_subtrees(set<CDir*>& s)
-{
-  for (map<CDir*,set<CDir*> >::iterator p = subtrees.begin();
-       p != subtrees.end();
-       ++p) {
-    CDir *root = p->first;
-    if (root->is_full_dir_auth())
-      s.insert(root);
-  }
-}
-void MDCache::get_auth_subtrees(set<CDir*>& s)
-{
-  for (map<CDir*,set<CDir*> >::iterator p = subtrees.begin();
-       p != subtrees.end();
-       ++p) {
-    CDir *root = p->first;
-    if (root->is_auth())
-      s.insert(root);
-  }
-}
-
-
-// count.
-
-int MDCache::num_subtrees()
-{
-  return subtrees.size();
-}
-
-int MDCache::num_subtrees_fullauth()
-{
-  int n = 0;
-  for (map<CDir*,set<CDir*> >::iterator p = subtrees.begin();
-       p != subtrees.end();
-       ++p) {
-    CDir *root = p->first;
-    if (root->is_full_dir_auth())
-      n++;
-  }
-  return n;
-}
-
-int MDCache::num_subtrees_fullnonauth()
-{
-  int n = 0;
-  for (map<CDir*,set<CDir*> >::iterator p = subtrees.begin();
-       p != subtrees.end();
-       ++p) {
-    CDir *root = p->first;
-    if (root->is_full_dir_nonauth())
-      n++;
-  }
-  return n;
-}
-
-
-
 // ===================================
 // journal and snap/cow helpers
 
index 2d02df32bd5189581adacd3603a33c89c7889a7f..fe3d0e6e60b10b923f6b36d140118388c25917e9 100644 (file)
@@ -359,12 +359,52 @@ public:
   void project_subtree_rename(CInode *diri, CDir *olddir, CDir *newdir);
   void adjust_subtree_after_rename(CInode *diri, CDir *olddir, bool pop);
 
-  void get_auth_subtrees(set<CDir*>& s);
-  void get_fullauth_subtrees(set<CDir*>& s);
+  auto get_auth_subtrees() {
+    std::vector<CDir*> c;
+    for (auto& p : subtrees) {
+      auto& root = p.first;
+      if (root->is_auth()) {
+        c.push_back(root);
+      }
+    }
+    return c;
+  }
 
-  int num_subtrees();
-  int num_subtrees_fullauth();
-  int num_subtrees_fullnonauth();
+  auto get_fullauth_subtrees() {
+    std::vector<CDir*> c;
+    for (auto& p : subtrees) {
+      auto& root = p.first;
+      if (root->is_full_dir_auth()) {
+        c.push_back(root);
+      }
+    }
+    return c;
+  }
+  auto num_subtrees_fullauth() const {
+    std::size_t n = 0;
+    for (auto& p : subtrees) {
+      auto& root = p.first;
+      if (root->is_full_dir_auth()) {
+        ++n;
+      }
+    }
+    return n;
+  }
+
+  auto num_subtrees_fullnonauth() const {
+    std::size_t n = 0;
+    for (auto& p : subtrees) {
+      auto& root = p.first;
+      if (root->is_full_dir_nonauth()) {
+        ++n;
+      }
+    }
+    return n;
+  }
+
+  auto num_subtrees() const {
+    return subtrees.size();
+  }
 
   
 protected: