| 99 | } |
| 100 | |
| 101 | bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) { |
| 102 | Slice memkey = key.memtable_key(); |
| 103 | Table::Iterator iter(&table_); |
| 104 | iter.Seek(memkey.data()); |
| 105 | if (iter.Valid()) { |
| 106 | // entry format is: |
| 107 | // klength varint32 |
| 108 | // userkey char[klength] |
| 109 | // tag uint64 |
| 110 | // vlength varint32 |
| 111 | // value char[vlength] |
| 112 | // Check that it belongs to same user key. We do not check the |
| 113 | // sequence number since the Seek() call above should have skipped |
| 114 | // all entries with overly large sequence numbers. |
| 115 | const char* entry = iter.key(); |
| 116 | uint32_t key_length; |
| 117 | const char* key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length); |
| 118 | if (comparator_.comparator.user_comparator()->Compare( |
| 119 | Slice(key_ptr, key_length - 8), key.user_key()) == 0) { |
| 120 | // Correct user key |
| 121 | const uint64_t tag = DecodeFixed64(key_ptr + key_length - 8); |
| 122 | switch (static_cast<ValueType>(tag & 0xff)) { |
| 123 | case kTypeValue: { |
| 124 | Slice v = GetLengthPrefixedSlice(key_ptr + key_length); |
| 125 | value->assign(v.data(), v.size()); |
| 126 | return true; |
| 127 | } |
| 128 | case kTypeDeletion: |
| 129 | *s = Status::NotFound(Slice()); |
| 130 | return true; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | } // namespace leveldb |
nothing calls this directly
no test coverage detected