]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: automatically fragment stray dirs
authorSimon Gao <simon29rock@gmail.com>
Sat, 22 Feb 2020 02:26:57 +0000 (10:26 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 21 Apr 2020 00:46:31 +0000 (08:46 +0800)
Signed-off-by: Simon Gao <simon29rock@gmail.com>
src/mds/CDir.h
src/mds/MDBalancer.cc
src/mds/MDBalancer.h
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDLog.cc

index 8af22193511328c2f7e2c6f1b780f7f82947ddb7..4ad5edfd5de74a357f39f0159c646d3ceeff9a5d 100644 (file)
@@ -392,11 +392,13 @@ public:
   void merge(const std::vector<CDir*>& subs, MDSContext::vec& waiters, bool replay);
 
   bool should_split() const {
-    return (int)get_frag_size() > g_conf()->mds_bal_split_size;
+    return g_conf()->mds_bal_split_size > 0 &&
+           (int)get_frag_size() > g_conf()->mds_bal_split_size;
   }
   bool should_split_fast() const;
   bool should_merge() const {
-    return (int)get_frag_size() < g_conf()->mds_bal_merge_size;
+    return get_frag() != frag_t() &&
+          (int)get_frag_size() < g_conf()->mds_bal_merge_size;
   }
 
   mds_authority_t authority() const override;
index a1b8508f54e32adcd8ea6677423d68190b59bfd8..0c3fa3ebaa06c2dc2accc7bddf1f893703ffe76f 100644 (file)
@@ -1154,7 +1154,7 @@ void MDBalancer::maybe_fragment(CDir *dir, bool hot)
       !dir->inode->is_stray()) { // not straydir
 
     // split
-    if (g_conf()->mds_bal_split_size > 0 && (dir->should_split() || hot)) {
+    if (dir->should_split() || hot) {
       if (split_pending.count(dir->dirfrag()) == 0) {
         queue_split(dir, false);
       } else {
@@ -1177,6 +1177,8 @@ void MDBalancer::maybe_fragment(CDir *dir, bool hot)
 
 void MDBalancer::hit_dir(CDir *dir, int type, int who, double amount)
 {
+  if (dir->inode->is_stray())
+    return;
   // hit me
   double v = dir->pop_me.get(type).hit(amount);
 
index c6d85a5aed6e289003fcc74ee34da0509e9545ae..2e8fef16779078df6ef4b61e9ab35d79735f94d7 100644 (file)
@@ -58,6 +58,9 @@ public:
 
   void queue_split(const CDir *dir, bool fast);
   void queue_merge(CDir *dir);
+  bool is_fragment_pending(dirfrag_t df) {
+    return split_pending.count(df) || merge_pending.count(df);
+  }
 
   /**
    * Based on size and configuration, decide whether to issue a queue_split
index e5e1da59e6a9df19363c7e0526117a6010dcab7c..413c7e88cce06dfac45afcb380ef83e0b6dd8eac 100644 (file)
@@ -691,6 +691,51 @@ void MDCache::open_root()
   populate_mydir();
 }
 
+void MDCache::advance_stray() {
+  // check whether the directory has been fragmented
+  if (stray_fragmenting_index >= 0) {
+    auto&& dfs = strays[stray_fragmenting_index]->get_dirfrags();
+    bool any_fragmenting = false;
+    for (const auto& dir : dfs) {
+      if (dir->state_test(CDir::STATE_FRAGMENTING) ||
+         mds->balancer->is_fragment_pending(dir->dirfrag())) {
+       any_fragmenting = true;
+       break;
+      }
+    }
+    if (!any_fragmenting)
+      stray_fragmenting_index = -1;
+  }
+
+  for (int i = 1; i < NUM_STRAY; i++){
+    stray_index = (stray_index + i) % NUM_STRAY;
+    if (stray_index != stray_fragmenting_index)
+      break;
+  }
+
+  if (stray_fragmenting_index == -1 && is_open()) {
+    // Fragment later stray dir in advance. We don't choose past
+    // stray dir because in-flight requests may still use it.
+    stray_fragmenting_index = (stray_index + 3) % NUM_STRAY;
+    auto&& dfs = strays[stray_fragmenting_index]->get_dirfrags();
+    bool any_fragmenting = false;
+    for (const auto& dir : dfs) {
+      if (dir->should_split()) {
+       mds->balancer->queue_split(dir, true);
+       any_fragmenting = true;
+      } else if (dir->should_merge()) {
+       mds->balancer->queue_merge(dir);
+       any_fragmenting = true;
+      }
+    }
+    if (!any_fragmenting)
+      stray_fragmenting_index = -1;
+  }
+
+  dout(10) << "advance_stray to index " << stray_index
+          << " fragmenting index " << stray_fragmenting_index << dendl;
+}
+
 void MDCache::populate_mydir()
 {
   ceph_assert(myin);
index 6dd04f1bfb575a48b5844c9bd9adde22aa88b4d4..1fb4460f8b1ccf7e2836806606ce765fc808d3b6 100644 (file)
@@ -213,9 +213,7 @@ class MDCache {
     return cache_size() > cache_memory_limit*cache_health_threshold;
   }
 
-  void advance_stray() {
-    stray_index = (stray_index+1)%NUM_STRAY;
-  }
+  void advance_stray();
 
   /**
    * Call this when you know that a CDentry is ready to be passed
@@ -1112,6 +1110,7 @@ class MDCache {
   bool readonly = false;
 
   int stray_index = 0;
+  int stray_fragmenting_index = -1;
 
   set<CInode*> base_inodes;
 
index ee2d08cebba4728b04f82754f552848ba5b40399..76d455cb2d0e54bb8f5ec311fbd88c82cd1641ed 100644 (file)
@@ -554,8 +554,6 @@ void MDLog::_prepare_new_segment()
   logger->set(l_mdl_seg, segments.size());
 
   // Adjust to next stray dir
-  dout(10) << "Advancing to next stray directory on mds " << mds->get_nodeid() 
-          << dendl;
   mds->mdcache->advance_stray();
 }