|
|
@ -1157,18 +1157,15 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key, |
|
|
|
} |
|
|
|
// TTL: Get the true value and make sure the data is still living
|
|
|
|
if(!value->empty()) { |
|
|
|
auto separator = value->find_first_of("|"); |
|
|
|
std::string ddl_str = value->substr(0, separator); |
|
|
|
uint64_t dead_line = std::atoll(ddl_str.c_str()); |
|
|
|
uint64_t dead_line; |
|
|
|
DecodeDeadLineValue(value, dead_line); |
|
|
|
if (dead_line != 0) { |
|
|
|
// use TTL
|
|
|
|
if (std::time(nullptr) >= dead_line) { |
|
|
|
// data expired
|
|
|
|
*value = ""; |
|
|
|
s = Status::NotFound("Data expired"); |
|
|
|
} |
|
|
|
else { |
|
|
|
*value = value->substr(separator + 1); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// TTL not set
|
|
|
|
} |
|
|
@ -1514,10 +1511,7 @@ void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) { |
|
|
|
// TTL: Update TTL Encode
|
|
|
|
Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
|
WriteBatch batch; |
|
|
|
// char * ttl_encode = new char[8];
|
|
|
|
// EncodeFixed64(ttl_encode, 0);
|
|
|
|
std::string ttl_value = "0|" + value.ToString(); |
|
|
|
batch.Put(key, ttl_value); |
|
|
|
batch.Put(key, EncodeDeadLine(0, value)); |
|
|
|
return Write(opt, &batch); |
|
|
|
} |
|
|
|
|
|
|
@ -1525,11 +1519,8 @@ Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
|
Status DB::Put(const WriteOptions& options, const Slice& key, |
|
|
|
const Slice& value, uint64_t ttl) { |
|
|
|
WriteBatch batch; |
|
|
|
// char * ttl_encode = new char[8];
|
|
|
|
// EncodeFixed64(ttl_encode, std::time(nullptr) + ttl);
|
|
|
|
auto dead_line = std::time(nullptr) + ttl; |
|
|
|
std::string ttl_value = std::to_string(dead_line) + "|" + value.ToString(); |
|
|
|
batch.Put(key, ttl_value); |
|
|
|
batch.Put(key, EncodeDeadLine(dead_line, value)); |
|
|
|
return Write(options, &batch); |
|
|
|
} |
|
|
|
|
|
|
|