Skip to content

Commit

Permalink
backout changes for rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sears committed Apr 28, 2020
1 parent b0eefef commit 2b38b4a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 47 deletions.
59 changes: 32 additions & 27 deletions fdbserver/DeltaTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ static int perfectSubtreeSplitPointCached(int subtree_size) {
// // commonPrefix can be passed in if known
// void writeDelta(dT &d, const T &base, int commonPrefix = -1) const;
//
// // Compare *this to t.
// // Compare *this to t, returns < 0 for less than, 0 for equal, > 0 for greater than
// // The first skipLen bytes can be assumed to be equal
// comparison compare(const T &rhs, int skipLen) const;
// int compare(const T &rhs, int skipLen) const;
//
// // Get the common prefix bytes between *this and base
// // skip is a hint of how many prefix bytes are already known to be the same
// int getCommonPrefixLen(const T &base, int skip) const;
//
// // Returns the size of the delta object needed to make *this from base
// // TODO: Explain contract required for deltaSize to be used to predict final
// // TODO: Explain contract required for deltaSize to be used to predict final
// // balanced tree size incrementally while adding sorted items to a build set
// int deltaSize(const T &base) const;
//
Expand Down Expand Up @@ -365,12 +365,12 @@ struct DeltaTree {
bool addLeftChild = false;

while(n != nullptr) {
comparison cmp = k.compare(n->item, skipLen);
int cmp = k.compare(n->item, skipLen);

if (cmp >= 0) {
if(cmp >= 0) {
// If we found an item identical to k then if it is deleted, undeleted it,
// otherwise fail
if (cmp == 0) {
if(cmp == 0) {
auto &d = n->raw->delta();
if(d.getDeleted()) {
d.setDeleted(false);
Expand All @@ -389,7 +389,8 @@ struct DeltaTree {
}

n = right;
} else {
}
else {
DecodedNode *left = n->getLeftChild(arena);

if(left == nullptr) {
Expand Down Expand Up @@ -531,46 +532,48 @@ struct DeltaTree {
// returns true, otherwise returns false and the cursor position will be invalid.
// If pHint is given then initialCmp must be logically equivalent to s.compare(pHint->get())
// If hintFwd is omitted, it will be calculated (see other definitions above)
bool seekLessThanOrEqual(const T& s, int skipLen, const Cursor* pHint, comparison initialCmp) {
bool seekLessThanOrEqual(const T &s, int skipLen, const Cursor *pHint, int initialCmp) {
DecodedNode *n;

// If there's a hint position, use it
// At the end of using the hint, if n is valid it should point to a node which has not yet been compared to.
if(pHint != nullptr && pHint->node != nullptr) {
n = pHint->node;
if (initialCmp == 0) {
if(initialCmp == 0) {
node = n;
return _hideDeletedBackward();
}
if (initialCmp > 0) {
if(initialCmp > 0) {
node = n;
while(n != nullptr) {
n = n->jumpNext(mirror->root);
if(n == nullptr) {
break;
}

comparison cmp = s.compare(n->item, skipLen);
if (cmp > 0) {
int cmp = s.compare(n->item, skipLen);
if(cmp > 0) {
node = n;
continue;
}
if (cmp == 0) {
if(cmp == 0) {
node = n;
n = nullptr;
} else {
}
else {
n = n->leftChild;
}
break;
}
} else {
}
else {
while(n != nullptr) {
n = n->jumpPrev(mirror->root);
if(n == nullptr) {
break;
}
comparison cmp = s.compare(n->item, skipLen);
if (cmp >= 0) {
int cmp = s.compare(n->item, skipLen);
if(cmp >= 0) {
node = n;
n = (cmp == 0) ? nullptr : n->rightChild;
break;
Expand All @@ -585,15 +588,16 @@ struct DeltaTree {
}

while(n != nullptr) {
comparison cmp = s.compare(n->item, skipLen);
int cmp = s.compare(n->item, skipLen);

if (cmp < 0) {
if(cmp < 0) {
n = n->getLeftChild(mirror->arena);
} else {
}
else {
// n <= s so store it in node as a potential result
node = n;

if (cmp == 0) {
if(cmp == 0) {
break;
}

Expand All @@ -611,15 +615,16 @@ struct DeltaTree {
node = nullptr;

while(n != nullptr) {
comparison cmp = s.compare(n->item, skipLen);
int cmp = s.compare(n->item, skipLen);

if (cmp > 0) {
if(cmp > 0) {
n = n->getRightChild(mirror->arena);
} else {
}
else {
// n >= s so store it in node as a potential result
node = n;

if (cmp == 0) {
if(cmp == 0) {
break;
}

Expand All @@ -637,9 +642,9 @@ struct DeltaTree {
node = nullptr;

while(n != nullptr) {
comparison cmp = s.compare(n->item, skipLen);
int cmp = s.compare(n->item, skipLen);

if (cmp == 0) {
if(cmp == 0) {
if(n->isDeleted()) {
return false;
}
Expand Down
45 changes: 25 additions & 20 deletions fdbserver/VersionedBTree.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,16 +1888,16 @@ struct SplitStringRef {
return {b.end()};
}

template <typename StringT>
comparison compare(const StringT& rhs) const {
template<typename StringT>
int compare(const StringT &rhs) const {
auto j = begin();
auto k = rhs.begin();
auto jEnd = end();
auto kEnd = rhs.end();

while(j != jEnd && k != kEnd) {
comparison cmp = ::compare(*j, *k);
if (cmp != 0) {
int cmp = *j - *k;
if(cmp != 0) {
return cmp;
}
}
Expand All @@ -1909,6 +1909,7 @@ struct SplitStringRef {

return 1;
}

};

// A BTree "page id" is actually a list of LogicalPageID's whose contents should be concatenated together.
Expand Down Expand Up @@ -2018,20 +2019,20 @@ struct RedwoodRecordRef {
}

// Compares and orders by key, version, chunk.start, chunk.total, value
comparison compare(const RedwoodRecordRef& rhs, int skip = 0) const {
int compare(const RedwoodRecordRef &rhs, int skip = 0) const {
int keySkip = std::min(skip, key.size());
comparison cmp = key.substr(keySkip).compare(rhs.key.substr(keySkip));
int cmp = key.substr(keySkip).compare(rhs.key.substr(keySkip));

if (cmp == 0) {
cmp = ::compare(version, rhs.version);
if (cmp == 0) {
if(cmp == 0) {
cmp = version - rhs.version;
if(cmp == 0) {
// It is assumed that in any data set there will never be more than one
// unique chunk total size for the same key and version, so sort by start, total
// Chunked (represented by chunk.total > 0) sorts higher than whole
cmp = ::compare(chunk.start, rhs.chunk.start);
if (cmp == 0) {
cmp = ::compare(chunk.total, rhs.chunk.total);
if (cmp == 0) {
cmp = chunk.start - rhs.chunk.start;
if(cmp == 0) {
cmp = chunk.total - rhs.chunk.total;
if(cmp == 0) {
cmp = value.compare(rhs.value);
}
}
Expand Down Expand Up @@ -4162,7 +4163,7 @@ class VersionedBTree : public IVersionedStore {
else {
// Otherwise we must visit the records. If updating, the visit is to erase them, and if doing a
// linear merge than the visit is to add them to the output set.
while (cursor.valid() && cursor.get().compare(end, skipLen) < 0) {
while(cursor.valid() && cursor.get().compare(end, skipLen) < 0) {
if(updating) {
debug_printf("%s Erasing %s [existing, boundary start]\n", context.c_str(), cursor.get().toString().c_str());
cursor.erase();
Expand Down Expand Up @@ -5559,21 +5560,25 @@ struct IntIntPair {
return 0;
}

comparison compare(const IntIntPair& rhs, int skip = 0) const {
int compare(const IntIntPair &rhs, int skip = 0) const {
if(skip == 2) {
return 0;
}
comparison cmp = (skip > 0) ? 0 : ::compare(k, rhs.k);
int cmp = (skip > 0) ? 0 : (k - rhs.k);

if (cmp == 0) {
cmp = ::compare(v, rhs.v);
if(cmp == 0) {
cmp = v - rhs.v;
}
return cmp;
}

bool operator==(const IntIntPair& rhs) const { return compare(rhs) == 0; }
bool operator==(const IntIntPair &rhs) const {
return compare(rhs) == 0;
}

bool operator<(const IntIntPair& rhs) const { return compare(rhs) < 0; }
bool operator<(const IntIntPair &rhs) const {
return compare(rhs) < 0;
}

int deltaSize(const IntIntPair &base, bool worstcase = false, int skipLen = 0) const {
return sizeof(Delta);
Expand Down

0 comments on commit 2b38b4a

Please sign in to comment.