Skip to content

Commit f3c74a7

Browse files
author
Laura Flores
committed
mgr/balancer: add pg_upmap_primaries to balancer status detail
Followup to ceph@8a55535. Streamlines some of the logic so pg upmap activity is properly initalized, and updated in offline mode as well as online. Signed-off-by: Laura Flores <[email protected]>
1 parent 61e721c commit f3c74a7

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/pybind/mgr/balancer/module.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,11 @@ class Module(MgrModule):
340340
success_string = 'Optimization plan created successfully'
341341
in_progress_string = 'in progress'
342342
last_pg_upmap: List[Dict[str, Any]] = []
343-
added_pg_upmap_items: List[Dict[str, Any]] = []
344-
removed_pg_upmap_items: List[Dict[str, Any]] = []
343+
pg_upmap_items_added: List[Dict[str, Any]] = []
344+
pg_upmap_items_removed: List[Dict[str, Any]] = []
345+
last_pg_upmap_primaries: List[Dict[str, Any]] = []
346+
pg_upmap_primaries_added: List[Dict[str, Any]] = []
347+
pg_upmap_activity_initalized = False
345348

346349
def __init__(self, *args: Any, **kwargs: Any) -> None:
347350
super(Module, self).__init__(*args, **kwargs)
@@ -376,10 +379,12 @@ def show_status_detail(self) -> Tuple[int, str, str]:
376379
'optimize_result': self.optimize_result,
377380
'no_optimization_needed': self.no_optimization_needed,
378381
'mode': self.get_module_option('mode'),
379-
'added_pg_upmap_items': self.added_pg_upmap_items,
380-
'removed_pg_upmap_items': self.removed_pg_upmap_items,
382+
'pg_upmap_items_added': self.pg_upmap_items_added,
383+
'pg_upmap_items_removed': self.pg_upmap_items_removed,
384+
'pg_upmap_primaries_added': self.pg_upmap_primaries_added,
385+
'pg_upmap_primaries_removed': self.pg_upmap_primaries_removed
381386
}
382-
return (0, json.dumps(s, indent=4), '')
387+
return (0, json.dumps(s, indent=4, sort_keys=True), '')
383388

384389
@CLICommand('balancer mode')
385390
def set_mode(self, mode: Mode) -> Tuple[int, str, str]:
@@ -660,6 +665,7 @@ def plan_execute(self, plan: str) -> Tuple[int, str, str]:
660665
if not plan_:
661666
return (-errno.ENOENT, '', f'plan {plan} not found')
662667
r, detail = self.execute(plan_)
668+
self.update_pg_upmap_activity() # update pg activity in `balancer status detail`
663669
self.plan_rm(plan)
664670
return (r, '', detail)
665671

@@ -745,15 +751,13 @@ def serve(self) -> None:
745751
start = time.time()
746752
r, detail = self.optimize(plan)
747753
end = time.time()
748-
self.added_pg_upmap_items = [pg for pg in osdmap.dump().get('pg_upmap_items', '') if pg not in self.last_pg_upmap]
749-
self.removed_pg_upmap_items = [pg for pg in self.last_pg_upmap if pg not in osdmap.dump().get('pg_upmap_items', '')]
750-
self.last_pg_upmap = osdmap.dump().get('pg_upmap_items', '')
751754
self.last_optimize_duration = str(datetime.timedelta(seconds=(end - start)))
752755
if r == 0:
753756
self.optimize_result = self.success_string
754757
self.execute(plan)
755758
else:
756759
self.optimize_result = detail
760+
self.update_pg_upmap_activity() # update pg activity in `balancer status detail`
757761
self.optimizing = False
758762
self.log.debug('Sleeping for %d', sleep_interval)
759763
self.event.wait(sleep_interval)
@@ -1578,6 +1582,23 @@ def gather_telemetry(self) -> Dict[str, Any]:
15781582
'mode': self.mode,
15791583
}
15801584

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
1591+
1592+
# 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', '')
1596+
1597+
# 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', '')
1601+
15811602
def self_test(self) -> None:
15821603
# turn balancer on
15831604
self.on()

0 commit comments

Comments
 (0)