Merge pull request #617 from rdallman/wb-merge-sliceparts

WriteBatch.Merge w/ SliceParts support
main
Igor Canadi 9 years ago
commit a187e66ad0
  1. 21
      db/write_batch.cc
  2. 17
      db/write_batch_base.cc
  3. 3
      db/write_batch_internal.h
  4. 7
      include/rocksdb/write_batch.h
  5. 5
      include/rocksdb/write_batch_base.h

@ -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<char>(kTypeMerge));
} else {
b->rep_.push_back(static_cast<char>(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<char>(kTypeLogData));
PutLengthPrefixedSlice(&rep_, blob);

@ -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

@ -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);

@ -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;

@ -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;

Loading…
Cancel
Save