From 6f1aeed7ba7c6a9f7ce39d710c48155a0436ffae Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Thu, 14 Jun 2018 17:36:19 +0800 Subject: [PATCH] mds: track snapshot count in rstat Signed-off-by: "Yan, Zheng" --- src/mds/CDir.cc | 2 +- src/mds/CInode.cc | 13 ++++++++++--- src/mds/MDCache.cc | 4 +++- src/mds/Server.cc | 4 +++- src/mds/mdstypes.cc | 12 ++++++------ src/mds/mdstypes.h | 8 ++++---- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index fc16586675a4d..cd53470c5cdf7 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -862,7 +862,7 @@ void CDir::steal_dentry(CDentry *dn) fnode.rstat.rbytes += pi->accounted_rstat.rbytes; fnode.rstat.rfiles += pi->accounted_rstat.rfiles; fnode.rstat.rsubdirs += pi->accounted_rstat.rsubdirs; - fnode.rstat.rsnaprealms += pi->accounted_rstat.rsnaprealms; + fnode.rstat.rsnaps += pi->accounted_rstat.rsnaps; if (pi->accounted_rstat.rctime > fnode.rstat.rctime) fnode.rstat.rctime = pi->accounted_rstat.rctime; diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index cd76392773801..75fad43d33f64 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -2237,13 +2237,17 @@ void CInode::finish_scatter_gather_update(int type) case CEPH_LOCK_INEST: { + // adjust summation + assert(is_auth()); + fragtree_t tmpdft = dirfragtree; nest_info_t rstat; - rstat.rsubdirs = 1; bool rstat_valid = true; - // adjust summation - assert(is_auth()); + rstat.rsubdirs = 1; + if (const sr_t *srnode = get_projected_srnode(); srnode) + rstat.rsnaps = srnode->snaps.size(); + mempool_inode *pi = get_projected_inode(); dout(20) << " orig rstat " << pi->rstat << dendl; pi->rstat.version++; @@ -4282,6 +4286,9 @@ next: } } nest_info.rsubdirs++; // it gets one to account for self + if (const sr_t *srnode = in->get_projected_srnode(); srnode) + nest_info.rsnaps += srnode->snaps.size(); + // ...and that their sum matches our inode settings if (!dir_info.same_sums(in->inode.dirstat) || !nest_info.same_sums(in->inode.rstat)) { diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 43628c36655ee..b9f2607446107 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -12608,7 +12608,9 @@ do_rdlocks: frag_info_t dir_info; nest_info_t nest_info; - nest_info.rsubdirs++; // it gets one to account for self + nest_info.rsubdirs = 1; // it gets one to account for self + if (const sr_t *srnode = diri->get_projected_srnode(); srnode) + nest_info.rsnaps = srnode->snaps.size(); diri->dirfragtree.get_leaves(frags); for (list::iterator p = frags.begin(); p != frags.end(); ++p) { diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 770a465199d07..d7a37220c8ff5 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -8445,7 +8445,7 @@ void _rollback_repair_dir(MutationRef& mut, CDir *dir, rename_rollback::drec &r, pf->rstat.rbytes += linkunlink * rstat.rbytes; pf->rstat.rfiles += linkunlink * rstat.rfiles; pf->rstat.rsubdirs += linkunlink * rstat.rsubdirs; - pf->rstat.rsnaprealms += linkunlink * rstat.rsnaprealms; + pf->rstat.rsnaps += linkunlink * rstat.rsnaps; } if (pf->fragstat.mtime == ctime) { pf->fragstat.mtime = r.dirfrag_old_mtime; @@ -9158,6 +9158,7 @@ void Server::handle_client_mksnap(MDRequestRef& mdr) auto &pi = diri->project_inode(false, true); pi.inode.ctime = pi.inode.rstat.rctime = info.stamp; + pi.inode.rstat.rsnaps++; pi.inode.version = diri->pre_dirty(); // project the snaprealm @@ -9295,6 +9296,7 @@ void Server::handle_client_rmsnap(MDRequestRef& mdr) auto &pi = diri->project_inode(false, true); pi.inode.version = diri->pre_dirty(); pi.inode.ctime = pi.inode.rstat.rctime = mdr->get_op_stamp(); + pi.inode.rstat.rsnaps--; mdr->ls = mdlog->get_current_segment(); EUpdate *le = new EUpdate(mdlog, "rmsnap"); diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc index 492a845b415f2..65e8ac0f7d4a1 100644 --- a/src/mds/mdstypes.cc +++ b/src/mds/mdstypes.cc @@ -86,7 +86,7 @@ void nest_info_t::encode(bufferlist &bl) const int64_t ranchors = 0; encode(ranchors, bl); } - encode(rsnaprealms, bl); + encode(rsnaps, bl); encode(rctime, bl); ENCODE_FINISH(bl); } @@ -102,7 +102,7 @@ void nest_info_t::decode(bufferlist::const_iterator &bl) int64_t ranchors; decode(ranchors, bl); } - decode(rsnaprealms, bl); + decode(rsnaps, bl); decode(rctime, bl); DECODE_FINISH(bl); } @@ -113,7 +113,7 @@ void nest_info_t::dump(Formatter *f) const f->dump_unsigned("rbytes", rbytes); f->dump_unsigned("rfiles", rfiles); f->dump_unsigned("rsubdirs", rsubdirs); - f->dump_unsigned("rsnaprealms", rsnaprealms); + f->dump_unsigned("rsnaps", rsnaps); f->dump_stream("rctime") << rctime; } @@ -125,7 +125,7 @@ void nest_info_t::generate_test_instances(list& ls) ls.back()->rbytes = 2; ls.back()->rfiles = 3; ls.back()->rsubdirs = 4; - ls.back()->rsnaprealms = 6; + ls.back()->rsnaps = 6; ls.back()->rctime = utime_t(7, 8); } @@ -138,8 +138,8 @@ ostream& operator<<(ostream &out, const nest_info_t &n) out << " rc" << n.rctime; if (n.rbytes) out << " b" << n.rbytes; - if (n.rsnaprealms) - out << " sr" << n.rsnaprealms; + if (n.rsnaps) + out << " rs" << n.rsnaps; if (n.rfiles || n.rsubdirs) out << " " << n.rsize() << "=" << n.rfiles << "+" << n.rsubdirs; out << ")"; diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index f4da164303552..f56aafe60f95d 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -230,7 +230,7 @@ struct nest_info_t : public scatter_info_t { int64_t rsubdirs = 0; int64_t rsize() const { return rfiles + rsubdirs; } - int64_t rsnaprealms = 0; + int64_t rsnaps = 0; nest_info_t() {} @@ -247,7 +247,7 @@ struct nest_info_t : public scatter_info_t { rbytes += fac*other.rbytes; rfiles += fac*other.rfiles; rsubdirs += fac*other.rsubdirs; - rsnaprealms += fac*other.rsnaprealms; + rsnaps += fac*other.rsnaps; } // *this += cur - acc; @@ -257,7 +257,7 @@ struct nest_info_t : public scatter_info_t { rbytes += cur.rbytes - acc.rbytes; rfiles += cur.rfiles - acc.rfiles; rsubdirs += cur.rsubdirs - acc.rsubdirs; - rsnaprealms += cur.rsnaprealms - acc.rsnaprealms; + rsnaps += cur.rsnaps - acc.rsnaps; } bool same_sums(const nest_info_t &o) const { @@ -265,7 +265,7 @@ struct nest_info_t : public scatter_info_t { rbytes == o.rbytes && rfiles == o.rfiles && rsubdirs == o.rsubdirs && - rsnaprealms == o.rsnaprealms; + rsnaps == o.rsnaps; } void encode(bufferlist &bl) const; -- 2.39.5