]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/Memstore:Refactor collection_list_range and collection_list_partial
authorXiaoxi Chen <xiaoxi.chen@intel.com>
Fri, 24 Apr 2015 08:04:21 +0000 (16:04 +0800)
committerSage Weil <sage@redhat.com>
Fri, 7 Aug 2015 12:43:43 +0000 (08:43 -0400)
Add collection_list_impl which abstract the common process
of collection list behavior.

Signed-off-by: Xiaoxi Chen <xiaoxi.chen@intel.com>
src/os/MemStore.cc
src/os/MemStore.h

index 67f0911ccb29b086f05ecf22deb3f97012b44136..34eeedd1032afb0ba4cdc35f98586bba32748136 100644 (file)
@@ -436,12 +436,10 @@ int MemStore::collection_list(coll_t cid, vector<ghobject_t>& o)
   return 0;
 }
 
-int MemStore::collection_list_partial(coll_t cid, ghobject_t start,
-                                     int min, int max, snapid_t snap, 
+int MemStore::collection_list_impl(coll_t cid, ghobject_t start, ghobject_t end,
+                                     int max, snapid_t snap,
                                      vector<ghobject_t> *ls, ghobject_t *next)
 {
-  dout(10) << __func__ << " " << cid << " " << start << " " << min << "-"
-          << max << " " << snap << dendl;
   CollectionRef c = get_collection(cid);
   if (!c)
     return -ENOENT;
@@ -449,34 +447,40 @@ int MemStore::collection_list_partial(coll_t cid, ghobject_t start,
 
   map<ghobject_t,ObjectRef>::iterator p = c->object_map.lower_bound(start);
   while (p != c->object_map.end() &&
-        ls->size() < (unsigned)max) {
+        (max == -1 || ls->size() < (unsigned)max) &&
+         p->first < end) {
     ls->push_back(p->first);
     ++p;
   }
-  if (p == c->object_map.end())
-    *next = ghobject_t::get_max();
-  else
-    *next = p->first;
+  if (next != NULL) {
+    if (p == c->object_map.end())
+      *next = ghobject_t::get_max();
+    else
+      *next = p->first;
+  }
   return 0;
 }
 
+int MemStore::collection_list_partial(coll_t cid, ghobject_t start,
+                                     int min, int max, snapid_t snap,
+                                     vector<ghobject_t> *ls, ghobject_t *next)
+{
+  dout(10) << __func__ << " " << cid << " " << start << " " << min << "-"
+          << max << " " << snap << dendl;
+
+  collection_list_impl(cid, start, ghobject_t::get_max(), max, snap, ls, next);
+  return 0;
+}
+
+
 int MemStore::collection_list_range(coll_t cid,
                                    ghobject_t start, ghobject_t end,
                                    snapid_t seq, vector<ghobject_t> *ls)
 {
   dout(10) << __func__ << " " << cid << " " << start << " " << end
           << " " << seq << dendl;
-  CollectionRef c = get_collection(cid);
-  if (!c)
-    return -ENOENT;
-  RWLock::RLocker l(c->lock);
 
-  map<ghobject_t,ObjectRef>::iterator p = c->object_map.lower_bound(start);
-  while (p != c->object_map.end() &&
-        p->first < end) {
-    ls->push_back(p->first);
-    ++p;
-  }
+  collection_list_impl(cid, start, end, -1, seq, ls, NULL);
   return 0;
 }
 
index d6cb51a866483f0156db0596ba18ff172b4a6a20..09d4980f00d81ea46c892705eec080696430873b 100644 (file)
@@ -307,6 +307,9 @@ public:
   bool collection_exists(coll_t c);
   bool collection_empty(coll_t c);
   int collection_list(coll_t cid, vector<ghobject_t>& o);
+  int collection_list_impl(coll_t cid, ghobject_t start, ghobject_t end,
+                             int max, snapid_t snap,
+                             vector<ghobject_t> *ls, ghobject_t *next);
   int collection_list_partial(coll_t cid, ghobject_t start,
                              int min, int max, snapid_t snap, 
                              vector<ghobject_t> *ls, ghobject_t *next);