From 8beb0a9fdee4e04d371664e0d63be6e2f9a38c21 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Mon, 25 May 2020 21:48:23 +0800 Subject: [PATCH] mds: cleanup uncommitted fragments before mds goes to active Fixes: https://tracker.ceph.com/issues/45699 Signed-off-by: "Yan, Zheng" (cherry picked from commit 77eb368d2d35f2418875227fff9a34b5ef15a290) --- src/mds/MDCache.cc | 6 ++++++ src/mds/MDCache.h | 10 +++++++--- src/mds/MDSRank.cc | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 68a3299ae53a5..acf57977e1ad3 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -11959,6 +11959,12 @@ void MDCache::rollback_uncommitted_fragment(dirfrag_t basedirfrag, frag_vec_t&& } } +void MDCache::wait_for_uncommitted_fragments(MDSGather *gather) +{ + for (auto& p : uncommitted_fragments) + p.second.waiters.push_back(gather->new_sub()); +} + void MDCache::rollback_uncommitted_fragments() { dout(10) << "rollback_uncommitted_fragments: " << uncommitted_fragments.size() << " pending" << dendl; diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 5b0b361b4ffea..abe7e624855be 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -1234,12 +1234,16 @@ private: public: void wait_for_uncommitted_fragment(dirfrag_t dirfrag, MDSContext *c) { - ceph_assert(uncommitted_fragments.count(dirfrag)); - uncommitted_fragments[dirfrag].waiters.push_back(c); + uncommitted_fragments.at(dirfrag).waiters.push_back(c); } + bool is_any_uncommitted_fragment() const { + return !uncommitted_fragments.empty(); + } + void wait_for_uncommitted_fragments(MDSGather *gather); + void rollback_uncommitted_fragments(); + void split_dir(CDir *dir, int byn); void merge_dir(CInode *diri, frag_t fg); - void rollback_uncommitted_fragments(); void find_stale_fragment_freeze(); void fragment_freeze_inc_num_waiters(CDir *dir); diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index af108a99984fa..c47bd464adafc 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -1916,6 +1916,14 @@ void MDSRank::rejoin_done() mdcache->show_subtrees(); mdcache->show_cache(); + if (mdcache->is_any_uncommitted_fragment()) { + dout(1) << " waiting for uncommitted fragments" << dendl; + MDSGatherBuilder gather(g_ceph_context, new C_MDS_VoidFn(this, &MDSRank::rejoin_done)); + mdcache->wait_for_uncommitted_fragments(gather.get()); + gather.activate(); + return; + } + // funny case: is our cache empty? no subtrees? if (!mdcache->is_subtrees()) { if (whoami == 0) { -- 2.39.5