From 36bf2ecf4c6a97a3610bc47bea60e11c34b888d8 Mon Sep 17 00:00:00 2001 From: chaoguang <13974480+zjuLcg@users.noreply.github.com> Date: Fri, 3 Apr 2020 00:26:11 -0700 Subject: [PATCH] add \xff\xff prefix to returned keys --- fdbclient/ReadYourWrites.actor.cpp | 2 +- fdbclient/SpecialKeySpace.actor.cpp | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.actor.cpp index 5aabb379d7..dea11a5653 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.actor.cpp @@ -1281,7 +1281,7 @@ Future< Standalone > 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(this), begin, end, limits, snapshot, reverse); // Use special key prefix "\xff\xff/transaction/conflicting_keys/", diff --git a/fdbclient/SpecialKeySpace.actor.cpp b/fdbclient/SpecialKeySpace.actor.cpp index 1b00389e8a..e5b2ed6005 100644 --- a/fdbclient/SpecialKeySpace.actor.cpp +++ b/fdbclient/SpecialKeySpace.actor.cpp @@ -71,6 +71,15 @@ ACTOR Future> SpecialKeySpace::getRangeAggregationAct state RangeMap::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::Iterator beginIter = @@ -150,11 +159,13 @@ ACTOR Future> SpecialKeySpace::getRangeAggregationAct Standalone 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> SpecialKeySpace::getRangeAggregationAct Standalone 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;