Skip to content

Commit 5174b1f

Browse files
authored
Merge pull request ceph#60523 from ljflores/wip-tracker-68657
mgr/balancer: optimize 'balancer status detail'
2 parents 70458ff + c4274c0 commit 5174b1f

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

doc/rados/operations/balancer.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ To see the status in greater detail, run the following command:
247247

248248
ceph balancer status detail
249249

250+
To enable `ceph balancer status detail`, run the following command:
251+
252+
.. prompt:: bash $
253+
254+
ceph config set mgr mgr/balancer/update_pg_upmap_activity True
255+
256+
To disable `ceph balancer status detail`, run the following command:
257+
258+
.. prompt:: bash $
259+
260+
ceph config set mgr mgr/balancer/update_pg_upmap_activity False
261+
250262
To evaluate the distribution that would result from executing a specific plan,
251263
run the following command:
252264

src/pybind/mgr/balancer/module.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ class Module(MgrModule):
325325
type='str',
326326
default='',
327327
desc='pools which the automatic balancing will be limited to',
328+
runtime=True),
329+
Option(name='update_pg_upmap_activity',
330+
type='bool',
331+
default=False,
332+
desc='Updates pg_upmap activity stats to be used in `balancer status detail`',
328333
runtime=True)
329334
]
330335

@@ -339,12 +344,10 @@ class Module(MgrModule):
339344
no_optimization_needed = False
340345
success_string = 'Optimization plan created successfully'
341346
in_progress_string = 'in progress'
342-
last_pg_upmap: List[Dict[str, Any]] = []
343347
pg_upmap_items_added: List[Dict[str, Any]] = []
344348
pg_upmap_items_removed: List[Dict[str, Any]] = []
345-
last_pg_upmap_primaries: List[Dict[str, Any]] = []
346349
pg_upmap_primaries_added: List[Dict[str, Any]] = []
347-
pg_upmap_activity_initalized = False
350+
pg_upmap_primaries_removed: List[Dict[str, Any]] = []
348351

349352
def __init__(self, *args: Any, **kwargs: Any) -> None:
350353
super(Module, self).__init__(*args, **kwargs)
@@ -371,6 +374,11 @@ def show_status_detail(self) -> Tuple[int, str, str]:
371374
"""
372375
Show balancer status (detailed)
373376
"""
377+
pg_upmap_activity = cast(bool, self.get_module_option('update_pg_upmap_activity'))
378+
if not pg_upmap_activity:
379+
msg = 'This command is disabled.\n' \
380+
'To enable, run `ceph config set mgr mgr/balancer/update_pg_upmap_activity True`.\n'
381+
return 0, msg, ''
374382
s = {
375383
'plans': list(self.plans.keys()),
376384
'active': self.active,
@@ -665,7 +673,9 @@ def plan_execute(self, plan: str) -> Tuple[int, str, str]:
665673
if not plan_:
666674
return (-errno.ENOENT, '', f'plan {plan} not found')
667675
r, detail = self.execute(plan_)
668-
self.update_pg_upmap_activity() # update pg activity in `balancer status detail`
676+
pg_upmap_activity = cast(bool, self.get_module_option('update_pg_upmap_activity'))
677+
if pg_upmap_activity:
678+
self.update_pg_upmap_activity(plan_) # update pg activity in `balancer status detail`
669679
self.plan_rm(plan)
670680
return (r, '', detail)
671681

@@ -757,7 +767,9 @@ def serve(self) -> None:
757767
self.execute(plan)
758768
else:
759769
self.optimize_result = detail
760-
self.update_pg_upmap_activity() # update pg activity in `balancer status detail`
770+
pg_upmap_activity = cast(bool, self.get_module_option('update_pg_upmap_activity'))
771+
if pg_upmap_activity:
772+
self.update_pg_upmap_activity(plan) # update pg activity in `balancer status detail`
761773
self.optimizing = False
762774
self.log.debug('Sleeping for %d', sleep_interval)
763775
self.event.wait(sleep_interval)
@@ -1582,22 +1594,16 @@ def gather_telemetry(self) -> Dict[str, Any]:
15821594
'mode': self.mode,
15831595
}
15841596

1585-
def update_pg_upmap_activity(self) -> None:
1586-
osdmap = self.get_osdmap()
1587-
if not self.pg_upmap_activity_initalized:
1588-
self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '')
1589-
self.last_pg_upmap_primaries = osdmap.dump().get('pg_upmap_primaries', '')
1590-
self.pg_upmap_activity_initalized = True
1597+
def update_pg_upmap_activity(self, plan: Plan) -> None:
1598+
incdump = plan.inc.dump()
15911599

15921600
# update pg_upmap_items
1593-
self.pg_upmap_items_added = [pg for pg in osdmap.dump().get('pg_upmap_items', '') if pg not in self.last_pg_upmap]
1594-
self.pg_upmap_items_removed = [pg for pg in self.last_pg_upmap if pg not in osdmap.dump().get('pg_upmap_items', '')]
1595-
self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '')
1601+
self.pg_upmap_items_added = incdump.get('new_pg_upmap_items', [])
1602+
self.pg_upmap_items_removed = incdump.get('old_pg_upmap_items', [])
15961603

15971604
# update pg_upmap_primaries
1598-
self.pg_upmap_primaries_added = [pg for pg in osdmap.dump().get('pg_upmap_primaries', '') if pg not in self.last_pg_upmap_primaries]
1599-
self.pg_upmap_primaries_removed = [pg for pg in self.last_pg_upmap_primaries if pg not in osdmap.dump().get('pg_upmap_primaries', '')]
1600-
self.last_pg_upmap_primaries = osdmap.dump().get('pg_upmap_primaries', '')
1605+
self.pg_upmap_primaries_added = incdump.get('new_pg_upmap_primaries', [])
1606+
self.pg_upmap_primaries_removed = incdump.get('old_pg_upmap_primaries', [])
16011607

16021608
def self_test(self) -> None:
16031609
# turn balancer on

0 commit comments

Comments
 (0)