From e21e5de4ef5fc2d53f60a6b430e7589e0008558a Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 7 Jul 2020 16:14:22 +0800 Subject: [PATCH] mds/OpenFileTable: reduce anchor map lookup during prefetch reduce one anchor map lookup for each inode Signed-off-by: "Yan, Zheng" (cherry picked from commit 1adc21e1b46744fa810b9d29530a04369af303e7) --- src/mds/MDCache.cc | 10 +++++++--- src/mds/MDCache.h | 4 +++- src/mds/OpenFileTable.cc | 31 ++++++++++++++++++------------- src/mds/OpenFileTable.h | 7 ++++--- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 88eece19f00bb..869cde4bf4e2f 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -9287,7 +9287,9 @@ void MDCache::kick_open_ino_peers(mds_rank_t who) } void MDCache::open_ino(inodeno_t ino, int64_t pool, MDSContext* fin, - bool want_replica, bool want_xlocked) + bool want_replica, bool want_xlocked, + vector *ancestors_hint, + mds_rank_t auth_hint) { dout(10) << "open_ino " << ino << " pool " << pool << " want_replica " << want_replica << dendl; @@ -9320,8 +9322,10 @@ void MDCache::open_ino(inodeno_t ino, int64_t pool, MDSContext* fin, info.tid = ++open_ino_last_tid; info.pool = pool >= 0 ? pool : default_file_layout.pool_id; info.waiters.push_back(fin); - if (mds->is_rejoin() && - open_file_table.get_ancestors(ino, info.ancestors, info.auth_hint)) { + if (auth_hint != MDS_RANK_NONE) + info.auth_hint = auth_hint; + if (ancestors_hint) { + info.ancestors = std::move(*ancestors_hint); info.fetch_backtrace = false; info.checking = mds->get_nodeid(); _open_ino_traverse_dir(ino, info, 0); diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 38fac4235db4d..66c17fdd0a4f6 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -840,7 +840,9 @@ class MDCache { void kick_open_ino_peers(mds_rank_t who); void open_ino(inodeno_t ino, int64_t pool, MDSContext *fin, - bool want_replica=true, bool want_xlocked=false); + bool want_replica=true, bool want_xlocked=false, + vector *ancestors_hint=nullptr, + mds_rank_t auth_hint=MDS_RANK_NONE); void find_ino_peers(inodeno_t ino, MDSContext *c, mds_rank_t hint=MDS_RANK_NONE, bool path_locked=false); diff --git a/src/mds/OpenFileTable.cc b/src/mds/OpenFileTable.cc index 9b5e73bc4a0ba..fba4afd9381a3 100644 --- a/src/mds/OpenFileTable.cc +++ b/src/mds/OpenFileTable.cc @@ -975,23 +975,19 @@ void OpenFileTable::load(MDSContext *onload) new C_OnFinisher(c, mds->finisher)); } -bool OpenFileTable::get_ancestors(inodeno_t ino, vector& ancestors, - mds_rank_t& auth_hint) +void OpenFileTable::_get_ancestors(const Anchor& parent, + vector& ancestors, + mds_rank_t& auth_hint) { - auto p = loaded_anchor_map.find(ino); - if (p == loaded_anchor_map.end()) - return false; - - inodeno_t dirino = p->second.dirino; - if (dirino == inodeno_t(0)) - return false; + inodeno_t dirino = parent.dirino; + std::string_view d_name = parent.d_name; bool first = true; ancestors.clear(); while (true) { - ancestors.push_back(inode_backpointer_t(dirino, p->second.d_name, 0)); + ancestors.push_back(inode_backpointer_t(dirino, string{d_name}, 0)); - p = loaded_anchor_map.find(dirino); + auto p = loaded_anchor_map.find(dirino); if (p == loaded_anchor_map.end()) break; @@ -999,12 +995,12 @@ bool OpenFileTable::get_ancestors(inodeno_t ino, vector& an auth_hint = p->second.auth; dirino = p->second.dirino; + d_name = p->second.d_name; if (dirino == inodeno_t(0)) break; first = false; } - return true; } class C_OFT_OpenInoFinish: public MDSContext { @@ -1156,7 +1152,16 @@ void OpenFileTable::_prefetch_inodes() continue; num_opening_inodes++; - mdcache->open_ino(it.first, pool, new C_OFT_OpenInoFinish(this, it.first), false); + + auto fin = new C_OFT_OpenInoFinish(this, it.first); + if (it.second.dirino != inodeno_t(0)) { + vector ancestors; + mds_rank_t auth_hint = MDS_RANK_NONE; + _get_ancestors(it.second, ancestors, auth_hint); + mdcache->open_ino(it.first, pool, fin, false, false, &ancestors, auth_hint); + } else { + mdcache->open_ino(it.first, pool, fin, false); + } if (!(num_opening_inodes % 1000)) mds->heartbeat_reset(); diff --git a/src/mds/OpenFileTable.h b/src/mds/OpenFileTable.h index ced86afae1ba6..ebf7feff67beb 100644 --- a/src/mds/OpenFileTable.h +++ b/src/mds/OpenFileTable.h @@ -50,9 +50,6 @@ public: waiting_for_load.push_back(c); } - bool get_ancestors(inodeno_t ino, vector& ancestors, - mds_rank_t& auth_hint); - bool prefetch_inodes(); bool is_prefetched() const { return prefetch_state == DONE; } void wait_for_prefetch(MDSContext *c) { @@ -106,6 +103,10 @@ protected: void _prefetch_inodes(); void _prefetch_dirfrags(); + void _get_ancestors(const Anchor& parent, + vector& ancestors, + mds_rank_t& auth_hint); + MDSRank *mds; version_t omap_version = 0; -- 2.39.5