Expose WriteBatch::Append().
WriteBatchInternal has a method for efficiently concatenating two WriteBatches. This commit exposes the method to the public API. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=208724311
This commit is contained in:
parent
6caf73ad9d
commit
f7b0e1d901
@ -112,6 +112,10 @@ void WriteBatch::Delete(const Slice& key) {
|
|||||||
PutLengthPrefixedSlice(&rep_, key);
|
PutLengthPrefixedSlice(&rep_, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteBatch::Append(const WriteBatch &source) {
|
||||||
|
WriteBatchInternal::Append(this, &source);
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class MemTableInserter : public WriteBatch::Handler {
|
class MemTableInserter : public WriteBatch::Handler {
|
||||||
public:
|
public:
|
||||||
|
@ -91,21 +91,21 @@ TEST(WriteBatchTest, Append) {
|
|||||||
WriteBatch b1, b2;
|
WriteBatch b1, b2;
|
||||||
WriteBatchInternal::SetSequence(&b1, 200);
|
WriteBatchInternal::SetSequence(&b1, 200);
|
||||||
WriteBatchInternal::SetSequence(&b2, 300);
|
WriteBatchInternal::SetSequence(&b2, 300);
|
||||||
WriteBatchInternal::Append(&b1, &b2);
|
b1.Append(b2);
|
||||||
ASSERT_EQ("",
|
ASSERT_EQ("",
|
||||||
PrintContents(&b1));
|
PrintContents(&b1));
|
||||||
b2.Put("a", "va");
|
b2.Put("a", "va");
|
||||||
WriteBatchInternal::Append(&b1, &b2);
|
b1.Append(b2);
|
||||||
ASSERT_EQ("Put(a, va)@200",
|
ASSERT_EQ("Put(a, va)@200",
|
||||||
PrintContents(&b1));
|
PrintContents(&b1));
|
||||||
b2.Clear();
|
b2.Clear();
|
||||||
b2.Put("b", "vb");
|
b2.Put("b", "vb");
|
||||||
WriteBatchInternal::Append(&b1, &b2);
|
b1.Append(b2);
|
||||||
ASSERT_EQ("Put(a, va)@200"
|
ASSERT_EQ("Put(a, va)@200"
|
||||||
"Put(b, vb)@201",
|
"Put(b, vb)@201",
|
||||||
PrintContents(&b1));
|
PrintContents(&b1));
|
||||||
b2.Delete("foo");
|
b2.Delete("foo");
|
||||||
WriteBatchInternal::Append(&b1, &b2);
|
b1.Append(b2);
|
||||||
ASSERT_EQ("Put(a, va)@200"
|
ASSERT_EQ("Put(a, va)@200"
|
||||||
"Put(b, vb)@202"
|
"Put(b, vb)@202"
|
||||||
"Put(b, vb)@201"
|
"Put(b, vb)@201"
|
||||||
|
@ -54,6 +54,13 @@ class LEVELDB_EXPORT WriteBatch {
|
|||||||
// releases. It is intended for LevelDB usage metrics.
|
// releases. It is intended for LevelDB usage metrics.
|
||||||
size_t ApproximateSize();
|
size_t ApproximateSize();
|
||||||
|
|
||||||
|
// Copies the operations in "source" to this batch.
|
||||||
|
//
|
||||||
|
// This runs in O(source size) time. However, the constant factor is better
|
||||||
|
// than calling Iterate() over the source batch with a Handler that replicates
|
||||||
|
// the operations into this batch.
|
||||||
|
void Append(const WriteBatch& source);
|
||||||
|
|
||||||
// Support for iterating over the contents of a batch.
|
// Support for iterating over the contents of a batch.
|
||||||
class Handler {
|
class Handler {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user