Skip to content

Commit

Permalink
os/Filestore:Refactor collection_list_range and collection_list_partial
Browse files Browse the repository at this point in the history
Add collection_list_impl which abstract the common process
of coleection list behavior.

Todo: Refactor Index::collection_list_partial as
well.

Signed-off-by: Xiaoxi Chen <xiaoxi.chen@intel.com>
  • Loading branch information
xiaoxichen819 authored and liewegas committed Aug 7, 2015
1 parent d171537 commit 921c458
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/os/CollectionIndex.h
Expand Up @@ -166,7 +166,7 @@ class CollectionIndex {
/// List contents of collection by hash
virtual int collection_list_partial(
const ghobject_t &start, ///< [in] object at which to start
int min_count, ///< [in] get at least min_count objects
const ghobject_t end, ///< [in] list only objects < end
int max_count, ///< [in] return at most max_count objects
snapid_t seq, ///< [in] list only objects with snap >= seq
vector<ghobject_t> *ls, ///< [out] Listed objects
Expand Down
95 changes: 32 additions & 63 deletions src/os/FileStore.cc
Expand Up @@ -4631,7 +4631,7 @@ bool FileStore::collection_empty(coll_t c)

vector<ghobject_t> ls;
collection_list_handle_t handle;
r = index->collection_list_partial(ghobject_t(), 1, 1, 0, &ls, NULL);
r = index->collection_list_partial(ghobject_t(), ghobject_t::get_max(), 1, 0, &ls, NULL);
if (r < 0) {
assert(!m_filestore_fail_eio || r != -EIO);
return false;
Expand All @@ -4640,59 +4640,9 @@ bool FileStore::collection_empty(coll_t c)
tracepoint(objectstore, collection_empty_exit, ret);
return ret;
}

int FileStore::collection_list_range(coll_t c, ghobject_t start, ghobject_t end,
snapid_t seq, vector<ghobject_t> *ls)
{
tracepoint(objectstore, collection_list_range_enter, c.c_str());
bool done = false;
ghobject_t next = start;

if (!c.is_temp() && !c.is_meta() && next.hobj.pool < -1) {
coll_t temp = c.get_temp();
int r = collection_list_range(temp, start, end, seq, ls);
if (r < 0)
return r;
// ... always continue on to non-temp ...
}

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());

// special case for empty collection
if (ls->empty()) {
break;
}

while (!ls->empty() && ls->back() >= end) {
ls->pop_back();
done = true;
}

if (next >= end) {
done = true;
}
}

tracepoint(objectstore, collection_list_range_exit, 0);
return 0;
}

