From d8768c59c6f5be503c7e91d93c416e8986f1b43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BA=88=E6=9B=88?= <10222140454@stu.ecnu.edu.cn> Date: Tue, 29 Oct 2024 10:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9sstable=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=80=BB=E8=BE=91-=E9=99=88=E4=BA=88=E6=9B=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- leveldb_base/table/block.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/leveldb_base/table/block.cc b/leveldb_base/table/block.cc index e7e34f2..57dba4a 100644 --- a/leveldb_base/table/block.cc +++ b/leveldb_base/table/block.cc @@ -15,7 +15,7 @@ #include "util/coding.h" #include "util/logging.h" -// 添加所需头文件-柠 +// 添加所需头文件-陈予曈 #include #include #include @@ -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;