From 976a40c47712ca0935823e9e707505e7c8dbbe98 Mon Sep 17 00:00:00 2001 From: Neha Ojha Date: Tue, 9 Mar 2021 00:48:58 +0000 Subject: [PATCH] pybind/mgr/balancer/module.py: assign weight-sets to all buckets before balancing Add an additional check to make sure that the choose_args section has the same number of buckets as the crushmap. If not, ensure that get_compat_weight_set_weights assigns weight-sets to all buckets. Without this change, if we end up with an orig_ws, which has fewer buckets than the crushmap, the mgr will crash due a KeyError in do_crush_compat(). Fixes: https://tracker.ceph.com/issues/49576 Signed-off-by: Neha Ojha (cherry picked from commit 42c01f0c3932f7a9157797013e5db2e03d9c1fd9) Conflicts: src/pybind/mgr/balancer/module.py - trivial resolution --- src/pybind/mgr/balancer/module.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index acca915dceda3..503179b52747e 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -1180,8 +1180,13 @@ class Module(MgrModule): 'change balancer mode and retry might help' def get_compat_weight_set_weights(self, ms): - if not CRUSHMap.have_default_choose_args(ms.crush_dump): + have_choose_args = CRUSHMap.have_default_choose_args(ms.crush_dump) + if have_choose_args: + # get number of buckets in choose_args + choose_args_len = len(CRUSHMap.get_default_choose_args(ms.crush_dump)) + if not have_choose_args or choose_args_len != len(ms.crush_dump['buckets']): # enable compat weight-set first + self.log.debug('no choose_args or all buckets do not have weight-sets') self.log.debug('ceph osd crush weight-set create-compat') result = CommandResult('') self.send_command(result, 'mon', '', json.dumps({ -- 2.39.5