From 0364b3f173e5366eb0b8b5381a2855afd5ab8733 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 15 Mar 2017 18:08:30 -0400 Subject: [PATCH] osd/OSDMap: clean_pg_remaps Helper to clean out no-op pg_remap cruft: - pg_remap entries that match the raw result - pg_remap_items entries where the 'from' part of the (from,to) set isn't present. Signed-off-by: Sage Weil --- src/osd/OSDMap.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ src/osd/OSDMap.h | 3 +++ 2 files changed, 46 insertions(+) diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index f33ae5c1af350..c4e388f86cfba 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -3315,6 +3315,49 @@ int OSDMap::summarize_mapping_stats( return 0; } + +int OSDMap::clean_remaps( + CephContext *cct, + Incremental *pending_inc) +{ + ldout(cct, 10) << __func__ << dendl; + int changed = 0; + for (auto& p : pg_remap) { + vector raw; + int primary; + pg_to_raw_osds(p.first, &raw, &primary); + if (raw == p.second) { + ldout(cct, 10) << " removing redundant pg_remap " << p.first << " " + << p.second << dendl; + pending_inc->old_pg_remap.insert(p.first); + ++changed; + } + } + for (auto& p : pg_remap_items) { + vector raw; + int primary; + pg_to_raw_osds(p.first, &raw, &primary); + vector> newmap; + for (auto& q : p.second) { + if (std::find(raw.begin(), raw.end(), q.first) != raw.end()) { + newmap.push_back(q); + } + } + if (newmap.empty()) { + ldout(cct, 10) << " removing no-op pg_remap_items " << p.first << " " + << p.second << dendl; + pending_inc->old_pg_remap_items.insert(p.first); + ++changed; + } else if (newmap != p.second) { + ldout(cct, 10) << " simplifying partially no-op pg_remap_items " + << p.first << " " << p.second << " -> " << newmap << dendl; + pending_inc->new_pg_remap_items[p.first] = newmap; + ++changed; + } + } + return changed; +} + bool OSDMap::try_pg_remap( CephContext *cct, pg_t pg, ///< pg to potentially remap diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 4221b2e0fb34b..856793bdaa23c 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -861,6 +861,9 @@ public: return calc_pg_role(osd, group, nrep) >= 0; } + int clean_remaps( + CephContext *cct, + Incremental *pending_inc); bool try_pg_remap( CephContext *cct, -- 2.39.5