diff --git a/db/write_batch.cc b/db/write_batch.cc index 52956f8a8..53509b90f 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -275,6 +275,27 @@ void WriteBatch::Merge(ColumnFamilyHandle* column_family, const Slice& key, WriteBatchInternal::Merge(this, GetColumnFamilyID(column_family), key, value); } +void WriteBatchInternal::Merge(WriteBatch* b, uint32_t column_family_id, + const SliceParts& key, + const SliceParts& value) { + WriteBatchInternal::SetCount(b, WriteBatchInternal::Count(b) + 1); + if (column_family_id == 0) { + b->rep_.push_back(static_cast(kTypeMerge)); + } else { + b->rep_.push_back(static_cast(kTypeColumnFamilyMerge)); + PutVarint32(&b->rep_, column_family_id); + } + PutLengthPrefixedSliceParts(&b->rep_, key); + PutLengthPrefixedSliceParts(&b->rep_, value); +} + +void WriteBatch::Merge(ColumnFamilyHandle* column_family, + const SliceParts& key, + const SliceParts& value) { + WriteBatchInternal::Merge(this, GetColumnFamilyID(column_family), + key, value); +} + void WriteBatch::PutLogData(const Slice& blob) { rep_.push_back(static_cast(kTypeLogData)); PutLengthPrefixedSlice(&rep_, blob); diff --git a/db/write_batch_base.cc b/db/write_batch_base.cc index 5e3f5f08a..4eca5d259 100644 --- a/db/write_batch_base.cc +++ b/db/write_batch_base.cc @@ -43,4 +43,21 @@ void WriteBatchBase::Delete(const SliceParts& key) { Delete(key_slice); } +void WriteBatchBase::Merge(ColumnFamilyHandle* column_family, + const SliceParts& key, const SliceParts& value) { + std::string key_buf, value_buf; + Slice key_slice(key, &key_buf); + Slice value_slice(value, &value_buf); + + Merge(column_family, key_slice, value_slice); +} + +void WriteBatchBase::Merge(const SliceParts& key, const SliceParts& value) { + std::string key_buf, value_buf; + Slice key_slice(key, &key_buf); + Slice value_slice(value, &value_buf); + + Merge(key_slice, value_slice); +} + } // namespace rocksdb diff --git a/db/write_batch_internal.h b/db/write_batch_internal.h index 793c0d40f..18f106776 100644 --- a/db/write_batch_internal.h +++ b/db/write_batch_internal.h @@ -76,6 +76,9 @@ class WriteBatchInternal { static void Merge(WriteBatch* batch, uint32_t column_family_id, const Slice& key, const Slice& value); + static void Merge(WriteBatch* batch, uint32_t column_family_id, + const SliceParts& key, const SliceParts& value); + // Return the number of entries in the batch. static int Count(const WriteBatch* batch); diff --git a/include/rocksdb/write_batch.h b/include/rocksdb/write_batch.h index c096ae1ed..43b2574c2 100644 --- a/include/rocksdb/write_batch.h +++ b/include/rocksdb/write_batch.h @@ -66,6 +66,13 @@ class WriteBatch : public WriteBatchBase { Merge(nullptr, key, value); } + // variant that takes SliceParts + void Merge(ColumnFamilyHandle* column_family, const SliceParts& key, + const SliceParts& value) override; + void Merge(const SliceParts& key, const SliceParts& value) override { + Merge(nullptr, key, value); + } + using WriteBatchBase::Delete; // If the database contains a mapping for "key", erase it. Else do nothing. void Delete(ColumnFamilyHandle* column_family, const Slice& key) override; diff --git a/include/rocksdb/write_batch_base.h b/include/rocksdb/write_batch_base.h index a218cc1de..cfe3ceb48 100644 --- a/include/rocksdb/write_batch_base.h +++ b/include/rocksdb/write_batch_base.h @@ -40,6 +40,11 @@ class WriteBatchBase { const Slice& value) = 0; virtual void Merge(const Slice& key, const Slice& value) = 0; + // variant that takes SliceParts + virtual void Merge(ColumnFamilyHandle* column_family, const SliceParts& key, + const SliceParts& value); + virtual void Merge(const SliceParts& key, const SliceParts& value); + // If the database contains a mapping for "key", erase it. Else do nothing. virtual void Delete(ColumnFamilyHandle* column_family, const Slice& key) = 0; virtual void Delete(const Slice& key) = 0;