int FileStore::collection_list_partial(coll_t c, ghobject_t start,
int min, int max, snapid_t seq,
vector<ghobject_t> *ls, ghobject_t *next)
int FileStore::collection_list_impl(coll_t c, ghobject_t start, ghobject_t end, int max,
snapid_t seq, vector<ghobject_t> *ls, ghobject_t *next)
{
tracepoint(objectstore, collection_list_partial_enter, c.c_str());
dout(10) << "collection_list_partial: " << c << " start " << start << dendl;
assert(next);

if (start.is_max())
return 0;

Expand Down Expand Up @@ -4720,15 +4670,14 @@ int FileStore::collection_list_partial(coll_t c, ghobject_t start,
dout(20) << __func__ << " pool is " << pool << " shard is " << shard
<< " pgid " << pgid << dendl;
}

ghobject_t sep;
sep.hobj.pool = -1;
sep.set_shard(shard);
if (!c.is_temp() && !c.is_meta()) {
if (start < sep) {
dout(10) << __func__ << " first checking temp pool" << dendl;
coll_t temp = c.get_temp();
int r = collection_list_partial(temp, start, min, max, seq, ls, next);
int r = collection_list_impl(temp, start, end, max, seq, ls, next);
if (r < 0)
return r;
if (*next != ghobject_t::get_max())
Expand All @@ -4749,26 +4698,46 @@ int FileStore::collection_list_partial(coll_t c, ghobject_t start,
assert(NULL != index.index);
RWLock::RLocker l((index.index)->access_lock);

r = index->collection_list_partial(start,
min, max, seq,
ls, next);
r = index->collection_list_partial(start, end, max, seq, ls, next);

if (r < 0) {
assert(!m_filestore_fail_eio || r != -EIO);
return r;
}
if (ls)
dout(20) << "objects: " << *ls << dendl;
dout(20) << "objects: " << ls << dendl;

// HashIndex doesn't know the pool when constructing a 'next' value
if (!next->is_max()) {
if (next && !next->is_max()) {
next->hobj.pool = pool;
next->set_shard(shard);
dout(20) << " next " << *next << dendl;
}
dout(20) << " next " << *next << dendl;

tracepoint(objectstore, collection_list_partial_exit, 0);
return 0;
}
int FileStore::collection_list_range(coll_t c, ghobject_t start, ghobject_t end,
snapid_t seq, vector<ghobject_t> *ls)
{
tracepoint(objectstore, collection_list_range_enter, c.c_str());

ghobject_t next;
int r = collection_list_impl(c, start, end, -1, seq, ls, &next);
tracepoint(objectstore, collection_list_range_exit, 0);
return r;
}

int FileStore::collection_list_partial(coll_t c, ghobject_t start,
int min, int max, snapid_t seq,
vector<ghobject_t> *ls, ghobject_t *next)
{
tracepoint(objectstore, collection_list_partial_enter, c.c_str());
dout(10) << "collection_list_partial: " << c << " start " << start << dendl;

assert(next);
int r = collection_list_impl(c, start, ghobject_t::get_max(), max, seq, ls, next);
tracepoint(objectstore, collection_list_partial_exit, 0);
return r;
}

int FileStore::collection_list(coll_t c, vector<ghobject_t>& ls)
{
Expand Down
2 changes: 2 additions & 0 deletions src/os/FileStore.h
Expand Up @@ -617,6 +617,8 @@ class FileStore : public JournalingObjectStore,
const SequencerPosition &spos);

// collections
int collection_list_impl(coll_t c, ghobject_t start, ghobject_t end, int max,
snapid_t seq, vector<ghobject_t> *ls, ghobject_t *next);
int list_collections(vector<coll_t>& ls);
int list_collections(vector<coll_t>& ls, bool include_temp);
int collection_version_current(coll_t c, uint32_t *version);
Expand Down
2 changes: 1 addition & 1 deletion src/os/FlatIndex.cc
Expand Up @@ -373,7 +373,7 @@ static int get_hobject_from_oinfo(const char *dir, const char *file,
}

int FlatIndex::collection_list_partial(const ghobject_t &start,
int min_count,
const ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
Expand Down
2 changes: 1 addition & 1 deletion src/os/FlatIndex.h
Expand Up @@ -74,7 +74,7 @@ class FlatIndex : public CollectionIndex {
/// @see CollectionIndex
int collection_list_partial(
const ghobject_t &start,
int min_count,
const ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
Expand Down
22 changes: 11 additions & 11 deletions src/os/HashIndex.cc
Expand Up @@ -322,11 +322,11 @@ int HashIndex::_lookup(const ghobject_t &oid,

int HashIndex::_collection_list(vector<ghobject_t> *ls) {
vector<string> path;
return list_by_hash(path, 0, 0, 0, 0, ls);
return list_by_hash(path, ghobject_t::get_max(), 0, 0, 0, ls);
}

int HashIndex::_collection_list_partial(const ghobject_t &start,
int min_count,
const ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
Expand All @@ -336,8 +336,8 @@ int HashIndex::_collection_list_partial(const ghobject_t &start,
if (!next)
next = &_next;
*next = start;
dout(20) << "_collection_list_partial " << start << " " << min_count << "-" << max_count << " ls.size " << ls->size() << dendl;
return list_by_hash(path, min_count, max_count, seq, next, ls);
dout(20) << "_collection_list_partial start:" << start << " end:" << end << "-" << max_count << " ls.size " << ls->size() << dendl;
return list_by_hash(path, end, max_count, seq, next, ls);
}

int HashIndex::prep_delete() {
Expand Down Expand Up @@ -816,7 +816,7 @@ int HashIndex::get_path_contents_by_hash(const vector<string> &path,
}

int HashIndex::list_by_hash(const vector<string> &path,
int min_count,
ghobject_t end,
int max_count,
snapid_t seq,
ghobject_t *next,
Expand All @@ -841,17 +841,12 @@ int HashIndex::list_by_hash(const vector<string> &path,
set<pair<string, ghobject_t> >::iterator j = objects.lower_bound(
make_pair(*i, ghobject_t()));
if (j == objects.end() || j->first != *i) {
if (min_count > 0 && out->size() > (unsigned)min_count) {
if (next)
*next = ghobject_t(hobject_t("", "", CEPH_NOSNAP, hash_prefix_to_hash(*i), -1, ""));
return 0;
}
*(next_path.rbegin()) = *(i->rbegin());
ghobject_t next_recurse;
if (next)
next_recurse = *next;
r = list_by_hash(next_path,
min_count,
end,
max_count,
seq,
&next_recurse,
Expand All @@ -871,6 +866,11 @@ int HashIndex::list_by_hash(const vector<string> &path,
*next = j->second;
return 0;
}
if (j->second >= end) {
if (next)
*next = ghobject_t::get_max();
return 0;
}
if (!next || j->second >= *next) {
out->push_back(j->second);
}
Expand Down
4 changes: 2 additions & 2 deletions src/os/HashIndex.h
Expand Up @@ -193,7 +193,7 @@ class HashIndex : public LFNIndex {

int _collection_list_partial(
const ghobject_t &start,
int min_count,
ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
Expand Down Expand Up @@ -366,7 +366,7 @@ class HashIndex : public LFNIndex {
/// List objects in collection in ghobject_t order
int list_by_hash(
const vector<string> &path, /// [in] Path to list
int min_count, /// [in] List at least min_count
ghobject_t end, /// [in] List only objects < end
int max_count, /// [in] List at most max_count
snapid_t seq, /// [in] list only objects where snap >= seq
ghobject_t *next, /// [in,out] List objects >= *next
Expand Down
4 changes: 2 additions & 2 deletions src/os/LFNIndex.cc
Expand Up @@ -155,13 +155,13 @@ int LFNIndex::pre_hash_collection(uint32_t pg_num, uint64_t expected_num_objs)


int LFNIndex::collection_list_partial(const ghobject_t &start,
int min_count,
const ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
ghobject_t *next)
{
return _collection_list_partial(start, min_count, max_count, seq, ls, next);
return _collection_list_partial(start, end, max_count, seq, ls, next);
}

/* Derived class utility methods */
Expand Down
4 changes: 2 additions & 2 deletions src/os/LFNIndex.h
Expand Up @@ -192,7 +192,7 @@ class LFNIndex : public CollectionIndex {
/// @see CollectionIndex
int collection_list_partial(
const ghobject_t &start,
int min_count,
const ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
Expand Down Expand Up @@ -268,7 +268,7 @@ class LFNIndex : public CollectionIndex {
/// @see CollectionIndex
virtual int _collection_list_partial(
const ghobject_t &start,
int min_count,
const ghobject_t end,
int max_count,
snapid_t seq,
vector<ghobject_t> *ls,
Expand Down

0 comments on commit 921c458

Please sign in to comment.