浏览代码

跑通了mmtable中的逻辑

pull/2/head
augurier 2 个月前
父节点
当前提交
885d1dfcb0
共有 2 个文件被更改,包括 4 次插入8 次删除
  1. +2
    -6
      db/dbformat.cc
  2. +2
    -2
      db/memtable.cc

+ 2
- 6
db/dbformat.cc 查看文件

@ -58,14 +58,10 @@ int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const {
// increasing user key (according to user-supplied comparator)
// decreasing sequence number
// decreasing type (though sequence# should be enough to disambiguate)
Slice user_akey = ExtractUserKey(akey);
Slice user_bkey = ExtractUserKey(bkey);
std::string a = user_akey.ToString();
std::string b = user_bkey.ToString();
int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey));
if (r == 0) {
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8);
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8);
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8) | 0b10;
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8) | 0b10;
if (anum > bnum) {
r = -1;
} else if (anum < bnum) {

+ 2
- 2
db/memtable.cc 查看文件

@ -138,7 +138,7 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) {
uint32_t key_length;
const char* key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length);
std::cout << " get:" << ExtractUserKey(Slice(key_ptr, key_length)).ToString();
std::cout << " get:" << ExtractUserKey(Slice(key_ptr, key_length)).ToString() << std::endl;
if (comparator_.comparator.user_comparator()->Compare(
ExtractUserKey(Slice(key_ptr, key_length)), key.user_key()) == 0) {
// Correct user key
@ -151,7 +151,7 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) {
time(&nowTime);
assert(nowTime > 0);
const uint64_t deadTime = DecodeFixed64(key_ptr + key_length - 16);
if(static_cast<uint64_t>(nowTime) > deadTime){ //过期了
if(static_cast<uint64_t>(nowTime) >= deadTime){ //过期了
std::cout << nowTime << "dead:" << deadTime << std::endl;
*s = Status::NotFound(Slice());
return true; //todo:之前有没过期的key

正在加载...
取消
保存