Browse Source

修改sstable读取逻辑-陈予曈

main
陈予曈 2 months ago
parent
commit
d8768c59c6
1 changed files with 7 additions and 6 deletions
  1. +7
    -6
      leveldb_base/table/block.cc

+ 7
- 6
leveldb_base/table/block.cc View File

@ -15,7 +15,7 @@
#include "util/coding.h"
#include "util/logging.h"
// 添加所需头文件-
// 添加所需头文件-陈予曈
#include <iostream>
#include <sstream>
#include <iomanip>
@ -168,6 +168,7 @@ class Block::Iter : public Iterator {
} while (ParseNextKey() && NextEntryOffset() < original);
}
// 修改sstable读取逻辑-陈予曈
void Seek(const Slice& target) override {
// Binary search in restart array to find the last restart point
// with a key < target
@ -228,28 +229,28 @@ class Block::Iter : public Iterator {
return;
}
if (Compare(key_, target) >= 0) {
//重新解析record-柠
// 重新解析record-陈予曈
std::string value_with_ttl(value_.data(), value_.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_ = Slice(value_.data(), value_.size()-19);
} 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_sst" << std::endl;
status_ = Status::NotFound(Slice());
value_ = Slice(value_.data(), 0);
}
else
else //数据未过期
{
value_ = Slice(value_.data(), value_.size()-19);
}
}
} else {
} else { // 时间戳信息不存在
value_ = Slice(value_.data(), value_.size());
}
return;

Loading…
Cancel
Save