From: Sage Weil Date: Fri, 7 Nov 2008 21:26:41 +0000 (-0800) Subject: mds: match last snap exactly on replay, add_*_dentry X-Git-Tag: v0.5~48 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=214f0fa62aaae70ad1ed270e188cd79d2bbc9e18;p=ceph.git mds: match last snap exactly on replay, add_*_dentry In general, we add new snapped dentries and THEN the new live dentry to the metablob. That means that during replay, we see [2,2] followed by [3,head], replacing [2,head]. The [2,2] dentry should be added anew, without paying heed to [2,head], and then the [3,head] should replace/update [2,head]. It was mainly just the assertions in add_*_dentry that were getting in the way.. but the lookup_exact_snap is also slightly faster. --- diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index e0f17f7c4b87..093de51c2206 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -211,7 +211,7 @@ CDentry* CDir::add_null_dentry(const nstring& dname, snapid_t first, snapid_t last) { // foreign - assert(lookup(dname, last) == 0); + assert(lookup_exact_snap(dname, last) == 0); // create dentry CDentry* dn = new CDentry(dname, first, last); @@ -247,7 +247,7 @@ CDentry* CDir::add_primary_dentry(const nstring& dname, CInode *in, snapid_t first, snapid_t last) { // primary - assert(lookup(dname, last) == 0); + assert(lookup_exact_snap(dname, last) == 0); // create dentry CDentry* dn = new CDentry(dname, first, last); @@ -278,7 +278,7 @@ CDentry* CDir::add_remote_dentry(const nstring& dname, inodeno_t ino, unsigned c snapid_t first, snapid_t last) { // foreign - assert(lookup(dname, last) == 0); + assert(lookup_exact_snap(dname, last) == 0); // create dentry CDentry* dn = new CDentry(dname, ino, d_type, first, last); diff --git a/src/mds/CDir.h b/src/mds/CDir.h index 91616506c8f6..58d66e083d6d 100644 --- a/src/mds/CDir.h +++ b/src/mds/CDir.h @@ -286,6 +286,12 @@ protected: // -- dentries and inodes -- public: + CDentry* lookup_exact_snap(const nstring& dname, snapid_t last) { + map_t::iterator p = items.find(dentry_key_t(last, dname.c_str())); + if (p == items.end()) + return NULL; + return p->second; + } CDentry* lookup(const string& n, snapid_t snap=CEPH_NOSNAP) { return lookup(n.c_str(), snap); } diff --git a/src/mds/journal.cc b/src/mds/journal.cc index 87e3c37eac6c..01658a0125aa 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -358,8 +358,8 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) for (list::iterator p = lump.get_dfull().begin(); p != lump.get_dfull().end(); p++) { - CDentry *dn = dir->lookup(p->dn, p->dnlast); - if (!dn || dn->last != p->dnlast) { + CDentry *dn = dir->lookup_exact_snap(p->dn, p->dnlast); + if (!dn) { dn = dir->add_null_dentry(p->dn, p->dnfirst, p->dnlast); dn->set_version(p->dnv); if (p->dirty) dn->_mark_dirty(logseg); @@ -431,8 +431,8 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) for (list::iterator p = lump.get_dremote().begin(); p != lump.get_dremote().end(); p++) { - CDentry *dn = dir->lookup(p->dn, p->dnlast); - if (!dn || dn->last != p->dnlast) { + CDentry *dn = dir->lookup_exact_snap(p->dn, p->dnlast); + if (!dn) { dn = dir->add_remote_dentry(p->dn, p->ino, p->d_type, p->dnfirst, p->dnlast); dn->set_version(p->dnv); if (p->dirty) dn->_mark_dirty(logseg); @@ -455,8 +455,8 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) for (list::iterator p = lump.get_dnull().begin(); p != lump.get_dnull().end(); p++) { - CDentry *dn = dir->lookup(p->dn, p->dnfirst); - if (!dn || dn->last != p->dnlast) { + CDentry *dn = dir->lookup_exact_snap(p->dn, p->dnfirst); + if (!dn) { dn = dir->add_null_dentry(p->dn, p->dnfirst, p->dnlast); dn->set_version(p->dnv); if (p->dirty) dn->_mark_dirty(logseg);