WriteBatch.Merge w/ SliceParts support

also hooked up WriteBatchInternal
This commit is contained in:
Reed Allman 2015-05-27 16:59:22 -07:00
parent 3ab8ffd4dd
commit a0635ba3f6
5 changed files with 53 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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