Skip to content

Commit

Permalink
Merge pull request #4700 from Daniel-B-Smith/range-read-copy
Browse files Browse the repository at this point in the history
Remove unnecessary copy of KVS entries into range read response
  • Loading branch information
sears committed Apr 22, 2021
2 parents 77af97c + aeb4938 commit e3ce689
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fdbserver/storageserver.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ ACTOR Future<Void> getShardStateQ(StorageServer* data, GetShardStateRequest req)
void merge(Arena& arena,
VectorRef<KeyValueRef, VecSerStrategy::String>& output,
VectorRef<KeyValueRef> const& vm_output,
VectorRef<KeyValueRef> const& base,
Standalone<RangeResultRef> const& base,
int& vCount,
int limit,
bool stopAtEndOfBase,
Expand All @@ -1448,6 +1448,9 @@ void merge(Arena& arena,
// start is still inclusive and end is exclusive
{
ASSERT(limit != 0);
// Add a dependency of the new arena on the result from the KVS so that we don't have to copy any of the KVS
// results.
arena.dependsOn(base.arena());

bool forward = limit > 0;
if (!forward)
Expand All @@ -1458,7 +1461,7 @@ void merge(Arena& arena,
KeyValueRef const* baseEnd = base.end();
while (baseStart != baseEnd && vCount > 0 && output.size() < adjustedLimit && accumulatedBytes < limitBytes) {
if (forward ? baseStart->key < vm_output[pos].key : baseStart->key > vm_output[pos].key) {
output.push_back_deep(arena, *baseStart++);
output.push_back(arena, *baseStart++);
} else {
output.push_back_deep(arena, vm_output[pos]);
if (baseStart->key == vm_output[pos].key)
Expand All @@ -1469,7 +1472,7 @@ void merge(Arena& arena,
accumulatedBytes += sizeof(KeyValueRef) + output.end()[-1].expectedSize();
}
while (baseStart != baseEnd && output.size() < adjustedLimit && accumulatedBytes < limitBytes) {
output.push_back_deep(arena, *baseStart++);
output.push_back(arena, *baseStart++);
accumulatedBytes += sizeof(KeyValueRef) + output.end()[-1].expectedSize();
}
if (!stopAtEndOfBase) {
Expand Down

0 comments on commit e3ce689

Please sign in to comment.