Browse Source

fix some redefine problem

main
kevinyao0901 2 months ago
parent
commit
c3d1bcd942
2 changed files with 37 additions and 29 deletions
  1. +34
    -29
      db/db_impl.cc
  2. +3
    -0
      db/db_impl.h

+ 34
- 29
db/db_impl.cc View File

@ -11,6 +11,9 @@
#include <set>
#include <string>
#include <vector>
#include <cstring> // For memcpy
#include <ctime> // For std::time
#include "db/builder.h"
#include "db/db_iter.h"
@ -34,11 +37,41 @@
#include "util/coding.h"
#include "util/logging.h"
#include "util/mutexlock.h"
#include "db_impl.h"
namespace leveldb {
const int kNumNonTableCacheFiles = 10;
//TTL ToDo : add func for TTL Put
void AppendExpirationTime(std::string* value, uint64_t expiration_time) {
// 将过期时间戳(64位整数)附加到值的前面
value->append(reinterpret_cast<const char*>(&expiration_time), sizeof(expiration_time));
}
uint64_t GetCurrentTime() {
// 返回当前的Unix时间戳
return static_cast<uint64_t>(time(nullptr));
}
// 解析过期时间戳
uint64_t ParseExpirationTime(const std::string& value) {
// 假设过期时间戳在值的前 8 字节,以大端序存储
assert(value.size() >= sizeof(uint64_t));
uint64_t expiration_time;
memcpy(&expiration_time, value.data(), sizeof(uint64_t));
return expiration_time;
}
// 解析出实际的值(去掉前面的过期时间戳部分)
std::string ParseActualValue(const std::string& value) {
// 去掉前 8 字节(存储过期时间戳),返回实际值
return value.substr(sizeof(uint64_t));
}
//finish modify
// Information kept for every waiting writer
struct DBImpl::Writer {
explicit Writer(port::Mutex* mu)
@ -1650,33 +1683,5 @@ Status DestroyDB(const std::string& dbname, const Options& options) {
return result;
}
// TTL ToDo: add func for TTL get
uint64_t ParseExpirationTime(const std::string& value) {
// 假设时间戳存储在值的前8个字节(64位整数)
uint64_t expiration_time;
memcpy(&expiration_time, value.data(), sizeof(uint64_t));
return expiration_time;
}
std::string ParseActualValue(const std::string& value) {
// 假设实际值存储在过期时间戳之后
return value.substr(sizeof(uint64_t));
}
//finish modify
//TTL ToDo : add func for TTL Put
void AppendExpirationTime(std::string* value, uint64_t expiration_time) {
// 将过期时间戳(64位整数)附加到值的前面
value->append(reinterpret_cast<const char*>(&expiration_time), sizeof(expiration_time));
}
uint64_t GetCurrentTime() {
// 返回当前的Unix时间戳
return static_cast<uint64_t>(time(nullptr));
}
//finish modify
} // namespace leveldb
} // namespace leveldb

+ 3
- 0
db/db_impl.h View File

@ -38,6 +38,9 @@ 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 Delete(const WriteOptions&, const Slice& key) override;
Status Write(const WriteOptions& options, WriteBatch* updates) override;
Status Get(const ReadOptions& options, const Slice& key,

Loading…
Cancel
Save