Skip to content

Commit

Permalink
Merge pull request #20788 from xiexingguo/wip-balancer-04
Browse files Browse the repository at this point in the history
pybind/mgr/balancer: two more fixes

Reviewed-by: xie xingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
tchaikov committed Mar 9, 2018
2 parents b296f5c + 1e3498a commit 8426e1b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/pybind/mgr/balancer/module.py
Expand Up @@ -143,6 +143,15 @@ def calc_stats(self, count, target, total):
num = max(len(target), 1)
r = {}
for t in ('pgs', 'objects', 'bytes'):
if total[t] == 0:
r[t] = {
'avg': 0,
'stddev': 0,
'sum_weight': 0,
'score': 0,
}
continue

avg = float(total[t]) / float(num)
dev = 0.0

Expand Down Expand Up @@ -426,7 +435,7 @@ def calc_eval(self, ms, pools):
self.log.debug('pool_rule %s' % pool_rule)

osd_weight = { a['osd']: a['weight']
for a in ms.osdmap_dump.get('osds',[]) }
for a in ms.osdmap_dump.get('osds',[]) if a['weight'] > 0 }

# get expected distributions by root
actual_by_root = {}
Expand All @@ -450,10 +459,11 @@ def calc_eval(self, ms, pools):
roots.append(root)
weight_map = ms.crush.get_take_weight_osd_map(rootid)
adjusted_map = {
osd: cw * osd_weight.get(osd, 1.0)
for osd,cw in weight_map.iteritems()
osd: cw * osd_weight[osd]
for osd,cw in weight_map.iteritems() if osd in osd_weight and cw > 0
}
sum_w = sum(adjusted_map.values()) or 1.0
sum_w = sum(adjusted_map.values())
assert sum_w > 0
pe.target_by_root[root] = { osd: w / sum_w
for osd,w in adjusted_map.iteritems() }
actual_by_root[root] = {
Expand Down Expand Up @@ -545,7 +555,7 @@ def calc_eval(self, ms, pools):
'objects': objects,
'bytes': bytes,
}
for root, m in pe.total_by_root.iteritems():
for root in pe.total_by_root.iterkeys():
pe.count_by_root[root] = {
'pgs': {
k: float(v)
Expand Down

0 comments on commit 8426e1b

Please sign in to comment.