From 99fcd161bd222a4f0d2ddde0f1a4caecd1a78882 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 26 Sep 2017 18:36:06 -0400 Subject: [PATCH] mgr/balancer: normalize weight-set weights to sum to target weight Signed-off-by: Sage Weil --- src/pybind/mgr/balancer/module.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 612fe6b4a60..9b00922cac4 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -646,6 +646,18 @@ class Module(MgrModule): new_weight) next_ws[osd] = new_weight + # normalize weights under this root + root_weight = crush.get_item_weight(pe.root_ids[root]) + root_sum = sum(b for a,b in next_ws.iteritems() + if a in target.keys()) + if root_sum > 0 and root_weight > 0: + factor = root_sum / root_weight + self.log.debug('normalizing root %s %d, weight %f, ws sum %f, factor %f', + root, pe.root_ids[root], root_weight, + root_sum, factor) + for osd in actual.keys(): + next_ws[osd] = next_ws[osd] / factor + # recalc plan.compat_ws = copy.deepcopy(next_ws) next_ms = plan.final_state() -- 2.39.5