Skip to content

Commit

Permalink
Merge pull request #13321 from liewegas/wip-kill-sortbitwise-harder
Browse files Browse the repository at this point in the history
osd: kill sortbitwise

Reviewed-by: Brad Hubbard <bhubbard@redhat.com>
  • Loading branch information
liewegas committed Feb 13, 2017
2 parents 24f43e9 + 784c7ed commit 316dc98
Show file tree
Hide file tree
Showing 56 changed files with 553 additions and 1,030 deletions.
59 changes: 3 additions & 56 deletions src/common/hobject.cc
Expand Up @@ -319,40 +319,7 @@ bool hobject_t::parse(const string &s)
return true;
}

int cmp_nibblewise(const hobject_t& l, const hobject_t& r)
{
if (l.max < r.max)
return -1;
if (l.max > r.max)
return 1;
if (l.pool < r.pool)
return -1;
if (l.pool > r.pool)
return 1;
if (l.get_nibblewise_key() < r.get_nibblewise_key())
return -1;
if (l.get_nibblewise_key() > r.get_nibblewise_key())
return 1;
if (l.nspace < r.nspace)
return -1;
if (l.nspace > r.nspace)
return 1;
if (l.get_effective_key() < r.get_effective_key())
return -1;
if (l.get_effective_key() > r.get_effective_key())
return 1;
if (l.oid < r.oid)
return -1;
if (l.oid > r.oid)
return 1;
if (l.snap < r.snap)
return -1;
if (l.snap > r.snap)
return 1;
return 0;
}

int cmp_bitwise(const hobject_t& l, const hobject_t& r)
int cmp(const hobject_t& l, const hobject_t& r)
{
if (l.max < r.max)
return -1;
Expand Down Expand Up @@ -606,27 +573,7 @@ bool ghobject_t::parse(const string& s)
return true;
}

int cmp_nibblewise(const ghobject_t& l, const ghobject_t& r)
{
if (l.max < r.max)
return -1;
if (l.max > r.max)
return 1;
if (l.shard_id < r.shard_id)
return -1;
if (l.shard_id > r.shard_id)
return 1;
int ret = cmp_nibblewise(l.hobj, r.hobj);
if (ret != 0)
return ret;
if (l.generation < r.generation)
return -1;
if (l.generation > r.generation)
return 1;
return 0;
}

