diff --git a/src/mds/CDentry.cc b/src/mds/CDentry.cc index 032f83a4297..8790377858e 100644 --- a/src/mds/CDentry.cc +++ b/src/mds/CDentry.cc @@ -249,6 +249,18 @@ void CDentry::unlink_remote(CDentry::linkage_t *dnl) dnl->inode = 0; } +void CDentry::push_projected_linkage() +{ + _project_linkage(); + + if (is_auth()) { + CInode *diri = dir->inode; + if (diri->is_stray()) + diri->mdcache->notify_stray_removed(); + } +} + + void CDentry::push_projected_linkage(CInode *inode) { // dirty rstat tracking is in the projected plane @@ -261,6 +273,12 @@ void CDentry::push_projected_linkage(CInode *inode) if (dirty_rstat) inode->mark_dirty_rstat(); + + if (is_auth()) { + CInode *diri = dir->inode; + if (diri->is_stray()) + diri->mdcache->notify_stray_created(); + } } CDentry::linkage_t *CDentry::pop_projected_linkage() diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h index 3d300237f6a..f9505875e04 100644 --- a/src/mds/CDentry.h +++ b/src/mds/CDentry.h @@ -168,9 +168,7 @@ public: projected.push_back(linkage_t()); return &projected.back(); } - void push_projected_linkage() { - _project_linkage(); - } + void push_projected_linkage(); void push_projected_linkage(inodeno_t ino, char d_type) { linkage_t *p = _project_linkage(); p->remote_ino = ino; diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 5921b4415d3..fd023da1983 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -657,6 +657,7 @@ void MDCache::populate_mydir() } // open or create stray + uint64_t num_strays = 0; for (int i = 0; i < NUM_STRAY; ++i) { stringstream name; name << "stray" << i; @@ -699,9 +700,14 @@ void MDCache::populate_mydir() dir->fetch(new C_MDS_RetryOpenRoot(this)); return; } + + if (dir->get_frag_size() > 0) + num_strays += dir->get_frag_size(); } } + stray_manager.set_num_strays(num_strays); + // okay! dout(10) << "populate_mydir done" << dendl; assert(!open); @@ -742,11 +748,6 @@ CDentry *MDCache::get_or_create_stray_dentry(CInode *in) assert(straydn->get_projected_linkage()->is_null()); } - // Notify even if a null dentry already existed, because - // StrayManager counts the number of stray inodes, not the - // number of dentries in the directory. - stray_manager.notify_stray_created(); - straydn->state_set(CDentry::STATE_STRAY); return straydn; } @@ -9397,7 +9398,6 @@ void MDCache::scan_stray_dir(dirfrag_t next) for (CDir::map_t::iterator q = dir->items.begin(); q != dir->items.end(); ++q) { CDentry *dn = q->second; dn->state_set(CDentry::STATE_STRAY); - stray_manager.notify_stray_created(); CDentry::linkage_t *dnl = dn->get_projected_linkage(); if (dnl->is_primary()) { CInode *in = dnl->get_inode(); @@ -12284,6 +12284,21 @@ void MDCache::register_perfcounters() stray_manager.set_logger(logger.get()); } +void MDCache::activate_stray_manager() +{ + if (open) { + stray_manager.activate(); + } else { + wait_for_open( + new MDSInternalContextWrapper(mds, + new FunctionContext([this](int r){ + stray_manager.activate(); + }) + ) + ); + } +} + /** * Call this when putting references to an inode/dentry or * when attempting to trim it. diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 76e779794a7..cd0afbe9d09 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -142,9 +142,7 @@ public: stray_index = (stray_index+1)%NUM_STRAY; } - void activate_stray_manager() { - stray_manager.activate(); - } + void activate_stray_manager(); /** * Call this when you know that a CDentry is ready to be passed diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 7a6b1132cbb..d62720b4609 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -7136,20 +7136,6 @@ void Server::_rename_apply(MDRequestRef& mdr, CDentry *srcdn, CDentry *destdn, C } } - if (srcdn->get_dir()->inode->is_stray() && - srcdn->get_dir()->inode->get_stray_owner() == mds->get_nodeid()) { - // A reintegration event or a migration away from me - dout(20) << __func__ << ": src dentry was a stray, updating stats" << dendl; - mdcache->notify_stray_removed(); - } - - if (destdn->get_dir()->inode->is_stray() && - destdn->get_dir()->inode->get_stray_owner() == mds->get_nodeid()) { - // A stray migration (to me) - dout(20) << __func__ << ": dst dentry was a stray, updating stats" << dendl; - mdcache->notify_stray_created(); - } - // src if (srcdn->is_auth()) srcdn->mark_dirty(mdr->more()->pvmap[srcdn], mdr->ls); diff --git a/src/mds/StrayManager.cc b/src/mds/StrayManager.cc index 816f9249883..f4d3ac4efc7 100644 --- a/src/mds/StrayManager.cc +++ b/src/mds/StrayManager.cc @@ -226,7 +226,6 @@ void StrayManager::_purge_stray_purged( mds->mdlog->submit_entry(le, new C_PurgeStrayLogged(this, dn, pdv, mds->mdlog->get_current_segment())); - num_strays--; logger->set(l_mdc_num_strays, num_strays); } } @@ -377,6 +376,13 @@ void StrayManager::advance_delayed() logger->set(l_mdc_num_strays_delayed, num_strays_delayed); } +void StrayManager::set_num_strays(uint64_t num) +{ + assert(!started); + num_strays = num; + logger->set(l_mdc_num_strays, num_strays); +} + void StrayManager::notify_stray_created() { num_strays++; diff --git a/src/mds/StrayManager.h b/src/mds/StrayManager.h index eff21958ddf..a9bf3aa7840 100644 --- a/src/mds/StrayManager.h +++ b/src/mds/StrayManager.h @@ -127,6 +127,7 @@ class StrayManager bool eval_stray(CDentry *dn, bool delay=false); + void set_num_strays(uint64_t num); uint64_t get_num_strays() const { return num_strays; } /**