Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions fdbclient/include/fdbclient/FDBTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,23 @@ struct KeyValueRef {
KeyRef key;
ValueRef value;
KeyValueRef() {}

KeyValueRef(const KeyRef& key, const ValueRef& value) : key(key), value(value) {}
KeyValueRef(Arena& a, const KeyValueRef& copyFrom) : key(a, copyFrom.key), value(a, copyFrom.value) {}

KeyValueRef(Arena& a, const KeyRef& key, const ValueRef& value) {
StringRef storage = makeString(key.size() + value.size(), a);
uint8_t* dst = mutateString(storage);

key.copyTo(dst);
value.copyTo(dst + key.size());

this->key = KeyRef(storage.begin(), key.size());
this->value = ValueRef(storage.begin() + key.size(), value.size());
}

KeyValueRef(Arena& a, const KeyValueRef& copyFrom) : KeyValueRef(a, copyFrom.key, copyFrom.value) {}

bool operator==(const KeyValueRef& r) const { return key == r.key && value == r.value; }
bool operator!=(const KeyValueRef& r) const { return key != r.key || value != r.value; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good


int expectedSize() const { return key.expectedSize() + value.expectedSize(); }

Expand Down
16 changes: 10 additions & 6 deletions fdbserver/kvstore/KeyValueStoreRocksDB.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,9 +1916,11 @@ struct RocksDBKeyValueStore : IKeyValueStore {
auto cursor = readIter.iter;
cursor->Seek(toSlice(a.keys.begin));
while (cursor->Valid() && toStringRef(cursor->key()) < a.keys.end) {
KeyValueRef kv(toStringRef(cursor->key()), toStringRef(cursor->value()));
accumulatedBytes += sizeof(KeyValueRef) + kv.expectedSize();
result.push_back_deep(result.arena(), kv);
KeyRef key = toStringRef(cursor->key());
ValueRef value = toStringRef(cursor->value());

accumulatedBytes += sizeof(KeyValueRef) + key.expectedSize() + value.expectedSize();
result.emplace_back_deep(result.arena(), key, value);
// Calling `cursor->Next()` is potentially expensive, so short-circut here just in case.
if (result.size() >= a.rowLimit || accumulatedBytes >= a.byteLimit) {
break;
Expand Down Expand Up @@ -1949,9 +1951,11 @@ struct RocksDBKeyValueStore : IKeyValueStore {
cursor->Prev();
}
while (cursor->Valid() && toStringRef(cursor->key()) >= a.keys.begin) {
KeyValueRef kv(toStringRef(cursor->key()), toStringRef(cursor->value()));
accumulatedBytes += sizeof(KeyValueRef) + kv.expectedSize();
result.push_back_deep(result.arena(), kv);
KeyRef key = toStringRef(cursor->key());
ValueRef value = toStringRef(cursor->value());

accumulatedBytes += sizeof(KeyValueRef) + key.expectedSize() + value.expectedSize();
result.emplace_back_deep(result.arena(), key, value);
// Calling `cursor->Prev()` is potentially expensive, so short-circut here just in case.
if (result.size() >= -a.rowLimit || accumulatedBytes >= a.byteLimit) {
break;
Expand Down
16 changes: 10 additions & 6 deletions fdbserver/kvstore/KeyValueStoreShardedRocksDB.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,11 @@ int readRangeInDb(PhysicalShard* shard,
auto* cursor = readIter->iter.get();
cursor->Seek(toSlice(range.begin));
while (cursor->Valid() && toStringRef(cursor->key()) < range.end) {
KeyValueRef kv(toStringRef(cursor->key()), toStringRef(cursor->value()));
accumulatedBytes += sizeof(KeyValueRef) + kv.expectedSize();
result->push_back_deep(result->arena(), kv);
KeyRef key = toStringRef(cursor->key());
ValueRef value = toStringRef(cursor->value());

accumulatedBytes += sizeof(KeyValueRef) + key.expectedSize() + value.expectedSize();
result->emplace_back_deep(result->arena(), key, value);
// Calling `cursor->Next()` is potentially expensive, so short-circut here just in case.
if (result->size() >= rowLimit || accumulatedBytes >= byteLimit) {
break;
Expand All @@ -1128,9 +1130,11 @@ int readRangeInDb(PhysicalShard* shard,
cursor->Prev();
}
while (cursor->Valid() && toStringRef(cursor->key()) >= range.begin) {
KeyValueRef kv(toStringRef(cursor->key()), toStringRef(cursor->value()));
accumulatedBytes += sizeof(KeyValueRef) + kv.expectedSize();
result->push_back_deep(result->arena(), kv);
KeyRef key = toStringRef(cursor->key());
ValueRef value = toStringRef(cursor->value());

accumulatedBytes += sizeof(KeyValueRef) + key.expectedSize() + value.expectedSize();
result->emplace_back_deep(result->arena(), key, value);
// Calling `cursor->Prev()` is potentially expensive, so short-circuit here just in case.
if (result->size() >= -rowLimit || accumulatedBytes >= byteLimit) {
break;
Expand Down