From: Haomai Wang Date: Sun, 26 Feb 2017 16:05:11 +0000 (+0800) Subject: db: add Append interface to allow merge write_batch X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e58f8c6dc36e62783a470ea857a62e64ff9820ba;p=rocksdb.git db: add Append interface to allow merge write_batch Signed-off-by: Haomai Wang --- diff --git a/db/write_batch.cc b/db/write_batch.cc index ea909e244..b66092204 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -1244,7 +1244,7 @@ void WriteBatchInternal::SetContents(WriteBatch* b, const Slice& contents) { b->content_flags_.store(ContentFlags::DEFERRED, std::memory_order_relaxed); } -void WriteBatchInternal::Append(WriteBatch* dst, const WriteBatch* src) { +void WriteBatchInternal::Append(WriteBatch* dst, WriteBatch* src) { SetCount(dst, Count(dst) + Count(src)); assert(src->rep_.size() >= WriteBatchInternal::kHeader); dst->rep_.append(src->rep_.data() + WriteBatchInternal::kHeader, @@ -1264,4 +1264,8 @@ size_t WriteBatchInternal::AppendedByteSize(size_t leftByteSize, } } +void WriteBatch::Append(WriteBatch& src) { + WriteBatchInternal::Append(this, &src); +} + } // namespace rocksdb diff --git a/db/write_batch_internal.h b/db/write_batch_internal.h index 1602fdbcc..77fbb79c3 100644 --- a/db/write_batch_internal.h +++ b/db/write_batch_internal.h @@ -177,7 +177,7 @@ class WriteBatchInternal { uint64_t log_number = 0, DB* db = nullptr, bool concurrent_memtable_writes = false); - static void Append(WriteBatch* dst, const WriteBatch* src); + static void Append(WriteBatch* dst, WriteBatch* src); // Returns the byte size of appending a WriteBatch with ByteSize // leftByteSize and a WriteBatch with ByteSize rightByteSize diff --git a/include/rocksdb/write_batch.h b/include/rocksdb/write_batch.h index 01f2108f1..ade7c7e6b 100644 --- a/include/rocksdb/write_batch.h +++ b/include/rocksdb/write_batch.h @@ -109,6 +109,7 @@ class WriteBatch : public WriteBatchBase { void Merge(const Slice& key, const Slice& value) override { Merge(nullptr, key, value); } + void Append(WriteBatch& src); // variant that takes SliceParts void Merge(ColumnFamilyHandle* column_family, const SliceParts& key,