From 08116b71f6cf11d16be573ce4fd0be96ee9bbdce Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 6 Dec 2017 11:50:48 +0800 Subject: [PATCH] mds: cleanup MDBalancer::try_rebalance() no logic changes Signed-off-by: "Yan, Zheng" --- src/mds/MDBalancer.cc | 81 ++++++++++++------------------------------- 1 file changed, 22 insertions(+), 59 deletions(-) diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index f16f4442444..aa5abd62d4a 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -825,28 +825,25 @@ void MDBalancer::try_rebalance(balance_state_t& state) set fullauthsubs; mds->mdcache->get_fullauth_subtrees(fullauthsubs); - for (set::iterator it = fullauthsubs.begin(); - it != fullauthsubs.end(); - ++it) { - CDir *im = *it; - if (im->get_inode()->is_stray()) continue; + for (auto dir : fullauthsubs) { + CInode *diri = dir->get_inode(); + if (diri->is_stray()) continue; - double pop = im->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate); + mds_rank_t from = diri->authority().first; + double pop = dir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate); if (g_conf->mds_bal_idle_threshold > 0 && pop < g_conf->mds_bal_idle_threshold && - im->inode != mds->mdcache->get_root() && - im->inode->authority().first != mds->get_nodeid()) { - dout(5) << " exporting idle (" << pop << ") import " << *im - << " back to mds." << im->inode->authority().first - << dendl; - mds->mdcache->migrator->export_dir_nicely(im, im->inode->authority().first); + diri != mds->mdcache->get_root() && + from != mds->get_nodeid()) { + dout(5) << " exporting idle (" << pop << ") import " << *dir + << " back to mds." << from << dendl; + mds->mdcache->migrator->export_dir_nicely(dir, from); continue; } - import_pop_map[ pop ] = im; - mds_rank_t from = im->inode->authority().first; - dout(15) << " map: i imported " << *im << " from " << from << dendl; - import_from_map.insert(pair(from, im)); + import_pop_map[pop] = dir; + dout(15) << " map: i imported " << *dir << " from " << from << dendl; + import_from_map.insert(pair(from, dir)); } @@ -905,57 +902,23 @@ void MDBalancer::try_rebalance(balance_state_t& state) continue; } - // any other imports - if (false) - for (map::iterator import = import_pop_map.begin(); - import != import_pop_map.end(); - import++) { - CDir *imp = (*import).second; - if (imp->inode->is_base() || - imp->inode->is_stray()) - continue; - - double pop = (*import).first; - if (pop < amount-have || pop < MIN_REEXPORT) { - dout(5) << "reexporting " << *imp - << " pop " << pop - << " back to mds." << imp->inode->authority() - << dendl; - have += pop; - mds->mdcache->migrator->export_dir_nicely(imp, imp->inode->authority().first); - } - if (amount-have < MIN_OFFLOAD) break; - } - if (amount-have < MIN_OFFLOAD) { - //fudge = amount-have; - continue; - } - // okay, search for fragments of my workload - set candidates; - mds->mdcache->get_fullauth_subtrees(candidates); - list exports; - for (set::iterator pot = candidates.begin(); - pot != candidates.end(); - ++pot) { - if ((*pot)->get_inode()->is_stray()) continue; - find_exports(*pot, amount, exports, have, already_exporting); + for (auto dir : fullauthsubs) { + if (dir->get_inode()->is_stray()) + continue; + find_exports(dir, amount, exports, have, already_exporting); if (have > amount-MIN_OFFLOAD) break; } //fudge = amount - have; - for (list::iterator it = exports.begin(); it != exports.end(); ++it) { - dout(5) << " - exporting " - << (*it)->pop_auth_subtree - << " " - << (*it)->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate) - << " to mds." << target - << " " << **it - << dendl; - mds->mdcache->migrator->export_dir_nicely(*it, target); + for (auto dir : exports) { + dout(5) << " - exporting " << dir->pop_auth_subtree + << " " << dir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate) + << " to mds." << target << " " << *dir << dendl; + mds->mdcache->migrator->export_dir_nicely(dir, target); } } -- 2.39.5