]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: use try_trim_non_auth_subtree helper
authorSage Weil <sage@newdream.net>
Fri, 18 Mar 2011 21:35:14 +0000 (14:35 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Fri, 1 Apr 2011 21:34:32 +0000 (14:34 -0700)
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 <sage@newdream.net>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/journal.cc

index 72182468d0d58ea09b72d48c3d1f696c94512672..7a16fa06c7eae5bf64c9016fb0fb47b91e6d9c47 100644 (file)
@@ -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<CDir*> bounds;
+  get_subtree_bounds(dir, bounds);
+  for (set<CDir*>::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)
 {
index c378b421ba888fd294f5da70baab01f072e63b17..49ac938322330c773695a7305aac0c74aa5cf4a8 100644 (file)
@@ -859,6 +859,7 @@ public:
   void send_expire_messages(map<int, MCacheExpire*>& 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();
index d9c203c0af6c6e97ebb736ef2b08234c683791dd..f2acbf27caf731e19acfa044071ba640412e670a 100644 (file)
@@ -1062,44 +1062,11 @@ void EExport::replay(MDS *mds)
   // adjust auth away
   mds->mdcache->adjust_bounded_subtree_auth(dir, realbounds, pair<int,int>(CDIR_AUTH_UNKNOWN, CDIR_AUTH_UNKNOWN));
 
-  // can we now trim child subtrees?
-  set<CDir*> bounds;
-  mds->mdcache->get_subtree_bounds(dir, bounds);
-  for (set<CDir*>::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