From: Patrick Donnelly Date: Tue, 5 Mar 2019 15:51:04 +0000 (-0800) Subject: mds: refactor subtree accessors X-Git-Tag: v14.1.1~26^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d23e1555df5c557d1e97b7259cb31a5943f75dc2;p=ceph-ci.git mds: refactor subtree accessors Mostly avoiding inefficient use of std::set. Signed-off-by: Patrick Donnelly --- diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index f7706270355..74a93a77230 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -148,9 +148,7 @@ void MDBalancer::handle_export_pins(void) } } - set 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 import_map; - set authsubs; - mds->mdcache->get_auth_subtrees(authsubs); - for (set::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 import_pop_map; multimap > import_from_map; - set 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; diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index a2f9a84c42b..b57fe15f899 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -1414,64 +1414,6 @@ void MDCache::adjust_subtree_after_rename(CInode *diri, CDir *olddir, bool pop) show_subtrees(); } - -void MDCache::get_fullauth_subtrees(set& s) -{ - for (map >::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& s) -{ - for (map >::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 >::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 >::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 diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 2d02df32bd5..fe3d0e6e60b 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -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& s); - void get_fullauth_subtrees(set& s); + auto get_auth_subtrees() { + std::vector 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 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: