Sfoglia il codice sorgente

修改sstable读取逻辑-陈予曈

main
陈予曈 7 mesi fa
parent
commit
d8768c59c6
1 ha cambiato i file con 7 aggiunte e 6 eliminazioni
  1. +7
    -6
      leveldb_base/table/block.cc

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

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

||||||
x
 
000:0
Caricamento…
Annulla
Salva