|
@ -4,14 +4,6 @@ |
|
|
|
|
|
|
|
|
#include "db/db_impl.h"
|
|
|
#include "db/db_impl.h"
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
#include "db/builder.h"
|
|
|
#include "db/builder.h"
|
|
|
#include "db/db_iter.h"
|
|
|
#include "db/db_iter.h"
|
|
|
#include "db/dbformat.h"
|
|
|
#include "db/dbformat.h"
|
|
@ -22,11 +14,22 @@ |
|
|
#include "db/table_cache.h"
|
|
|
#include "db/table_cache.h"
|
|
|
#include "db/version_set.h"
|
|
|
#include "db/version_set.h"
|
|
|
#include "db/write_batch_internal.h"
|
|
|
#include "db/write_batch_internal.h"
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
#include "leveldb/db.h"
|
|
|
#include "leveldb/db.h"
|
|
|
#include "leveldb/env.h"
|
|
|
#include "leveldb/env.h"
|
|
|
#include "leveldb/status.h"
|
|
|
#include "leveldb/status.h"
|
|
|
#include "leveldb/table.h"
|
|
|
#include "leveldb/table.h"
|
|
|
#include "leveldb/table_builder.h"
|
|
|
#include "leveldb/table_builder.h"
|
|
|
|
|
|
|
|
|
#include "port/port.h"
|
|
|
#include "port/port.h"
|
|
|
#include "table/block.h"
|
|
|
#include "table/block.h"
|
|
|
#include "table/merger.h"
|
|
|
#include "table/merger.h"
|
|
@ -1152,6 +1155,24 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key, |
|
|
s = current->Get(options, lkey, value, &stats); |
|
|
s = current->Get(options, lkey, value, &stats); |
|
|
have_stat_update = true; |
|
|
have_stat_update = true; |
|
|
} |
|
|
} |
|
|
|
|
|
// 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()); |
|
|
|
|
|
if (dead_line != 0) { |
|
|
|
|
|
// use TTL
|
|
|
|
|
|
if (std::time(nullptr) >= dead_line) { |
|
|
|
|
|
*value = ""; |
|
|
|
|
|
s = Status::NotFound("Data expired"); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
*value = value->substr(separator + 1); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// TTL not set
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
mutex_.Lock(); |
|
|
mutex_.Lock(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1198,6 +1219,11 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) { |
|
|
return DB::Put(o, key, val); |
|
|
return DB::Put(o, key, val); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Status DBImpl::Put(const WriteOptions& options, const Slice& key, |
|
|
|
|
|
const Slice& value, uint64_t ttl) { |
|
|
|
|
|
return DB::Put(options, key, value, ttl); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
return DB::Delete(options, key); |
|
|
return DB::Delete(options, key); |
|
|
} |
|
|
} |
|
@ -1485,12 +1511,28 @@ void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) { |
|
|
|
|
|
|
|
|
// Default implementations of convenience methods that subclasses of DB
|
|
|
// Default implementations of convenience methods that subclasses of DB
|
|
|
// can call if they wish
|
|
|
// can call if they wish
|
|
|
|
|
|
// TTL: Update TTL Encode
|
|
|
Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
WriteBatch batch; |
|
|
WriteBatch batch; |
|
|
batch.Put(key, value); |
|
|
|
|
|
|
|
|
// char * ttl_encode = new char[8];
|
|
|
|
|
|
// EncodeFixed64(ttl_encode, 0);
|
|
|
|
|
|
std::string ttl_value = "0|" + value.ToString(); |
|
|
|
|
|
batch.Put(key, ttl_value); |
|
|
return Write(opt, &batch); |
|
|
return Write(opt, &batch); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TTL: Put methods for ttl
|
|
|
|
|
|
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); |
|
|
|
|
|
return Write(options, &batch); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Status DB::Delete(const WriteOptions& opt, const Slice& key) { |
|
|
Status DB::Delete(const WriteOptions& opt, const Slice& key) { |
|
|
WriteBatch batch; |
|
|
WriteBatch batch; |
|
|
batch.Delete(key); |
|
|
batch.Delete(key); |
|
|