]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/KeyValuestore:Refactor collection_list_range and collection_list_partial
authorXiaoxi Chen <xiaoxi.chen@intel.com>
Fri, 24 Apr 2015 14:37:32 +0000 (22:37 +0800)
committerSage Weil <sage@redhat.com>
Fri, 7 Aug 2015 12:45:14 +0000 (08:45 -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/GenericObjectMap.cc
src/os/GenericObjectMap.h
src/os/KeyValueStore.cc
src/os/KeyValueStore.h

index c0ecd17209655030b296fc0ab8273594d31ddbb6..207236a7547ba43fec2dc5040dae69cf365c314c 100644 (file)
@@ -1049,7 +1049,7 @@ void GenericObjectMap::set_header(const coll_t &cid, const ghobject_t &oid,
   t->set(GHOBJECT_TO_SEQ_PREFIX, to_set);
 }
 
-int GenericObjectMap::list_objects(const coll_t &cid, ghobject_t start, int max,
+int GenericObjectMap::list_objects(const coll_t &cid, ghobject_t start, ghobject_t end, int max,
                                    vector<ghobject_t> *out, ghobject_t *next)
 {
   // FIXME
@@ -1101,7 +1101,14 @@ int GenericObjectMap::list_objects(const coll_t &cid, ghobject_t start, int max,
       break;
     }
 
+    if (header.oid >= end) {
+      if (next)
+       *next = ghobject_t::get_max();
+      break;
+    }
+
     assert(start <= header.oid);
+    assert(header.oid < end);
 
 
     size++;
index e947bb4f31119a2d9edf463bbb1efb605d086b92..ecf28222d4812d708359d232573dbfb7254a4c3e 100644 (file)
@@ -117,7 +117,7 @@ class GenericObjectMap {
   bool check(std::ostream &out);
 
   /// Util, list all objects, there must be no other concurrent access
-  int list_objects(const coll_t &cid, ghobject_t start, int max,
+  int list_objects(const coll_t &cid, ghobject_t start, ghobject_t end, int max,
                    vector<ghobject_t> *objs, ///< [out] objects
                    ghobject_t *next);
 
index bc9964130314888d552b0e84cec6947f26fee303..6ffd958a17d2c35176f66ad40f06520e5252444a 100644 (file)
@@ -2329,7 +2329,7 @@ int KeyValueStore::_destroy_collection(coll_t c, BufferTransaction &t)
     }
   }
 
-  r = backend->list_objects(c, ghobject_t(), modified_object+1, &oids,
+  r = backend->list_objects(c, ghobject_t(), ghobject_t::get_max(), modified_object+1, &oids,
                             0);
   // No other object
   if (oids.size() != modified_object && oids.size() != 0) {
@@ -2490,44 +2490,33 @@ bool KeyValueStore::collection_empty(coll_t c)
   dout(10) << __func__ << " " << dendl;
 
   vector<ghobject_t> oids;
-  backend->list_objects(c, ghobject_t(), 1, &oids, 0);
+  backend->list_objects(c, ghobject_t(), ghobject_t::get_max(), 1, &oids, 0);
 
   return oids.empty();
 }
 
-int KeyValueStore::collection_list_range(coll_t c, ghobject_t start,
-                                         ghobject_t end, snapid_t seq,
-                                         vector<ghobject_t> *ls)
+int KeyValueStore::collection_list_impl(coll_t c, ghobject_t start,
+                                         ghobject_t end, int max, snapid_t seq,
+                                         vector<ghobject_t> *ls, ghobject_t *next)
 {
-  bool done = false;
-  ghobject_t next = start;
-
-  while (!done) {
-    vector<ghobject_t> next_objects;
-    int r = collection_list_partial(c, next, get_ideal_list_min(),
-                                    get_ideal_list_max(), seq,
-                                    &next_objects, &next);
-    if (r < 0)
-      return r;
-
-    ls->insert(ls->end(), next_objects.begin(), next_objects.end());
+  if ( max < 0)
+      return -EINVAL;
 
-    // special case for empty collection
-    if (ls->empty()) {
-      break;
-    }
+  if (start.is_max())
+      return 0;
 
-    while (!ls->empty() && ls->back() >= end) {
-      ls->pop_back();
-      done = true;
-    }
+  int r = backend->list_objects(c, start, end, max, ls, next);
 
-    if (next >= end) {
-      done = true;
-    }
-  }
+  return r;
+}
 
-  return 0;
+int KeyValueStore::collection_list_range(coll_t c, ghobject_t start,
+                                         ghobject_t end, snapid_t seq,
+                                         vector<ghobject_t> *ls)
+{
+  ghobject_t next;
+  int r = collection_list_impl(c, start, end, -1, seq, ls, &next);
+  return r;
 }
 
 int KeyValueStore::collection_list_partial(coll_t c, ghobject_t start,
@@ -2538,13 +2527,8 @@ int KeyValueStore::collection_list_partial(coll_t c, ghobject_t start,
   dout(10) << __func__ << " " << c << " start:" << start << " is_max:"
            << start.is_max() << dendl;
 
-  if (min < 0 || max < 0)
-      return -EINVAL;
-
-  if (start.is_max())
-      return 0;
-
-  return backend->list_objects(c, start, max, ls, next);
+  int r = collection_list_impl(c, start, ghobject_t::get_max(), max, seq, ls, next);
+  return r;
 }
 
 int KeyValueStore::collection_list(coll_t c, vector<ghobject_t>& ls)
index c6d8701ac859aeb2efbdd240d51b9f6ef1d704da..96e36de46766e2b8637a70d9d4e8104f51ae4837 100644 (file)
@@ -619,6 +619,9 @@ class KeyValueStore : public ObjectStore,
   bool collection_exists(coll_t c);
   bool collection_empty(coll_t c);
   int collection_list(coll_t c, vector<ghobject_t>& oid);
+  int collection_list_impl(coll_t c, ghobject_t start, ghobject_t end,
+                              int max, snapid_t snap,
+                              vector<ghobject_t> *ls, ghobject_t *next);
   int collection_list_partial(coll_t c, ghobject_t start,
                               int min, int max, snapid_t snap,
                               vector<ghobject_t> *ls, ghobject_t *next);