From d171537bd47678a2af112458f3be296a646f3511 Mon Sep 17 00:00:00 2001 From: Xiaoxi Chen Date: Fri, 24 Apr 2015 16:04:21 +0800 Subject: [PATCH] os/Memstore: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 --- src/os/MemStore.cc | 42 +++++++++++++++++++++++------------------- src/os/MemStore.h | 3 +++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index 67f0911ccb29b..34eeedd1032af 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -436,12 +436,10 @@ int MemStore::collection_list(coll_t cid, vector& 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 *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::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 *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 *ls) { dout(10) << __func__ << " " << cid << " " << start << " " << end << " " << seq << dendl; - CollectionRef c = get_collection(cid); - if (!c) - return -ENOENT; - RWLock::RLocker l(c->lock); - map::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; } diff --git a/src/os/MemStore.h b/src/os/MemStore.h index d6cb51a866483..09d4980f00d81 100644 --- a/src/os/MemStore.h +++ b/src/os/MemStore.h @@ -307,6 +307,9 @@ public: bool collection_exists(coll_t c); bool collection_empty(coll_t c); int collection_list(coll_t cid, vector& o); + int collection_list_impl(coll_t cid, ghobject_t start, ghobject_t end, + int max, snapid_t snap, + vector *ls, ghobject_t *next); int collection_list_partial(coll_t cid, ghobject_t start, int min, int max, snapid_t snap, vector *ls, ghobject_t *next); -- 2.39.5