int cmp_bitwise(const ghobject_t& l, const ghobject_t& r)
int cmp(const ghobject_t& l, const ghobject_t& r)
{
if (l.max < r.max)
return -1;
Expand All @@ -636,7 +583,7 @@ int cmp_bitwise(const ghobject_t& l, const ghobject_t& r)
return -1;
if (l.shard_id > r.shard_id)
return 1;
int ret = cmp_bitwise(l.hobj, r.hobj);
int ret = cmp(l.hobj, r.hobj);
if (ret != 0)
return ret;
if (l.generation < r.generation)
Expand Down
163 changes: 30 additions & 133 deletions src/common/hobject.h
Expand Up @@ -289,48 +289,22 @@ struct hobject_t {
void decode(json_spirit::Value& v);
void dump(Formatter *f) const;
static void generate_test_instances(list<hobject_t*>& o);
friend int cmp_nibblewise(const hobject_t& l, const hobject_t& r);
friend int cmp_bitwise(const hobject_t& l, const hobject_t& r);
friend int cmp(const hobject_t& l, const hobject_t& r);
friend bool operator>(const hobject_t& l, const hobject_t& r) {
return cmp(l, r) > 0;
}
friend bool operator>=(const hobject_t& l, const hobject_t& r) {
return cmp(l, r) >= 0;
}
friend bool operator<(const hobject_t& l, const hobject_t& r) {
return cmp(l, r) < 0;
}
friend bool operator<=(const hobject_t& l, const hobject_t& r) {
return cmp(l, r) <= 0;
}
friend bool operator==(const hobject_t&, const hobject_t&);
friend bool operator!=(const hobject_t&, const hobject_t&);
friend struct ghobject_t;

struct NibblewiseComparator {
bool operator()(const hobject_t& l, const hobject_t& r) const {
return cmp_nibblewise(l, r) < 0;
}
};

struct BitwiseComparator {
bool operator()(const hobject_t& l, const hobject_t& r) const {
return cmp_bitwise(l, r) < 0;
}
};

struct Comparator {
bool bitwise;
explicit Comparator(bool b) : bitwise(b) {}
bool operator()(const hobject_t& l, const hobject_t& r) const {
if (bitwise)
return cmp_bitwise(l, r) < 0;
else
return cmp_nibblewise(l, r) < 0;
}
};
struct ComparatorWithDefault {
bool bitwise;
explicit ComparatorWithDefault(bool b=true) : bitwise(b) {}
bool operator()(const hobject_t& l, const hobject_t& r) const {
if (bitwise)
return cmp_bitwise(l, r) < 0;
else
return cmp_nibblewise(l, r) < 0;
}
};
template <typename T>
using bitwisemap = std::map<hobject_t, T, BitwiseComparator>;

using bitwiseset = std::set<hobject_t, BitwiseComparator>;
};
WRITE_CLASS_ENCODER(hobject_t)

Expand Down Expand Up @@ -373,62 +347,20 @@ inline bool operator!=(const T&, const hobject_t &rhs) {
return !rhs.is_max();
}

extern int cmp_nibblewise(const hobject_t& l, const hobject_t& r);
extern int cmp_bitwise(const hobject_t& l, const hobject_t& r);
static inline int cmp(const hobject_t& l, const hobject_t& r, bool sort_bitwise) {
if (sort_bitwise)
return cmp_bitwise(l, r);
else
return cmp_nibblewise(l, r);
}
extern int cmp(const hobject_t& l, const hobject_t& r);
template <typename T>
static inline int cmp(const hobject_t &l, const T&, bool sort_bitwise) {
static inline int cmp(const hobject_t &l, const T&) {
static_assert(always_false<T>::value::value, "Do not compare to get_max()");
return l.is_max() ? 0 : -1;
}
template <typename T>
static inline int cmp(const T&, const hobject_t&r, bool sort_bitwise) {
static_assert(always_false<T>::value::value, "Do not compare to get_max()");
return r.is_max() ? 0 : 1;
}
template <typename T>
static inline int cmp_nibblewise(const hobject_t &l, const T&, bool sort_bitwise) {
static_assert(always_false<T>::value::value, "Do not compare to get_max()");
return l.is_max() ? 0 : -1;
}
template <typename T>
static inline int cmp_nibblewise(const T&, const hobject_t&r, bool sort_bitwise) {
static_assert(always_false<T>::value::value, "Do not compare to get_max()");
return r.is_max() ? 0 : 1;
}
template <typename T>
static inline int cmp_bitwise(const hobject_t &l, const T&, bool sort_bitwise) {
static_assert(always_false<T>::value::value, "Do not compare to get_max()");
return l.is_max() ? 0 : -1;
}
template <typename T>
static inline int cmp_bitwise(const T&, const hobject_t&r, bool sort_bitwise) {
static inline int cmp(const T&, const hobject_t&r) {
static_assert(always_false<T>::value::value, "Do not compare to get_max()");
return r.is_max() ? 0 : 1;
}



// these are convenient
static inline hobject_t MAX_HOBJ(const hobject_t& l, const hobject_t& r, bool bitwise) {
if (cmp(l, r, bitwise) >= 0)
return l;
else
return r;
}

static inline hobject_t MIN_HOBJ(const hobject_t& l, const hobject_t& r, bool bitwise) {
if (cmp(l, r, bitwise) <= 0)
return l;
else
return r;
}

typedef version_t gen_t;

struct ghobject_t {
Expand Down Expand Up @@ -530,33 +462,22 @@ struct ghobject_t {
size_t encoded_size() const;
void dump(Formatter *f) const;
static void generate_test_instances(list<ghobject_t*>& o);
friend int cmp_nibblewise(const ghobject_t& l, const ghobject_t& r);
friend int cmp_bitwise(const ghobject_t& l, const ghobject_t& r);
friend int cmp(const ghobject_t& l, const ghobject_t& r);
friend bool operator>(const ghobject_t& l, const ghobject_t& r) {
return cmp(l, r) > 0;
}
friend bool operator>=(const ghobject_t& l, const ghobject_t& r) {
return cmp(l, r) >= 0;
}
friend bool operator<(const ghobject_t& l, const ghobject_t& r) {
return cmp(l, r) < 0;
}
friend bool operator<=(const ghobject_t& l, const ghobject_t& r) {
return cmp(l, r) <= 0;
}
friend bool operator==(const ghobject_t&, const ghobject_t&);
friend bool operator!=(const ghobject_t&, const ghobject_t&);

struct NibblewiseComparator {
bool operator()(const ghobject_t& l, const ghobject_t& r) const {
return cmp_nibblewise(l, r) < 0;
}
};

struct BitwiseComparator {
bool operator()(const ghobject_t& l, const ghobject_t& r) const {
return cmp_bitwise(l, r) < 0;
}
};

struct Comparator {
bool bitwise;
explicit Comparator(bool b) : bitwise(b) {}
bool operator()(const ghobject_t& l, const ghobject_t& r) const {
if (bitwise)
return cmp_bitwise(l, r) < 0;
else
return cmp_nibblewise(l, r) < 0;
}
};
};
WRITE_CLASS_ENCODER(ghobject_t)

Expand All @@ -573,31 +494,7 @@ ostream& operator<<(ostream& out, const ghobject_t& o);

WRITE_EQ_OPERATORS_4(ghobject_t, max, shard_id, hobj, generation)

extern int cmp_nibblewise(const ghobject_t& l, const ghobject_t& r);
extern int cmp_bitwise(const ghobject_t& l, const ghobject_t& r);
static inline int cmp(const ghobject_t& l, const ghobject_t& r,
bool sort_bitwise) {
if (sort_bitwise)
return cmp_bitwise(l, r);
else
return cmp_nibblewise(l, r);
}

// these are convenient
static inline ghobject_t MAX_GHOBJ(const ghobject_t& l, const ghobject_t& r,
bool bitwise) {
if (cmp(l, r, bitwise) >= 0)
return l;
else
return r;
}
extern int cmp(const ghobject_t& l, const ghobject_t& r);

static inline ghobject_t MIN_GHOBJ(const ghobject_t& l, const ghobject_t& r,
bool bitwise) {
if (cmp(l, r, bitwise) <= 0)
return l;
else
return r;
}

#endif
4 changes: 2 additions & 2 deletions src/librados/librados.cc
Expand Up @@ -4205,7 +4205,7 @@ extern "C" int rados_object_list_cursor_cmp(
{
hobject_t *lhs = (hobject_t*)lhs_cur;
hobject_t *rhs = (hobject_t*)rhs_cur;
return cmp_bitwise(*lhs, *rhs);
return cmp(*lhs, *rhs);
}

extern "C" int rados_object_list(rados_ioctx_t io,
Expand Down Expand Up @@ -6073,7 +6073,7 @@ bool librados::ObjectCursor::operator<(const librados::ObjectCursor &rhs)
{
const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor);
const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor));
return cmp_bitwise(lhs_hobj, rhs_hobj) == -1;
return lhs_hobj < rhs_hobj;
}

librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs)
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MOSDSubOp.h
Expand Up @@ -70,7 +70,7 @@ class MOSDSubOp : public Message {
map<string,bufferlist> attrset;

interval_set<uint64_t> data_subset;
map<hobject_t, interval_set<uint64_t>, hobject_t::BitwiseComparator> clone_subsets;
map<hobject_t, interval_set<uint64_t>> clone_subsets;

bool first, complete;

Expand Down
2 changes: 1 addition & 1 deletion src/os/FuseStore.cc
Expand Up @@ -475,7 +475,7 @@ static int os_readdir(const char *path,
while (true) {
vector<ghobject_t> ls;
int r = fs->store->collection_list(
cid, next, last, true, 1000, &ls, &next);
cid, next, last, 1000, &ls, &next);
if (r < 0)
return r;
for (auto p : ls) {
Expand Down
15 changes: 7 additions & 8 deletions src/os/ObjectStore.h
Expand Up @@ -475,7 +475,7 @@ class ObjectStore {
void *osr {nullptr}; // NULL on replay

map<coll_t, __le32> coll_index;
map<ghobject_t, __le32, ghobject_t::BitwiseComparator> object_index;
map<ghobject_t, __le32> object_index;

__le32 coll_id {0};
__le32 object_id {0};
Expand Down Expand Up @@ -748,7 +748,7 @@ class ObjectStore {
}

vector<__le32> om(other.object_index.size());
map<ghobject_t, __le32, ghobject_t::BitwiseComparator>::iterator object_index_p;
map<ghobject_t, __le32>::iterator object_index_p;
for (object_index_p = other.object_index.begin();
object_index_p != other.object_index.end();
++object_index_p) {
Expand Down Expand Up @@ -894,7 +894,7 @@ class ObjectStore {
colls[coll_index_p->second] = coll_index_p->first;
}

map<ghobject_t, __le32, ghobject_t::BitwiseComparator>::iterator object_index_p;
map<ghobject_t, __le32>::iterator object_index_p;
for (object_index_p = t->object_index.begin();
object_index_p != t->object_index.end();
++object_index_p) {
Expand Down Expand Up @@ -996,7 +996,7 @@ class ObjectStore {
return index_id;
}
__le32 _get_object_id(const ghobject_t& oid) {
map<ghobject_t, __le32, ghobject_t::BitwiseComparator>::iterator o = object_index.find(oid);
map<ghobject_t, __le32>::iterator o = object_index.find(oid);
if (o != object_index.end())
return o->second;

Expand Down Expand Up @@ -1833,7 +1833,6 @@ class ObjectStore {
* @param c collection
* @param start list object that sort >= this value
* @param end list objects that sort < this value
* @param sort_bitwise sort bitwise (instead of legacy nibblewise)
* @param max return no more than this many results
* @param seq return no objects with snap < seq
* @param ls [out] result
Expand All @@ -1842,13 +1841,13 @@ class ObjectStore {
*/
virtual int collection_list(const coll_t& c,
const ghobject_t& start, const ghobject_t& end,
bool sort_bitwise, int max,
int max,
vector<ghobject_t> *ls, ghobject_t *next) = 0;
virtual int collection_list(CollectionHandle &c,
const ghobject_t& start, const ghobject_t& end,
bool sort_bitwise, int max,
int max,
vector<ghobject_t> *ls, ghobject_t *next) {
return collection_list(c->get_cid(), start, end, sort_bitwise, max, ls, next);
return collection_list(c->get_cid(), start, end, max, ls, next);
}


Expand Down

0 comments on commit 316dc98

Please sign in to comment.