|
@ -11,6 +11,9 @@ |
|
|
#include <set>
|
|
|
#include <set>
|
|
|
#include <string>
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
#include <vector>
|
|
|
|
|
|
#include <cstring> // For memcpy
|
|
|
|
|
|
#include <ctime> // For std::time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "db/builder.h"
|
|
|
#include "db/builder.h"
|
|
|
#include "db/db_iter.h"
|
|
|
#include "db/db_iter.h"
|
|
@ -34,11 +37,41 @@ |
|
|
#include "util/coding.h"
|
|
|
#include "util/coding.h"
|
|
|
#include "util/logging.h"
|
|
|
#include "util/logging.h"
|
|
|
#include "util/mutexlock.h"
|
|
|
#include "util/mutexlock.h"
|
|
|
|
|
|
#include "db_impl.h"
|
|
|
|
|
|
|
|
|
namespace leveldb { |
|
|
namespace leveldb { |
|
|
|
|
|
|
|
|
const int kNumNonTableCacheFiles = 10; |
|
|
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
|
|
|
// Information kept for every waiting writer
|
|
|
struct DBImpl::Writer { |
|
|
struct DBImpl::Writer { |
|
|
explicit Writer(port::Mutex* mu) |
|
|
explicit Writer(port::Mutex* mu) |
|
@ -1650,33 +1683,5 @@ Status DestroyDB(const std::string& dbname, const Options& options) { |
|
|
return result; |
|
|
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
|