From: xie xingguo Date: Wed, 21 Nov 2018 06:25:45 +0000 (+0800) Subject: mon: auto clean up stale upmap items X-Git-Tag: v12.2.11~109^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e33e8fb92810f8bab5d2260dcebb7f8180130cfd;p=ceph.git mon: auto clean up stale upmap items See https://www.spinics.net/lists/ceph-users/msg49518.html Signed-off-by: xie xingguo (cherry picked from commit 4181aa86906886423af80e478e45554606fc7cf6) Conflicts: - *nextmap* has been renamed to *tmpmap* - add the *have_pg_upmaps* wrapper which is necessary for unittest --- diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 3c93f1b31593..af00b1e24022 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1741,6 +1741,7 @@ void OSDMap::maybe_remove_pg_upmaps(CephContext *cct, } } } + tmpmap.clean_pg_upmaps(cct, pending_inc); } int OSDMap::apply_incremental(const Incremental &inc) @@ -3906,7 +3907,7 @@ int OSDMap::summarize_mapping_stats( int OSDMap::clean_pg_upmaps( CephContext *cct, - Incremental *pending_inc) + Incremental *pending_inc) const { ldout(cct, 10) << __func__ << dendl; int changed = 0; diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 2a5f985c5fc9..5e3fe3d28642 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -1313,7 +1313,7 @@ public: int clean_pg_upmaps( CephContext *cct, - Incremental *pending_inc); + Incremental *pending_inc) const; bool try_pg_upmap( CephContext *cct, @@ -1333,6 +1333,11 @@ public: int get_osds_by_bucket_name(const string &name, set *osds) const; + bool have_pg_upmaps(pg_t pg) const { + return pg_upmap.count(pg) || + pg_upmap_items.count(pg); + } + /* * handy helpers to build simple maps... */ diff --git a/src/test/osd/TestOSDMap.cc b/src/test/osd/TestOSDMap.cc index 6335a0542051..7a6293eaca04 100644 --- a/src/test/osd/TestOSDMap.cc +++ b/src/test/osd/TestOSDMap.cc @@ -598,6 +598,41 @@ TEST_F(OSDMapTest, CleanPGUpmaps) { ASSERT_TRUE(parent_0 != parent_1); } + { + // cancel stale upmaps + osdmap.pg_to_raw_up(pgid, &up, &up_primary); + int from = -1; + for (int i = 0; i < (int)get_num_osds(); i++) { + if (std::find(up.begin(), up.end(), i) == up.end()) { + from = i; + break; + } + } + ASSERT_TRUE(from >= 0); + int to = -1; + for (int i = 0; i < (int)get_num_osds(); i++) { + if (std::find(up.begin(), up.end(), i) == up.end() && i != from) { + to = i; + break; + } + } + ASSERT_TRUE(to >= 0); + vector> new_pg_upmap_items; + new_pg_upmap_items.push_back(make_pair(from, to)); + OSDMap::Incremental pending_inc(osdmap.get_epoch() + 1); + pending_inc.new_pg_upmap_items[pgid] = + mempool::osdmap::vector>( + new_pg_upmap_items.begin(), new_pg_upmap_items.end()); + OSDMap nextmap; + nextmap.deepish_copy_from(osdmap); + nextmap.apply_incremental(pending_inc); + ASSERT_TRUE(nextmap.have_pg_upmaps(pgid)); + OSDMap::Incremental new_pending_inc(nextmap.get_epoch() + 1); + nextmap.clean_pg_upmaps(g_ceph_context, &new_pending_inc); + nextmap.apply_incremental(new_pending_inc); + ASSERT_TRUE(!nextmap.have_pg_upmaps(pgid)); + } + { // TEST pg_upmap {