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 Sep 6, 2017
1 parent c09308c commit ef1a3be
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 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

0 comments on commit ef1a3be

Please sign in to comment.