Merge pull request #20258 from tchaikov/wip-balancer-cleanup

mgr/balancer: replace magic value of -1 for DEFAULT_CHOOSE_ARGS

Reviewed-by: xie xingguo <xie.xingguo@zte.com.cn>
Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Kefu Chai 2018-02-05 10:01:11 +08:00 committed by GitHub
commit b813b13306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -77,7 +77,7 @@ class Plan:
self.initial.osdmap.get_crush_version())
ls.append('# mode %s' % self.mode)
if len(self.compat_ws) and \
'-1' not in self.initial.crush_dump.get('choose_args', {}):
not CRUSHMap.have_default_choose_args(self.initial.crush_dump):
ls.append('ceph osd crush weight-set create-compat')
for osd, weight in self.compat_ws.iteritems():
ls.append('ceph osd crush weight-set reweight-compat %s %f' %
@ -842,7 +842,7 @@ class Module(MgrModule):
return False
def get_compat_weight_set_weights(self, ms):
if '-1' not in ms.crush_dump.get('choose_args', {}):
if not CRUSHMap.have_default_choose_args(ms.crush_dump):
# enable compat weight-set first
self.log.debug('ceph osd crush weight-set create-compat')
result = CommandResult('')
@ -871,7 +871,7 @@ class Module(MgrModule):
else:
crushmap = ms.crush_dump
raw = crushmap.get('choose_args',{}).get('-1', [])
raw = CRUSHMap.get_default_choose_args(crushmap)
weight_set = {}
for b in raw:
bucket = None
@ -904,7 +904,7 @@ class Module(MgrModule):
# compat weight-set
if len(plan.compat_ws) and \
'-1' not in plan.initial.crush_dump.get('choose_args', {}):
not CRUSHMap.have_default_choose_args(plan.initial.crush_dump):
self.log.debug('ceph osd crush weight-set create-compat')
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({

View File

@ -125,6 +125,7 @@ class OSDMapIncremental(ceph_module.BasePyOSDMapIncremental):
class CRUSHMap(ceph_module.BasePyCRUSH):
ITEM_NONE = 0x7fffffff
DEFAULT_CHOOSE_ARGS = '-1'
def dump(self):
return self._dump()
@ -142,6 +143,15 @@ class CRUSHMap(ceph_module.BasePyCRUSH):
uglymap = self._get_take_weight_osd_map(root)
return { int(k): v for k, v in uglymap.get('weights', {}).iteritems() }
@staticmethod
def have_default_choose_args(dump):
return CRUSHMap.DEFAULT_CHOOSE_ARGS in dump.get('choose_args', {})
@staticmethod
def get_default_choose_args(dump):
return dump.get('choose_args').get(CRUSHMap.DEFAULT_CHOOSE_ARGS, [])
class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
"""
Standby modules only implement a serve and shutdown method, they