소스 검색

fix compile problem

main
kevinyao0901 4 주 전
부모
커밋
e7803e4705
4개의 변경된 파일24개의 추가작업 그리고 41개의 파일을 삭제
  1. +15
    -36
      db/db_impl.cc
  2. +2
    -3
      db/db_impl.h
  3. +7
    -0
      db/db_test.cc
  4. +0
    -2
      test/ttl_test.cc

+ 15
- 36
db/db_impl.cc 파일 보기

@ -11,9 +11,6 @@
#include <set>
#include <string>
#include <vector>
#include <cstring> // For memcpy
#include <ctime> // For std::time
#include "db/builder.h"
#include "db/db_iter.h"
@ -37,7 +34,6 @@
#include "util/coding.h"
#include "util/logging.h"
#include "util/mutexlock.h"
#include "db_impl.h"
namespace leveldb {
@ -1012,6 +1008,20 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
drop = true;
}
// TTL ToDo: add expiration time check
if (!drop) { // 如果还未被标记为丢弃
Slice value = input->value();
if (value.size() >= sizeof(uint64_t)) {
const char* ptr = value.data();
uint64_t expiration_time = DecodeFixed64(ptr);
uint64_t current_time = env_->NowMicros() / 1000000;
if (current_time > expiration_time) {
drop = true; // 过期的键值对,标记为丢弃
}
}
}
last_sequence_for_key = ikey.sequence;
}
#if 0
@ -1024,32 +1034,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
(int)last_sequence_for_key, (int)compact->smallest_snapshot);
#endif
//TTL ToDo: modify to add TTL check
// 添加过期时间的检查逻辑
if (!drop) {
// 获取值
Slice value = input->value();
// 检查值是否包含过期时间戳(假设过期时间戳存储在值的前8个字节)
if (value.size() >= sizeof(uint64_t)) {
const char* ptr = value.data();
uint64_t expiration_time = DecodeFixed64(ptr);
// 获取当前时间(单位:秒)
uint64_t current_time = env_->NowMicros() / 1000000;
// 如果当前时间超过过期时间,则丢弃该键值对
if (current_time > expiration_time) {
drop = true;
} else {
// 未过期,继续处理
}
} else {
// 值中没有过期时间戳,视为未过期,继续处理
}
}
//finish modify
if (!drop) {
// Open output file if necessary
if (compact->builder == nullptr) {
@ -1176,9 +1160,6 @@ int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes() {
return versions_->MaxNextLevelOverlappingBytes();
}
// TTL ToDo: modify Get function to implement TTL check
Status DBImpl::Get(const ReadOptions& options, const Slice& key,
std::string* value) {
Status s;
@ -1598,7 +1579,6 @@ Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value, ui
}
//finish modify
Status DB::Delete(const WriteOptions& opt, const Slice& key) {
WriteBatch batch;
batch.Delete(key);
@ -1683,5 +1663,4 @@ Status DestroyDB(const std::string& dbname, const Options& options) {
return result;
}
} // namespace leveldb
} // namespace leveldb

+ 2
- 3
db/db_impl.h 파일 보기

@ -38,9 +38,8 @@ class DBImpl : public DB {
// Implementations of the DB interface
Status Put(const WriteOptions&, const Slice& key,
const Slice& value) override;
//TTL ToDo
Status Put(const WriteOptions& o, const Slice& key, const Slice& val,
uint64_t ttl);
Status Put(const WriteOptions& , const Slice& key,
const Slice& value, uint64_t ttl) override;
Status Delete(const WriteOptions&, const Slice& key) override;
Status Write(const WriteOptions& options, WriteBatch* updates) override;
Status Get(const ReadOptions& options, const Slice& key,

+ 7
- 0
db/db_test.cc 파일 보기

@ -2117,6 +2117,13 @@ class ModelDB : public DB {
Status Put(const WriteOptions& o, const Slice& k, const Slice& v) override {
return DB::Put(o, k, v);
}
// TTL ToDo: add DBImpl for Put
// 新增支持TTL的Put方法
Status Put(const WriteOptions& o, const Slice& key, const Slice& val, uint64_t ttl) {
return DB::Put(o, key, val, ttl);
}
//finish modify
Status Delete(const WriteOptions& o, const Slice& key) override {
return DB::Delete(o, key);
}

+ 0
- 2
test/ttl_test.cc 파일 보기

@ -99,9 +99,7 @@ TEST(TestTTL, CompactionTTL) {
db->CompactRange(nullptr, nullptr);
leveldb::Range ranges[1];
ranges[0] = leveldb::Range("-", "A");
uint64_t sizes[1];
db->GetApproximateSizes(ranges, 1, sizes);
ASSERT_EQ(sizes[0], 0);
}

불러오는 중...
취소
저장