From 11720b96ec8f9ef683710dffa3da4cda2ecf096d Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 8 Aug 2017 16:36:23 -0400 Subject: [PATCH] pybind/mgr/balancer: make auto mode work (with upmap at least) Signed-off-by: Sage Weil (cherry picked from commit ef1a3be05671ad31907cf8c4beb64a766359bc66) --- src/pybind/mgr/balancer/module.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index b433007afa5b4..d1133e6cbafc5 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -16,7 +16,7 @@ default_mode = 'none' 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: @@ -312,9 +312,11 @@ class Module(MgrModule): 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() @@ -536,13 +538,14 @@ class Module(MgrModule): 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 ## @@ -555,7 +558,7 @@ class Module(MgrModule): 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) @@ -570,6 +573,7 @@ class Module(MgrModule): 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') @@ -597,7 +601,7 @@ class Module(MgrModule): 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 @@ -623,6 +627,7 @@ class Module(MgrModule): 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') -- 2.39.5