From 97562e100ee757c5e5c87902acf57f3d5bdaefd7 Mon Sep 17 00:00:00 2001 From: simon gao Date: Wed, 13 Nov 2019 05:51:07 -0500 Subject: [PATCH] mds: optimize function, fragset_t::simplify, to improve the efficiency of merging fragment Signed-off-by: simon gao --- src/include/frag.h | 39 +++++++++++++++++++++------------------ src/mds/MDCache.cc | 7 ++++--- src/mds/Migrator.cc | 4 ++-- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/include/frag.h b/src/include/frag.h index 5e8b154f12fa1..de532d63af447 100644 --- a/src/include/frag.h +++ b/src/include/frag.h @@ -159,7 +159,13 @@ public: decode_raw(v, p); _enc = v; } - + bool operator<(const frag_t& b) const + { + if (value() != b.value()) + return value() < b.value(); + else + return bits() < b.bits(); + } private: _frag_t _enc = 0; }; @@ -546,7 +552,6 @@ inline std::ostream& operator<<(std::ostream& out, const fragtree_t& ft) return out << ")"; } - /** * fragset_t -- a set of fragments */ @@ -567,29 +572,27 @@ public: f = f.parent(); } } - + + void insert_raw(frag_t f){ + _set.insert(f); + } void insert(frag_t f) { _set.insert(f); simplify(); } void simplify() { - while (1) { - bool clean = true; - std::set::iterator p = _set.begin(); - while (p != _set.end()) { - if (!p->is_root() && - _set.count(p->get_sibling())) { - _set.erase(p->get_sibling()); - _set.insert(p->parent()); - _set.erase(p++); - clean = false; - } else { - p++; - } + auto it = _set.begin(); + while (it != _set.end()) { + if (!it->is_root() && + _set.count(it->get_sibling())) { + _set.erase(it->get_sibling()); + auto ret = _set.insert(it->parent()); + _set.erase(it); + it = ret.first; + } else { + ++it; } - if (clean) - break; } } }; diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 41d0411352a1b..0e54d2740b3e8 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -1129,11 +1129,12 @@ void MDCache::get_force_dirfrag_bound_set(const vector& dfs, set byino; for (auto& frag : dfs) { - byino[frag.ino].insert(frag.frag); + byino[frag.ino].insert_raw(frag.frag); } dout(10) << " by ino: " << byino << dendl; for (map::iterator p = byino.begin(); p != byino.end(); ++p) { + p->second.simplify(); CInode *diri = get_inode(p->first); if (!diri) continue; @@ -1190,13 +1191,13 @@ void MDCache::map_dirfrag_set(const list& dfs, set& result) // group by inode map ino_fragset; for (const auto &df : dfs) { - ino_fragset[df.ino].insert(df.frag); + ino_fragset[df.ino].insert_raw(df.frag); } - // get frags for (map::iterator p = ino_fragset.begin(); p != ino_fragset.end(); ++p) { + p->second.simplify(); CInode *in = get_inode(p->first); if (!in) continue; diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index a9b6b80b7f0c1..c977d9b9f8425 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -2483,9 +2483,8 @@ void Migrator::handle_export_prep(const cref_t &m, bool did_assi map import_bound_fragset; for (const auto &bound : m->get_bounds()) { dout(10) << " bound " << bound << dendl; - import_bound_fragset[bound.ino].insert(bound.frag); + import_bound_fragset[bound.ino].insert_raw(bound.frag); } - // assimilate contents? if (!did_assim) { dout(7) << "doing assim on " << *dir << dendl; @@ -2515,6 +2514,7 @@ void Migrator::handle_export_prep(const cref_t &m, bool did_assi for (map::iterator p = import_bound_fragset.begin(); p != import_bound_fragset.end(); ++p) { + p->second.simplify(); CInode *in = cache->get_inode(p->first); ceph_assert(in); in->get_stickydirs(); -- 2.39.5