add \xff\xff prefix to returned keys

This commit is contained in:
chaoguang 2020-04-03 00:26:11 -07:00
parent 81dd97d27f
commit 36bf2ecf4c
2 changed files with 18 additions and 5 deletions

View File

@ -1281,7 +1281,7 @@ Future< Standalone<RangeResultRef> > ReadYourWritesTransaction::getRange(
}
// start with simplest point, special key space are only allowed to query if both begin and end start with \xff\xff
if (begin.getKey().startsWith(specialKeys.begin) && end.getKey().startsWith(specialKeys.end))
if (begin.getKey().startsWith(specialKeys.begin) && end.getKey().startsWith(specialKeys.begin))
return getDatabase()->specialKeySpace->getRange(Reference<ReadYourWritesTransaction>(this), begin, end, limits, snapshot, reverse);
// Use special key prefix "\xff\xff/transaction/conflicting_keys/<some_key>",

View File

@ -71,6 +71,15 @@ ACTOR Future<Standalone<RangeResultRef>> SpecialKeySpace::getRangeAggregationAct
state RangeMap<Key, SpecialKeyRangeBaseImpl*, KeyRangeRef>::Iterator iter;
state int actualBeginOffset;
state int actualEndOffset;
state bool prefixFlag = false;
// remove specialKeys prefix
if (begin.getKey().startsWith(specialKeys.begin)) {
prefixFlag = true;
ASSERT(end.getKey().startsWith(specialKeys.begin));
begin.setKey(begin.getKey().removePrefix(specialKeys.begin));
end.setKey(end.getKey().removePrefix(specialKeys.begin));
}
// make sure offset == 1
state RangeMap<Key, SpecialKeyRangeBaseImpl*, KeyRangeRef>::Iterator beginIter =
@ -150,11 +159,13 @@ ACTOR Future<Standalone<RangeResultRef>> SpecialKeySpace::getRangeAggregationAct
Standalone<RangeResultRef> pairs = wait(iter->value()->getRange(ryw, KeyRangeRef(keyStart, keyEnd)));
// limits handler
for (int i = pairs.size() - 1; i >= 0; --i) {
result.push_back_deep(result.arena(), pairs[i]);
// TODO : use depends on with push_back
KeyValueRef element = prefixFlag ? KeyValueRef(pairs[i].key.withPrefix(specialKeys.begin), pairs[i].value) : pairs[i];
result.push_back_deep(result.arena(), element);
// Note : behavior here is even the last k-v pair makes total bytes larger than specified, it is still
// returned In other words, the total size of the returned value (less the last entry) will be less than
// byteLimit
limits.decrement(pairs[i]);
limits.decrement(element);
if (limits.isReached()) {
result.more = true;
result.readToBegin = false;
@ -171,11 +182,13 @@ ACTOR Future<Standalone<RangeResultRef>> SpecialKeySpace::getRangeAggregationAct
Standalone<RangeResultRef> pairs = wait(iter->value()->getRange(ryw, KeyRangeRef(keyStart, keyEnd)));
// limits handler
for (int i = 0; i < pairs.size(); ++i) {
result.push_back_deep(result.arena(), pairs[i]);
// TODO : use depends on with push_back
KeyValueRef element = prefixFlag ? KeyValueRef(pairs[i].key.withPrefix(specialKeys.begin), pairs[i].value) : pairs[i];
result.push_back_deep(result.arena(), element);
// Note : behavior here is even the last k-v pair makes total bytes larger than specified, it is still
// returned In other words, the total size of the returned value (less the last entry) will be less than
// byteLimit
limits.decrement(pairs[i]);
limits.decrement(element);
if (limits.isReached()) {
result.more = true;
result.readThroughEnd = false;