From: Xiaoxi Chen Date: Fri, 24 Apr 2015 14:37:32 +0000 (+0800) Subject: os/KeyValuestore:Refactor collection_list_range and collection_list_partial X-Git-Tag: v9.1.0~421^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7bf999cfd228416c2f105bf38722759677551631;p=ceph.git os/KeyValuestore:Refactor collection_list_range and collection_list_partial Add collection_list_impl which abstract the common process of collection list behavior. Signed-off-by: Xiaoxi Chen --- diff --git a/src/os/GenericObjectMap.cc b/src/os/GenericObjectMap.cc index c0ecd1720965..207236a7547b 100644 --- a/src/os/GenericObjectMap.cc +++ b/src/os/GenericObjectMap.cc @@ -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 *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++; diff --git a/src/os/GenericObjectMap.h b/src/os/GenericObjectMap.h index e947bb4f3111..ecf28222d481 100644 --- a/src/os/GenericObjectMap.h +++ b/src/os/GenericObjectMap.h @@ -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 *objs, ///< [out] objects ghobject_t *next); diff --git a/src/os/KeyValueStore.cc b/src/os/KeyValueStore.cc index bc9964130314..6ffd958a17d2 100644 --- a/src/os/KeyValueStore.cc +++ b/src/os/KeyValueStore.cc @@ -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 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 *ls) +int KeyValueStore::collection_list_impl(coll_t c, ghobject_t start, + ghobject_t end, int max, snapid_t seq, + vector *ls, ghobject_t *next) { - bool done = false; - ghobject_t next = start; - - while (!done) { - vector 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 *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& ls) diff --git a/src/os/KeyValueStore.h b/src/os/KeyValueStore.h index c6d8701ac859..96e36de46766 100644 --- a/src/os/KeyValueStore.h +++ b/src/os/KeyValueStore.h @@ -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& oid); + int collection_list_impl(coll_t c, ghobject_t start, ghobject_t end, + int max, snapid_t snap, + vector *ls, ghobject_t *next); int collection_list_partial(coll_t c, ghobject_t start, int min, int max, snapid_t snap, vector *ls, ghobject_t *next);