]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/server: skip unwanted dn in handle_client_readdir 12921/head
authorXiaoxi Chen <xiaoxchen@ebay.com>
Wed, 11 Jan 2017 02:11:08 +0000 (19:11 -0700)
committerXiaoxi Chen <xiaoxchen@ebay.com>
Fri, 13 Jan 2017 13:39:14 +0000 (06:39 -0700)
We can skip unwanted dn which  < (offset_key, snap) via map.lower_bound, rather than
iterate across them.

Previously we iterate and skip dn which < (offset_key, dn->last), as dn->last >= snap
 means (offset_key, dn->last) >= (offset_key, snap), and such iterate_and_skip logic
still keep, so this commit doesnt change code logic but an optimization.

Signed-off-by: Xiaoxi Chen <xiaoxchen@ebay.com>
(cherry picked from commit 52fe52baf920c672ac7f63a3087dcd31137891b6)

src/mds/CDir.h
src/mds/Server.cc

index 8533ba8c1d2464933b7f41fddc6094f3f3471d8b..6f73eb24d2e2d7d00006d7efb62dc47697040b9a 100644 (file)
@@ -428,6 +428,7 @@ protected:
 
   map_t::iterator begin() { return items.begin(); }
   map_t::iterator end() { return items.end(); }
+  map_t::iterator lower_bound(dentry_key_t key) { return items.lower_bound(key); }
 
   unsigned get_num_head_items() const { return num_head_items; }
   unsigned get_num_head_null() const { return num_head_null; }
index 86be3f98f96eb99cbc6612e3f3b72760ebab6b11..8d250a295481492005664e3781e8f9297cb38646 100644 (file)
@@ -3395,7 +3395,9 @@ void Server::handle_client_readdir(MDRequestRef& mdr)
   bufferlist dnbl;
   __u32 numfiles = 0;
   bool end = (dir->begin() == dir->end());
-  for (CDir::map_t::iterator it = dir->begin();
+  // skip all dns < dentry_key_t(snapid, offset_str, offset_hash)
+  dentry_key_t skip_key(snapid, offset_str.c_str(), offset_hash);
+  for (CDir::map_t::iterator it = offset_str.empty() ? dir->begin() : dir->lower_bound(skip_key);
        !end && numfiles < max;
        end = (it == dir->end())) {
     CDentry *dn = it->second;