Skip to content

Commit

Permalink
pybind/mgr/balancer: make auto mode work
Browse files Browse the repository at this point in the history
(with upmap at least)

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Aug 8, 2017
1 parent 372bf39 commit 1ac2a87
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/pybind/mgr/balancer/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
default_sleep_interval = 60 # seconds
default_max_misplaced = .03 # max ratio of pgs replaced at a time

TIME_FORMAT = '%Y-%m-%d %H:%M:%S %Z'
TIME_FORMAT = '%Y-%m-%d_%H:%M:%S'


class MappingState:
Expand Down Expand Up @@ -312,9 +312,11 @@ def serve(self):
default_sleep_interval))
if self.active:
self.log.debug('Running')
plan = self.plan_create('auto-foo')
self.optimize(plan)
#self.plan_apply(plan)
name = 'auto_%s' % time.strftime(TIME_FORMAT, time.gmtime())
plan = self.plan_create(name)
if self.optimize(plan):
self.execute(plan)
self.plan_rm(name)
self.log.debug('Sleeping for %d', sleep_interval)
self.event.wait(sleep_interval)
self.event.clear()
Expand Down Expand Up @@ -536,13 +538,14 @@ def optimize(self, plan):
misplaced, max_misplaced)
else:
if plan.mode == 'upmap':
self.do_upmap(plan)
return self.do_upmap(plan)
elif plan.mode == 'crush-compat':
self.do_crush_compat(plan)
return self.do_crush_compat(plan)
elif plan.mode == 'none':
self.log.info('Idle')
else:
self.log.info('Unrecognized mode %s' % plan.mode)
return False

##

Expand All @@ -555,7 +558,7 @@ def do_upmap(self, plan):
pools = [str(i['pool_name']) for i in ms.osdmap_dump.get('pools',[])]
if len(pools) == 0:
self.log.info('no pools, nothing to do')
return
return False
# shuffle pool list so they all get equal (in)attention
random.shuffle(pools)
self.log.info('pools %s' % pools)
Expand All @@ -570,6 +573,7 @@ def do_upmap(self, plan):
if left <= 0:
break
self.log.info('prepared %d/%d changes' % (total_did, max_iterations))
return True

def do_crush_compat(self, plan):
self.log.info('do_crush_compat')
Expand Down Expand Up @@ -597,7 +601,7 @@ def do_crush_compat(self, plan):
if len(overlap) > 0:
self.log.err('error: some osds belong to multiple subtrees: %s' %
overlap)
return
return False

key = 'pgs' # pgs objects or bytes

Expand All @@ -623,6 +627,7 @@ def do_crush_compat(self, plan):
self.log.debug('Reweight osd.%d %f -> %f', osd, weight,
new_weight)
plan.compat_ws[osd] = new_weight
return True

def compat_weight_set_reweight(self, osd, new_weight):
self.log.debug('ceph osd crush weight-set reweight-compat')
Expand Down Expand Up @@ -761,7 +766,10 @@ def execute(self, plan):
'item': 'osd.%d' % osd,
'weight': [weight],
}), 'foo')
commands.append(result)
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error on command')
return

# new_weight
reweightn = {}
Expand All @@ -775,7 +783,10 @@ def execute(self, plan):
'format': 'json',
'weights': json.dumps(reweightn),
}), 'foo')
commands.append(result)
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error on command')
return

# upmap
incdump = plan.inc.dump()
Expand All @@ -787,7 +798,10 @@ def execute(self, plan):
'format': 'json',
'pgid': pgid,
}), 'foo')
commands.append(result)
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error on command')
return

for item in incdump.get('new_pg_upmap_items', []):
self.log.info('ceph osd pg-upmap-items %s mappings %s', item['pgid'],
Expand All @@ -802,13 +816,16 @@ def execute(self, plan):
'pgid': item['pgid'],
'id': osdlist,
}), 'foo')
commands.append(result)

# wait for commands
self.log.debug('commands %s' % commands)
for result in commands:
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error on command')
return

# wait for commands
#self.log.debug('commands %s' % commands)
#for result in commands:
# r, outb, outs = result.wait()
# if r != 0:
# self.log.error('Error on command')
# return
self.log.debug('done')

0 comments on commit 1ac2a87

Please sign in to comment.