From a47c2250629e2a3deb8bc026535c1cc53ed9908e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 18 Mar 2011 14:35:14 -0700 Subject: [PATCH] mds: use try_trim_non_auth_subtree helper This helper captures the logic of keeping subtrees when necessary but dropping them when possible, and cleaning up as appropriate. Signed-off-by: Sage Weil --- src/mds/MDCache.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++++ src/mds/MDCache.h | 1 + src/mds/journal.cc | 37 ++------------------------------ 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 72182468d0d58..7a16fa06c7eae 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -5543,6 +5543,59 @@ bool MDCache::trim_non_auth_subtree(CDir *directory) return keep_directory; } +/* + * during replay, when we determine a subtree is no longer ours, we + * try to trim it from our cache. because subtrees must be connected + * to the root, the fact that we can trim this tree may mean that our + * children or parents can also be trimmed. + */ +void MDCache::try_trim_non_auth_subtree(CDir *dir) +{ + dout(10) << "try_trim_nonauth_subtree " << *dir << dendl; + + // can we now trim child subtrees? + set bounds; + get_subtree_bounds(dir, bounds); + for (set::iterator p = bounds.begin(); p != bounds.end(); p++) { + CDir *bd = *p; + if (bd->get_dir_auth().first != mds->whoami && // we are not auth + bd->get_num_any() == 0) { // and empty + CInode *bi = bd->get_inode(); + dout(10) << " closing empty non-auth child subtree " << *bd << dendl; + remove_subtree(bd); + bd->mark_clean(); + bi->close_dirfrag(bd->get_frag()); + } + } + + if (trim_non_auth_subtree(dir)) { + // keep + try_subtree_merge(dir); + } else { + // can we trim this subtree (and possibly our ancestors) too? + CInode *diri; + while (true) { + dout(10) << " closing empty subtree " << *dir << dendl; + remove_subtree(dir); + dir->mark_clean(); + diri = dir->get_inode(); + diri->close_dirfrag(dir->get_frag()); + + if (diri->is_base()) + break; + + dir = get_subtree_root(diri->get_parent_dir()); + if (dir->get_dir_auth().first == mds->whoami) + break; // we are auth, keep. + + dout(10) << " parent subtree also non-auth: " << *dir << dendl; + if (trim_non_auth_subtree(dir)) + break; + } + } +} + + /* This function DOES put the passed message before returning */ void MDCache::handle_cache_expire(MCacheExpire *m) { diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index c378b421ba888..49ac938322330 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -859,6 +859,7 @@ public: void send_expire_messages(map& expiremap); void trim_non_auth(); // trim out trimmable non-auth items bool trim_non_auth_subtree(CDir *directory); + void try_trim_non_auth_subtree(CDir *dir); void trim_client_leases(); void check_memory_usage(); diff --git a/src/mds/journal.cc b/src/mds/journal.cc index d9c203c0af6c6..f2acbf27caf73 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -1062,44 +1062,11 @@ void EExport::replay(MDS *mds) // adjust auth away mds->mdcache->adjust_bounded_subtree_auth(dir, realbounds, pair(CDIR_AUTH_UNKNOWN, CDIR_AUTH_UNKNOWN)); - // can we now trim child subtrees? - set bounds; - mds->mdcache->get_subtree_bounds(dir, bounds); - for (set::iterator p = bounds.begin(); p != bounds.end(); p++) { - CDir *bd = *p; - if (bd->get_dir_auth().first != mds->whoami && // we are not auth - bd->get_num_any() == 0) { // and empty - CInode *bi = bd->get_inode(); - dout(10) << "EExport.replay " << base << " closing empty non-auth child subtree " << *bd << dendl; - mds->mdcache->remove_subtree(bd); - bd->mark_clean(); - bi->close_dirfrag(bd->get_frag()); - } - } - - if (mds->mdcache->trim_non_auth_subtree(dir)) { - // keep - mds->mdcache->try_subtree_merge(dir); - } else { - // can we trim this subtree (and possibly our ancestors) too? - CInode *diri = dir->get_inode(); - while (!diri->is_base()) { - dir = mds->mdcache->get_subtree_root(diri->get_parent_dir()); - if (dir->get_dir_auth().first == mds->whoami) - break; // we are auth, keep. - dout(10) << "EExport.replay " << base << " parent subtree also non-auth: " << *dir << dendl; - if (mds->mdcache->trim_non_auth_subtree(dir)) - break; - dout(10) << "EExport.replay " << base << " closing empty parent subtree " << *dir << dendl; - mds->mdcache->remove_subtree(dir); - dir->mark_clean(); - diri = dir->get_inode(); - diri->close_dirfrag(dir->get_frag()); - } - } + mds->mdcache->try_trim_non_auth_subtree(dir); } + // ----------------------- // EImportStart -- 2.39.5