run = True
plans = {}
mode = ''
+ optimizing = False
def __init__(self, *args, **kwargs):
super(Module, self).__init__(*args, **kwargs)
'current cluster')
return (0, self.evaluate(ms, pools, verbose=verbose), '')
elif command['prefix'] == 'balancer optimize':
+ # The GIL can be release by the active balancer, so disallow when active
+ if self.active:
+ return (-errno.EINVAL, '', 'Balancer enabled, disable to optimize manually')
+ if self.optimizing:
+ return (-errno.EINVAL, '', 'Balancer finishing up....try again')
pools = []
if 'pools' in command:
pools = command['pools']
return (-errno.EINVAL, '', 'pools %s not found' % invalid_pool_names)
plan = self.plan_create(command['plan'], osdmap, pools)
r, detail = self.optimize(plan)
- # remove plan if we are currently unable to find an optimization
- # or distribution is already perfect
- if r:
- self.plan_rm(command['plan'])
+ # Add plan if an optimization was created
+ if not r:
+ self.plans[command['plan']] = plan
return (r, '', detail)
elif command['prefix'] == 'balancer rm':
self.plan_rm(command['plan'])
return (-errno.ENOENT, '', 'plan %s not found' % command['plan'])
return (0, plan.show(), '')
elif command['prefix'] == 'balancer execute':
+ # The GIL can be release by the active balancer, so disallow when active
+ if self.active:
+ return (-errno.EINVAL, '', 'Balancer enabled, disable to execute a plan')
+ if self.optimizing:
+ return (-errno.EINVAL, '', 'Balancer finishing up....try again')
plan = self.plans.get(command['plan'])
if not plan:
return (-errno.ENOENT, '', 'plan %s not found' % command['plan'])
final = [int(p) for p in final]
final = [pool_name_by_id[p] for p in final if p in pool_name_by_id]
plan = self.plan_create(name, osdmap, final)
+ self.optimizing = True
r, detail = self.optimize(plan)
if r == 0:
self.execute(plan)
- self.plan_rm(name)
+ self.optimizing = False
self.log.debug('Sleeping for %d', sleep_interval)
self.event.wait(sleep_interval)
self.event.clear()
self.get("pg_dump"),
'plan %s initial' % name),
pools)
- self.plans[name] = plan
return plan
def plan_rm(self, name):