From: Laura Flores Date: Wed, 13 Sep 2023 19:57:07 +0000 (+0000) Subject: osd: fix read balancer logic to avoid redundant primary assignment X-Git-Tag: v19.0.0~350^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=47c5ba25ed0db0fd307f0d4a1717ff8418004b8e;p=ceph-ci.git osd: fix read balancer logic to avoid redundant primary assignment Fixes: https://tracker.ceph.com/issues/62833 Signed-off-by: Laura Flores --- diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 29af378f965..b9f1906b491 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -4993,17 +4993,16 @@ int OSDMap::balance_primaries( map> acting_prims_by_osd; pgs_by_osd = tmp_osd_map.get_pgs_by_osd(cct, pid, &prim_pgs_by_osd, &acting_prims_by_osd); - // Transfer pgs into a map, `pgs_to_check`. This will tell us the total num_changes after all - // calculations have been finalized. - // Transfer osds into a set, `osds_to_check`. - // This is to avoid poor runtime when we loop through the pgs and to set up - // our call to calc_desired_primary_distribution. + // Construct information about the pgs and osds we will consider in new primary mappings, + // as well as a map of all pgs and their original primary osds. map prim_pgs_to_check; vector osds_to_check; + map orig_prims; for (const auto & [osd, pgs] : prim_pgs_by_osd) { osds_to_check.push_back(osd); for (const auto & pg : pgs) { prim_pgs_to_check.insert({pg, false}); + orig_prims.insert({pg, osd}); } } @@ -5077,9 +5076,14 @@ int OSDMap::balance_primaries( prim_dist_scores[up_primary] -= 1; // Update the mappings - pending_inc->new_pg_upmap_primary[pg] = curr_best_osd; tmp_osd_map.pg_upmap_primaries[pg] = curr_best_osd; - prim_pgs_to_check[pg] = true; // mark that this pg changed mappings + if (curr_best_osd == orig_prims[pg]) { + pending_inc->new_pg_upmap_primary.erase(pg); + prim_pgs_to_check[pg] = false; + } else { + pending_inc->new_pg_upmap_primary[pg] = curr_best_osd; + prim_pgs_to_check[pg] = true; // mark that this pg changed mappings + } curr_num_changes++; }