Browse Source

更新 'leveldb_base/db/memtable.cc'

main
陈予曈 3 weeks ago
parent
commit
0f29779398
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      leveldb_base/db/memtable.cc

+ 6
- 5
leveldb_base/db/memtable.cc View File

@ -106,6 +106,7 @@ void MemTable::Add(SequenceNumber s, ValueType type, const Slice& key,
table_.Insert(buf);
}
//修改memtable读取逻辑-陈予曈
bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) {
Slice memkey = key.memtable_key();
Table::Iterator iter(&table_);
@ -130,30 +131,30 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) {
switch (static_cast<ValueType>(tag & 0xff)) {
case kTypeValue: {
Slice v = GetLengthPrefixedSlice(key_ptr + key_length);
// 过期则读取不到-柠
// 数据过期则读取不到-陈予曈
std::string value_with_ttl(v.data(), v.size());
if (value_with_ttl.size() >= 19) {
std::string expiration_time_str = value_with_ttl.substr(value_with_ttl.size() - 19); // 提取过期时间戳
std::tm tm = {};
char* res = strptime(expiration_time_str.c_str(), "%Y-%m-%d %H:%M:%S", &tm);
if (res == nullptr) {
if (res == nullptr) { //解析时间戳失败
value->assign(v.data(), v.size()-19);
return true;
} else {
std::time_t expiration_time = std::mktime(&tm);
std::time_t current_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
if (expiration_time <= current_time) {
if (expiration_time <= current_time) { //数据过期
//std::cerr << "notfound_mem" << std::endl;
*s = Status::NotFound(Slice());
value->assign(v.data(), 0);
}
else
else //数据未过期
{
value->assign(v.data(), v.size()-19);
}
return true;
}
} else {
} else { //时间戳信息不存在
value->assign(v.data(), v.size());
return true;
}

Loading…
Cancel
Save