From: Yan, Zheng Date: Thu, 26 Oct 2017 00:06:27 +0000 (+0800) Subject: mds: simplify SnapRealm::build_snap_{set,trace} X-Git-Tag: v13.1.0~413^2~24 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=813ba65ecf6d5175c699844822d49453b539eafe;p=ceph.git mds: simplify SnapRealm::build_snap_{set,trace} Signed-off-by: "Yan, Zheng" --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 6cf2d31c5f7f..32874fc1fbfe 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -5557,7 +5557,7 @@ void MDCache::prepare_realm_split(SnapRealm *realm, client_t client, inodeno_t i } else { splits[client] = snap = new MClientSnap(CEPH_SNAP_OP_SPLIT); snap->head.split = realm->inode->ino(); - realm->build_snap_trace(snap->bl); + snap->bl = realm->get_snap_trace(); for (const auto& child : realm->open_children) snap->split_realms.push_back(child->inode->ino()); @@ -5572,7 +5572,6 @@ void MDCache::prepare_realm_merge(SnapRealm *realm, SnapRealm *parent_realm, vector split_inos; vector split_realms; - bufferlist snapbl; for (elist::iterator p = realm->inodes_with_caps.begin(member_offset(CInode, item_caps)); !p.end(); @@ -5582,7 +5581,6 @@ void MDCache::prepare_realm_merge(SnapRealm *realm, SnapRealm *parent_realm, p != realm->open_children.end(); ++p) split_realms.push_back((*p)->inode->ino()); - parent_realm->build_snap_trace(snapbl); for (auto p : realm->client_caps) { assert(!p.second->empty()); @@ -5592,7 +5590,7 @@ void MDCache::prepare_realm_merge(SnapRealm *realm, SnapRealm *parent_realm, update->head.split = parent_realm->inode->ino(); update->split_inos = split_inos; update->split_realms = split_realms; - update->bl = snapbl; + update->bl = parent_realm->get_snap_trace(); } } } @@ -5790,7 +5788,7 @@ void MDCache::do_cap_import(Session *session, CInode *in, Capability *cap, cap->pending(), cap->wanted(), 0, cap->get_mseq(), mds->get_osd_epoch_barrier()); in->encode_cap_message(reap, cap); - realm->build_snap_trace(reap->snapbl); + reap->snapbl = realm->get_snap_trace(); reap->set_cap_peer(p_cap_id, p_seq, p_mseq, peer, p_flags); mds->send_message_client_counted(reap, session); } else { @@ -5967,7 +5965,7 @@ void MDCache::finish_snaprealm_reconnect(client_t client, SnapRealm *realm, snap dout(10) << "finish_snaprealm_reconnect client." << client << " has old seq " << seq << " < " << realm->get_newest_seq() << " on " << *realm << dendl; MClientSnap *snap = new MClientSnap(CEPH_SNAP_OP_UPDATE); - realm->build_snap_trace(snap->bl); + snap->bl = realm->get_snap_trace(); for (const auto& child : realm->open_children) snap->split_realms.push_back(child->inode->ino()); } else { @@ -9444,7 +9442,6 @@ void MDCache::do_realm_invalidate_and_update_notify(CInode *in, int snapop, bool vector split_inos; vector split_realms; - bufferlist snapbl; if (notify_clients) { assert(in->snaprealm->have_past_parents_open()); @@ -9459,7 +9456,6 @@ void MDCache::do_realm_invalidate_and_update_notify(CInode *in, int snapop, bool ++p) split_realms.push_back((*p)->inode->ino()); } - in->snaprealm->build_snap_trace(snapbl); } set past_children; @@ -9483,7 +9479,7 @@ void MDCache::do_realm_invalidate_and_update_notify(CInode *in, int snapop, bool update->head.split = in->ino(); update->split_inos = split_inos; update->split_realms = split_realms; - update->bl = snapbl; + update->bl = in->snaprealm->get_snap_trace(); updates[p->first] = update; } } diff --git a/src/mds/SnapRealm.cc b/src/mds/SnapRealm.cc index 12f0c6914432..70a5e49c4e08 100644 --- a/src/mds/SnapRealm.cc +++ b/src/mds/SnapRealm.cc @@ -233,52 +233,56 @@ void SnapRealm::close_parents() * get list of snaps for this realm. we must include parents' snaps * for the intervals during which they were our parent. */ -void SnapRealm::build_snap_set(set &s, - snapid_t& max_seq, snapid_t& max_last_created, snapid_t& max_last_destroyed, - snapid_t first, snapid_t last) const +void SnapRealm::build_snap_set() const { - dout(10) << "build_snap_set [" << first << "," << last << "] on " << *this << dendl; + dout(10) << "build_snap_set on " << *this << dendl; - if (srnode.seq > max_seq) - max_seq = srnode.seq; - if (srnode.last_created > max_last_created) - max_last_created = srnode.last_created; + cached_seq = srnode.seq; + cached_last_created = srnode.last_created; + cached_snaps.clear(); - // include my snaps within interval [first,last] - for (auto p = srnode.snaps.lower_bound(first); // first element >= first - p != srnode.snaps.end() && p->first <= last; - ++p) - s.insert(p->first); + // include my snaps + for (const auto& p : srnode.snaps) + cached_snaps.insert(p.first); if (!srnode.past_parent_snaps.empty()) { - set snaps; - for (auto p = srnode.past_parent_snaps.lower_bound(first); // first element >= first - p != srnode.past_parent_snaps.end() && *p <= last; - ++p) { - snaps.insert(*p); + set snaps = mdcache->mds->snapclient->filter(srnode.past_parent_snaps); + if (!snaps.empty()) { + snapid_t last = *snaps.rbegin(); + cached_seq = std::max(cached_seq, last); + cached_last_created = std::max(cached_last_created, last); } - snaps = mdcache->mds->snapclient->filter(snaps); - s.insert(snaps.begin(), snaps.end()); + cached_snaps.insert(snaps.begin(), snaps.end()); } else { - // include snaps for parents during intervals that intersect [first,last] - for (map::const_iterator p = srnode.past_parents.lower_bound(first); - p != srnode.past_parents.end() && p->first >= first && p->second.first <= last; - ++p) { - const CInode *oldparent = mdcache->get_inode(p->second.ino); + // include snaps for parents + for (const auto& p : srnode.past_parents) { + const CInode *oldparent = mdcache->get_inode(p.second.ino); assert(oldparent); // call open_parents first! assert(oldparent->snaprealm); - oldparent->snaprealm->build_snap_set(s, max_seq, max_last_created, max_last_destroyed, - std::max(first, p->second.first), - std::min(last, p->first)); + + const set& snaps = oldparent->snaprealm->get_snaps(); + snapid_t last = 0; + for (auto q = snaps.lower_bound(p.second.first); + q != snaps.end() && *q <= p.first; + q++) { + cached_snaps.insert(*q); + last = *q; + } + cached_seq = std::max(cached_seq, last); + cached_last_created = std::max(cached_last_created, last); } } - if (srnode.current_parent_since <= last && parent) - parent->build_snap_set(s, max_seq, max_last_created, max_last_destroyed, - std::max(first, srnode.current_parent_since), last); + snapid_t parent_seq = parent ? parent->get_newest_seq() : snapid_t(0); + if (parent_seq >= srnode.current_parent_since) { + auto& snaps = parent->get_snaps(); + auto p = snaps.lower_bound(srnode.current_parent_since); + cached_snaps.insert(p, snaps.end()); + cached_seq = std::max(cached_seq, parent_seq); + cached_last_created = std::max(cached_last_created, parent->get_last_created()); + } } - void SnapRealm::check_cache() const { assert(have_past_parents_open()); @@ -287,17 +291,12 @@ void SnapRealm::check_cache() const cached_last_destroyed == last_destroyed) return; - cached_snaps.clear(); cached_snap_context.clear(); - cached_last_created = srnode.last_created; - cached_seq = srnode.seq; cached_last_destroyed = last_destroyed; - build_snap_set(cached_snaps, cached_seq, cached_last_created, cached_last_destroyed, - 0, CEPH_NOSNAP); + build_snap_set(); - cached_snap_trace.clear(); - build_snap_trace(cached_snap_trace); + build_snap_trace(); dout(10) << "check_cache rebuilt " << cached_snaps << " seq " << srnode.seq @@ -580,16 +579,17 @@ void SnapRealm::merge_to(SnapRealm *newparent) inode->close_snaprealm(); } -const bufferlist& SnapRealm::get_snap_trace() +const bufferlist& SnapRealm::get_snap_trace() const { check_cache(); return cached_snap_trace; } -void SnapRealm::build_snap_trace(bufferlist& snapbl) const +void SnapRealm::build_snap_trace() const { - SnapRealmInfo info(inode->ino(), srnode.created, srnode.seq, srnode.current_parent_since); + cached_snap_trace.clear(); + SnapRealmInfo info(inode->ino(), srnode.created, srnode.seq, srnode.current_parent_since); if (parent) { info.h.parent = parent->inode->ino(); @@ -597,9 +597,16 @@ void SnapRealm::build_snap_trace(bufferlist& snapbl) const if (!srnode.past_parent_snaps.empty()) { past = mdcache->mds->snapclient->filter(srnode.past_parent_snaps); } else if (!srnode.past_parents.empty()) { - snapid_t last = srnode.past_parents.rbegin()->first; - snapid_t max_seq, max_last_created, max_last_destroyed; - build_snap_set(past, max_seq, max_last_created, max_last_destroyed, 0, last); + const set& snaps = get_snaps(); + for (const auto& p : srnode.past_parents) { + for (auto q = snaps.lower_bound(p.second.first); + q != snaps.end() && *q <= p.first; + q++) { + if (srnode.snaps.count(*q)) + continue; + past.insert(*q); + } + } } if (!past.empty()) { @@ -619,10 +626,10 @@ void SnapRealm::build_snap_trace(bufferlist& snapbl) const info.my_snaps.push_back(p->first); dout(10) << "build_snap_trace my_snaps " << info.my_snaps << dendl; - encode(info, snapbl); + encode(info, cached_snap_trace); if (parent) - parent->build_snap_trace(snapbl); + cached_snap_trace.append(parent->get_snap_trace()); } void SnapRealm::prune_past_parents() diff --git a/src/mds/SnapRealm.h b/src/mds/SnapRealm.h index 722fdde52dc1..a3259d6ded7b 100644 --- a/src/mds/SnapRealm.h +++ b/src/mds/SnapRealm.h @@ -88,13 +88,11 @@ public: !srnode.past_parents.empty(); } - void build_snap_set(set& s, - snapid_t& max_seq, snapid_t& max_last_created, snapid_t& max_last_destroyed, - snapid_t first, snapid_t last) const; + void build_snap_set() const; void get_snap_info(map& infomap, snapid_t first=0, snapid_t last=CEPH_NOSNAP); - const bufferlist& get_snap_trace(); - void build_snap_trace(bufferlist& snapbl) const; + const bufferlist& get_snap_trace() const; + void build_snap_trace() const; std::string_view get_snapname(snapid_t snapid, inodeno_t atino); snapid_t resolve_snapname(std::string_view name, inodeno_t atino, snapid_t first=0, snapid_t last=CEPH_NOSNAP);