Simplify MemTable::Update

Summary:
As suggested by testn in #1650

The Add is at the end of the function. Having a fallthough
will result in it being added twice.
Closes https://github.com/facebook/rocksdb/pull/1676

Differential Revision: D4331906

Pulled By: yiwu-arbug

fbshipit-source-id: 895c4a0
main
Daniel Black 8 years ago committed by Facebook Github Bot
parent 1a136c1f13
commit 342370f1d3
  1. 38
      db/memtable.cc

@ -717,30 +717,22 @@ void MemTable::Update(SequenceNumber seq,
ValueType type; ValueType type;
SequenceNumber unused; SequenceNumber unused;
UnPackSequenceAndType(tag, &unused, &type); UnPackSequenceAndType(tag, &unused, &type);
switch (type) { if (type == kTypeValue) {
case kTypeValue: { Slice prev_value = GetLengthPrefixedSlice(key_ptr + key_length);
Slice prev_value = GetLengthPrefixedSlice(key_ptr + key_length); uint32_t prev_size = static_cast<uint32_t>(prev_value.size());
uint32_t prev_size = static_cast<uint32_t>(prev_value.size()); uint32_t new_size = static_cast<uint32_t>(value.size());
uint32_t new_size = static_cast<uint32_t>(value.size());
// Update value, if new value size <= previous value size
// Update value, if new value size <= previous value size if (new_size <= prev_size ) {
if (new_size <= prev_size ) { char* p = EncodeVarint32(const_cast<char*>(key_ptr) + key_length,
char* p = EncodeVarint32(const_cast<char*>(key_ptr) + key_length, new_size);
new_size); WriteLock wl(GetLock(lkey.user_key()));
WriteLock wl(GetLock(lkey.user_key())); memcpy(p, value.data(), value.size());
memcpy(p, value.data(), value.size()); assert((unsigned)((p + value.size()) - entry) ==
assert((unsigned)((p + value.size()) - entry) == (unsigned)(VarintLength(key_length) + key_length +
(unsigned)(VarintLength(key_length) + key_length + VarintLength(value.size()) + value.size()));
VarintLength(value.size()) + value.size())); return;
return;
}
} }
// fallthrough
default:
// If the latest value is kTypeDeletion, kTypeMerge or kTypeLogData
// we don't have enough space for update inplace
Add(seq, kTypeValue, key, value);
return;
} }
} }
} }

Loading…
Cancel
Save