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