mirror of
https://github.com/ceph/ceph
synced 2025-01-19 01:21:49 +00:00
mgr: replace iteritems with six.iteritems (balancer)
Fixes: http://tracker.ceph.com/issues/24779 Signed-off-by: Nathan Cutler <ncutler@suse.com>
This commit is contained in:
parent
0e76e87d35
commit
962f0c416c
@ -8,6 +8,7 @@ import errno
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
import six
|
||||
import time
|
||||
from mgr_module import MgrModule, CommandResult
|
||||
from threading import Event
|
||||
@ -38,13 +39,13 @@ class MappingState:
|
||||
self.pg_up_by_poolid = {}
|
||||
for poolid in self.poolids:
|
||||
self.pg_up_by_poolid[poolid] = osdmap.map_pool_pgs_up(poolid)
|
||||
for a,b in self.pg_up_by_poolid[poolid].iteritems():
|
||||
for a,b in six.iteritems(self.pg_up_by_poolid[poolid]):
|
||||
self.pg_up[a] = b
|
||||
|
||||
def calc_misplaced_from(self, other_ms):
|
||||
num = len(other_ms.pg_up)
|
||||
misplaced = 0
|
||||
for pgid, before in other_ms.pg_up.iteritems():
|
||||
for pgid, before in six.iteritems(other_ms.pg_up):
|
||||
if before != self.pg_up.get(pgid, []):
|
||||
misplaced += 1
|
||||
if num > 0:
|
||||
@ -81,10 +82,10 @@ class Plan:
|
||||
if len(self.compat_ws) and \
|
||||
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():
|
||||
for osd, weight in six.iteritems(self.compat_ws):
|
||||
ls.append('ceph osd crush weight-set reweight-compat %s %f' %
|
||||
(osd, weight))
|
||||
for osd, weight in self.osd_weights.iteritems():
|
||||
for osd, weight in six.iteritems(self.osd_weights):
|
||||
ls.append('ceph osd reweight osd.%d %f' % (osd, weight))
|
||||
incdump = self.inc.dump()
|
||||
for pgid in incdump.get('old_pg_upmap_items', []):
|
||||
@ -160,7 +161,7 @@ class Eval:
|
||||
score = 0.0
|
||||
sum_weight = 0.0
|
||||
|
||||
for k, v in count[t].iteritems():
|
||||
for k, v in six.iteritems(count[t]):
|
||||
# adjust/normalize by weight
|
||||
if target[k]:
|
||||
adjusted = float(v) / target[k] / float(num)
|
||||
@ -481,12 +482,12 @@ class Module(MgrModule):
|
||||
weight_map = ms.crush.get_take_weight_osd_map(rootid)
|
||||
adjusted_map = {
|
||||
osd: cw * osd_weight[osd]
|
||||
for osd,cw in weight_map.iteritems() if osd in osd_weight and cw > 0
|
||||
for osd,cw in six.iteritems(weight_map) if osd in osd_weight and cw > 0
|
||||
}
|
||||
sum_w = sum(adjusted_map.values())
|
||||
assert len(adjusted_map) == 0 or sum_w > 0
|
||||
pe.target_by_root[root] = { osd: w / sum_w
|
||||
for osd,w in adjusted_map.iteritems() }
|
||||
for osd,w in six.iteritems(adjusted_map) }
|
||||
actual_by_root[root] = {
|
||||
'pgs': {},
|
||||
'objects': {},
|
||||
@ -506,7 +507,7 @@ class Module(MgrModule):
|
||||
self.log.debug('target_by_root %s' % pe.target_by_root)
|
||||
|
||||
# pool and root actual
|
||||
for pool, pi in pool_info.iteritems():
|
||||
for pool, pi in six.iteritems(pool_info):
|
||||
poolid = pi['pool']
|
||||
pm = ms.pg_up_by_poolid[poolid]
|
||||
pgs = 0
|
||||
@ -520,7 +521,7 @@ class Module(MgrModule):
|
||||
pgs_by_osd[osd] = 0
|
||||
objects_by_osd[osd] = 0
|
||||
bytes_by_osd[osd] = 0
|
||||
for pgid, up in pm.iteritems():
|
||||
for pgid, up in six.iteritems(pm):
|
||||
for osd in [int(osd) for osd in up]:
|
||||
if osd == CRUSHMap.ITEM_NONE:
|
||||
continue
|
||||
@ -546,29 +547,29 @@ class Module(MgrModule):
|
||||
pe.count_by_pool[pool] = {
|
||||
'pgs': {
|
||||
k: v
|
||||
for k, v in pgs_by_osd.iteritems()
|
||||
for k, v in six.iteritems(pgs_by_osd)
|
||||
},
|
||||
'objects': {
|
||||
k: v
|
||||
for k, v in objects_by_osd.iteritems()
|
||||
for k, v in six.iteritems(objects_by_osd)
|
||||
},
|
||||
'bytes': {
|
||||
k: v
|
||||
for k, v in bytes_by_osd.iteritems()
|
||||
for k, v in six.iteritems(bytes_by_osd)
|
||||
},
|
||||
}
|
||||
pe.actual_by_pool[pool] = {
|
||||
'pgs': {
|
||||
k: float(v) / float(max(pgs, 1))
|
||||
for k, v in pgs_by_osd.iteritems()
|
||||
for k, v in six.iteritems(pgs_by_osd)
|
||||
},
|
||||
'objects': {
|
||||
k: float(v) / float(max(objects, 1))
|
||||
for k, v in objects_by_osd.iteritems()
|
||||
for k, v in six.iteritems(objects_by_osd)
|
||||
},
|
||||
'bytes': {
|
||||
k: float(v) / float(max(bytes, 1))
|
||||
for k, v in bytes_by_osd.iteritems()
|
||||
for k, v in six.iteritems(bytes_by_osd)
|
||||
},
|
||||
}
|
||||
pe.total_by_pool[pool] = {
|
||||
@ -580,29 +581,29 @@ class Module(MgrModule):
|
||||
pe.count_by_root[root] = {
|
||||
'pgs': {
|
||||
k: float(v)
|
||||
for k, v in actual_by_root[root]['pgs'].iteritems()
|
||||
for k, v in six.iteritems(actual_by_root[root]['pgs'])
|
||||
},
|
||||
'objects': {
|
||||
k: float(v)
|
||||
for k, v in actual_by_root[root]['objects'].iteritems()
|
||||
for k, v in six.iteritems(actual_by_root[root]['objects'])
|
||||
},
|
||||
'bytes': {
|
||||
k: float(v)
|
||||
for k, v in actual_by_root[root]['bytes'].iteritems()
|
||||
for k, v in six.iteritems(actual_by_root[root]['bytes'])
|
||||
},
|
||||
}
|
||||
pe.actual_by_root[root] = {
|
||||
'pgs': {
|
||||
k: float(v) / float(max(pe.total_by_root[root]['pgs'], 1))
|
||||
for k, v in actual_by_root[root]['pgs'].iteritems()
|
||||
for k, v in six.iteritems(actual_by_root[root]['pgs'])
|
||||
},
|
||||
'objects': {
|
||||
k: float(v) / float(max(pe.total_by_root[root]['objects'], 1))
|
||||
for k, v in actual_by_root[root]['objects'].iteritems()
|
||||
for k, v in six.iteritems(actual_by_root[root]['objects'])
|
||||
},
|
||||
'bytes': {
|
||||
k: float(v) / float(max(pe.total_by_root[root]['bytes'], 1))
|
||||
for k, v in actual_by_root[root]['bytes'].iteritems()
|
||||
for k, v in six.iteritems(actual_by_root[root]['bytes'])
|
||||
},
|
||||
}
|
||||
self.log.debug('actual_by_pool %s' % pe.actual_by_pool)
|
||||
@ -614,7 +615,7 @@ class Module(MgrModule):
|
||||
b,
|
||||
pe.target_by_root[a],
|
||||
pe.total_by_root[a]
|
||||
) for a, b in pe.count_by_root.iteritems()
|
||||
) for a, b in six.iteritems(pe.count_by_root)
|
||||
}
|
||||
self.log.debug('stats_by_root %s' % pe.stats_by_root)
|
||||
|
||||
@ -630,8 +631,8 @@ class Module(MgrModule):
|
||||
|
||||
# total score is just average of normalized stddevs
|
||||
pe.score = 0.0
|
||||
for r, vs in pe.score_by_root.iteritems():
|
||||
for k, v in vs.iteritems():
|
||||
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)
|
||||
return pe
|
||||
@ -749,14 +750,14 @@ class Module(MgrModule):
|
||||
# get current osd reweights
|
||||
orig_osd_weight = { a['osd']: a['weight']
|
||||
for a in ms.osdmap_dump.get('osds',[]) }
|
||||
reweighted_osds = [ a for a,b in orig_osd_weight.iteritems()
|
||||
reweighted_osds = [ a for a,b in six.iteritems(orig_osd_weight)
|
||||
if b < 1.0 and b > 0.0 ]
|
||||
|
||||
# get current compat weight-set weights
|
||||
orig_ws = self.get_compat_weight_set_weights(ms)
|
||||
if not orig_ws:
|
||||
return -errno.EAGAIN, 'compat weight-set not available'
|
||||
orig_ws = { a: b for a, b in orig_ws.iteritems() if a >= 0 }
|
||||
orig_ws = { a: b for a, b in six.iteritems(orig_ws) if a >= 0 }
|
||||
|
||||
# Make sure roots don't overlap their devices. If so, we
|
||||
# can't proceed.
|
||||
@ -765,7 +766,7 @@ class Module(MgrModule):
|
||||
visited = {}
|
||||
overlap = {}
|
||||
root_ids = {}
|
||||
for root, wm in pe.target_by_root.iteritems():
|
||||
for root, wm in six.iteritems(pe.target_by_root):
|
||||
for osd in wm.iterkeys():
|
||||
if osd in visited:
|
||||
if osd not in overlap:
|
||||
@ -837,7 +838,7 @@ class Module(MgrModule):
|
||||
|
||||
# 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()
|
||||
root_sum = sum(b for a,b in six.iteritems(next_ws)
|
||||
if a in target.keys())
|
||||
if root_sum > 0 and root_weight > 0:
|
||||
factor = root_sum / root_weight
|
||||
@ -894,7 +895,7 @@ class Module(MgrModule):
|
||||
if best_pe.score < pe.score + fudge:
|
||||
self.log.info('Success, score %f -> %f', pe.score, best_pe.score)
|
||||
plan.compat_ws = best_ws
|
||||
for osd, w in best_ow.iteritems():
|
||||
for osd, w in six.iteritems(best_ow):
|
||||
if w != orig_osd_weight[osd]:
|
||||
self.log.debug('osd.%d reweight %f', osd, w)
|
||||
plan.osd_weights[osd] = w
|
||||
@ -981,7 +982,7 @@ class Module(MgrModule):
|
||||
self.log.error('Error creating compat weight-set')
|
||||
return r, outs
|
||||
|
||||
for osd, weight in plan.compat_ws.iteritems():
|
||||
for osd, weight in six.iteritems(plan.compat_ws):
|
||||
self.log.info('ceph osd crush weight-set reweight-compat osd.%d %f',
|
||||
osd, weight)
|
||||
result = CommandResult('')
|
||||
@ -995,7 +996,7 @@ class Module(MgrModule):
|
||||
|
||||
# new_weight
|
||||
reweightn = {}
|
||||
for osd, weight in plan.osd_weights.iteritems():
|
||||
for osd, weight in six.iteritems(plan.osd_weights):
|
||||
reweightn[str(osd)] = str(int(weight * float(0x10000)))
|
||||
if len(reweightn):
|
||||
self.log.info('ceph osd reweightn %s', reweightn)
|
||||
|
Loading…
Reference in New Issue
Block a user