mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
WriteBatch::Put() overload that gathers key and value from arrays of slices
Summary: In our project, when writing to the database, we want to form the value as the concatenation of a small header and a larger payload. It's a shame to have to copy the payload just so we can give RocksDB API a linear view of the value. Since RocksDB makes a copy internally, it's easy to support gather writes. Test Plan: write_batch_test, new test case Reviewers: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D13947
This commit is contained in:
@@ -98,6 +98,16 @@ class Slice {
|
||||
// Intentionally copyable
|
||||
};
|
||||
|
||||
// A set of Slices that are virtually concatenated together. 'parts' points
|
||||
// to an array of Slices. The number of elements in the array is 'num_parts'.
|
||||
struct SliceParts {
|
||||
SliceParts(const Slice* parts, int num_parts) :
|
||||
parts(parts), num_parts(num_parts) { }
|
||||
|
||||
const Slice* parts;
|
||||
int num_parts;
|
||||
};
|
||||
|
||||
inline bool operator==(const Slice& x, const Slice& y) {
|
||||
return ((x.size() == y.size()) &&
|
||||
(memcmp(x.data(), y.data(), x.size()) == 0));
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
namespace rocksdb {
|
||||
|
||||
class Slice;
|
||||
class SliceParts;
|
||||
|
||||
class WriteBatch {
|
||||
public:
|
||||
@@ -36,6 +37,11 @@ class WriteBatch {
|
||||
// Store the mapping "key->value" in the database.
|
||||
void Put(const Slice& key, const Slice& value);
|
||||
|
||||
// Variant of Put() that gathers output like writev(2). The key and value
|
||||
// that will be written to the database are concatentations of arrays of
|
||||
// slices.
|
||||
void Put(const SliceParts& key, const SliceParts& value);
|
||||
|
||||
// Merge "value" with the existing value of "key" in the database.
|
||||
// "key->merge(existing, value)"
|
||||
void Merge(const Slice& key, const Slice& value);
|
||||
|
||||
Reference in New Issue
Block a user