Mostly avoiding inefficient use of std::set.
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
}
}
- 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()) {
// 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;
// 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;
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
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: