Skip to content

Commit

Permalink
Add MemTableRep::NeedsUserKeyCompareInGet() and relavant changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rockeet committed Apr 24, 2023
1 parent d2ab1a6 commit 0541a65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion db/memtable.cc
Expand Up @@ -113,6 +113,7 @@ MemTable::MemTable(const InternalKeyComparator& cmp,
oldest_key_time_(std::numeric_limits<uint64_t>::max()),
atomic_flush_seqno_(kMaxSequenceNumber),
approximate_memory_usage_(0) {
needs_user_key_cmp_in_get_ = table_->NeedsUserKeyCompareInGet();
UpdateFlushState();
// something went wrong if we need to flush before inserting anything
assert(!ShouldScheduleFlush());
Expand Down Expand Up @@ -792,6 +793,7 @@ struct Saver {
bool do_merge;
bool allow_data_in_errors;
bool is_zero_copy;
bool needs_user_key_cmp_in_get;
bool CheckCallback(SequenceNumber _seq) {
if (callback_) {
return callback_->IsVisible(_seq);
Expand Down Expand Up @@ -832,8 +834,11 @@ static bool SaveValue(void* arg, const MemTableRep::KeyValuePair& pair) {
#else
constexpr size_t ts_sz = 0; // let compiler optimize it out
#endif
if (user_comparator->EqualWithoutTimestamp(user_key_slice,
if (!s->needs_user_key_cmp_in_get ||
user_comparator->EqualWithoutTimestamp(user_key_slice,
s->key->user_key())) {
assert(user_comparator->EqualWithoutTimestamp(user_key_slice,
s->key->user_key()));
// Correct user key
const uint64_t tag = DecodeFixed64(key_ptr + key_length - 8);
ValueType type;
Expand Down Expand Up @@ -1233,6 +1238,7 @@ bool MemTable::Get(const LookupKey& key, PinnableSlice* value,
saver.do_merge = do_merge;
saver.allow_data_in_errors = moptions_.allow_data_in_errors;
saver.is_zero_copy = read_opts.pinning_tls != nullptr;
saver.needs_user_key_cmp_in_get = needs_user_key_cmp_in_get_;
if (LIKELY(value != nullptr)) {
value->Reset();
}
Expand Down Expand Up @@ -1332,6 +1338,7 @@ void MemTable::MultiGet(const ReadOptions& read_options, MultiGetRange* range,
saver.do_merge = true;
saver.allow_data_in_errors = moptions_.allow_data_in_errors;
saver.is_zero_copy = read_options.pinning_tls != nullptr;
saver.needs_user_key_cmp_in_get = needs_user_key_cmp_in_get_;
table_->Get(read_options, *(iter->lkey), &saver, SaveValue);

if (!saver.found_final_value && saver.merge_in_progress) {
Expand Down
1 change: 1 addition & 0 deletions db/memtable.h
Expand Up @@ -557,6 +557,7 @@ class MemTable {
// These are used to manage memtable flushes to storage
bool flush_in_progress_; // started the flush
bool flush_completed_; // finished the flush
bool needs_user_key_cmp_in_get_;
uint64_t file_number_; // filled up after flush is complete

// The updates to be applied to the transaction log when this
Expand Down
2 changes: 2 additions & 0 deletions include/rocksdb/memtablerep.h
Expand Up @@ -343,6 +343,8 @@ class MemTableRep {
// Default: true
virtual bool IsSnapshotSupported() const { return true; }

virtual bool NeedsUserKeyCompareInGet() const { return true; }

protected:
// When *key is an internal key concatenated with the value, returns the
// user key.
Expand Down

0 comments on commit 0541a65

Please sign in to comment.