]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/server: skip unwanted dn in handle_client_readdir 12870/head
authorXiaoxi Chen <xiaoxchen@ebay.com>
Wed, 11 Jan 2017 02:11:08 +0000 (19:11 -0700)
committerXiaoxi Chen <xiaoxchen@ebay.com>
Wed, 11 Jan 2017 03:04:56 +0000 (20:04 -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>
src/mds/CDir.h
src/mds/Server.cc

index edd5434eba307157e1aade308541b252584e8c7d..8eb2cbc27e8c0d60b3f1e876e7117312ae644639 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 b8655cd4c2ae6dd59bf1d563e0ff29bc7e2e50b1..30cad75c1d4d47421a37f6064c7858ac2ef419a5 100644 (file)
@@ -3416,7 +3416,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;