From 2587989151fbaa2c698ee9110eb01bed8e50cb02 Mon Sep 17 00:00:00 2001 From: Dan van der Ster Date: Sat, 15 Sep 2018 14:46:00 +0200 Subject: [PATCH] mgr/balancer: add crush_compat_metrics param Add a crush_compat_metrics options to allow choosing between pgs, objects, and bytes when rebalancing with crush-compat mode. Multi-values are supported, so that the placement scoring can be a function of several metrics. By default we score based on the mean of pgs, objects, and bytes scores for all roots. Signed-off-by: Dan van der Ster (cherry picked from commit 1f6866c15307a2a681d0e5c0293797da7fa5d1de) --- src/pybind/mgr/balancer/module.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 8f0ea5fc84a5..68fc84b9bcb6 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -206,6 +206,7 @@ class Module(MgrModule): {'name': 'active'}, {'name': 'begin_time'}, {'name': 'crush_compat_max_iterations'}, + {'name': 'crush_compat_metrics'}, {'name': 'crush_compat_step'}, {'name': 'end_time'}, {'name': 'max_misplaced'}, @@ -622,12 +623,16 @@ class Module(MgrModule): } self.log.debug('score_by_root %s' % pe.score_by_root) + # get the list of score metrics, comma separated + metrics = self.get_config('crush_compat_metrics', 'pgs,objects,bytes').split(',') + # total score is just average of normalized stddevs pe.score = 0.0 for r, vs in six.iteritems(pe.score_by_root): for k, v in six.iteritems(vs): - pe.score += v - pe.score /= 3 * len(roots) + if k in metrics: + pe.score += v + pe.score /= len(metrics) * len(roots) return pe def evaluate(self, ms, pools, verbose=False): @@ -772,7 +777,12 @@ class Module(MgrModule): self.log.error(detail) return -errno.EOPNOTSUPP, detail - key = 'pgs' # pgs objects or bytes + # rebalance by pgs, objects, or bytes + metrics = self.get_config('crush_compat_metrics', 'pgs,objects,bytes').split(',') + key = metrics[0] # balancing using the first score metric + if key not in ['pgs', 'bytes', 'objects']: + self.log.warn("Invalid crush_compat balancing key %s. Using 'pgs'." % key) + key = 'pgs' # go best_ws = copy.deepcopy(orig_ws) -- 2.47.3