From 3a730d751deff892e7a0bddba87eba3dbb829c3e Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Tue, 12 Feb 2019 17:06:21 +0800 Subject: [PATCH] mgr/balancer: balance pools with same crush_rule in batch which is more efficient. Signed-off-by: xie xingguo --- src/pybind/mgr/balancer/module.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 60a361e368da5..3c1a384e54001 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -867,20 +867,31 @@ class Module(MgrModule): detail = 'No pools available' self.log.info(detail) return -errno.ENOENT, detail - # shuffle pool list so they all get equal (in)attention - random.shuffle(pools) - self.log.info('pools %s' % pools) inc = plan.inc total_did = 0 left = max_iterations - pools_with_pg_merge = [p['pool_name'] for p in self.get_osdmap().dump().get('pools', []) + osdmap_dump = self.get_osdmap().dump() + pools_with_pg_merge = [p['pool_name'] for p in osdmap_dump.get('pools', []) if p['pg_num'] > p['pg_num_target']] + crush_rule_by_pool_name = dict((p['pool_name'], p['crush_rule']) for p in osdmap_dump.get('pools', [])) + pools_by_crush_rule = {} # group pools by crush_rule for pool in pools: + if pool not in crush_rule_by_pool_name: + self.log.info('pool %s does not exist' % pool) + continue if pool in pools_with_pg_merge: self.log.info('pool %s has pending PG(s) for merging, skipping for now' % pool) continue - did = ms.osdmap.calc_pg_upmaps(inc, max_deviation, left, [pool]) + crush_rule = crush_rule_by_pool_name[pool] + if crush_rule not in pools_by_crush_rule: + pools_by_crush_rule[crush_rule] = [] + pools_by_crush_rule[crush_rule].append(pool) + classified_pools = pools_by_crush_rule.values() + # shuffle so all pools get equal (in)attention + random.shuffle(classified_pools) + for it in classified_pools: + did = ms.osdmap.calc_pg_upmaps(inc, max_deviation, left, it) total_did += did left -= did if left <= 0: -- 2.39.5