|
@ -1178,18 +1178,24 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key, |
|
|
} |
|
|
} |
|
|
mutex_.Lock(); |
|
|
mutex_.Lock(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (have_stat_update && current->UpdateStats(stats)) { |
|
|
|
|
|
|
|
|
if(s.ok()){ |
|
|
|
|
|
s = CheckIsExpire(value); |
|
|
|
|
|
} |
|
|
|
|
|
if (have_stat_update && current->UpdateStats(stats,s.IsExpire())) { |
|
|
MaybeScheduleCompaction();//有可能寻址过多,导致allow_seek为0,触发合并。
|
|
|
MaybeScheduleCompaction();//有可能寻址过多,导致allow_seek为0,触发合并。
|
|
|
} |
|
|
} |
|
|
mem->Unref(); |
|
|
mem->Unref(); |
|
|
if (imm != nullptr) imm->Unref(); |
|
|
if (imm != nullptr) imm->Unref(); |
|
|
|
|
|
|
|
|
current->Unref(); |
|
|
current->Unref(); |
|
|
if(!s.ok()){ |
|
|
|
|
|
return s; |
|
|
|
|
|
} |
|
|
|
|
|
auto s2 = CheckIsExpire(value); |
|
|
|
|
|
return s2; |
|
|
|
|
|
|
|
|
// if(!s.ok()){
|
|
|
|
|
|
// return s;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// auto s2 = CheckIsExpire(value);
|
|
|
|
|
|
// if(!s2.ok()){
|
|
|
|
|
|
// current->UpdateStats(stats);
|
|
|
|
|
|
// }
|
|
|
|
|
|
return s; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Iterator* DBImpl::NewIterator(const ReadOptions& options) { |
|
|
Iterator* DBImpl::NewIterator(const ReadOptions& options) { |
|
@ -1229,21 +1235,6 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) { |
|
|
|
|
|
|
|
|
Status DBImpl::Put(const WriteOptions& options, const Slice& key, |
|
|
Status DBImpl::Put(const WriteOptions& options, const Slice& key, |
|
|
const Slice& value, uint64_t ttl) { |
|
|
const Slice& value, uint64_t ttl) { |
|
|
//rocksdb的实现
|
|
|
|
|
|
// Status DBWithTTLImpl::AppendTS(const Slice& val, std::string* val_with_ts,
|
|
|
|
|
|
// SystemClock* clock) {
|
|
|
|
|
|
// val_with_ts->reserve(kTSLength + val.size());
|
|
|
|
|
|
// char ts_string[kTSLength];
|
|
|
|
|
|
// int64_t curtime;
|
|
|
|
|
|
// Status st = clock->GetCurrentTime(&curtime);
|
|
|
|
|
|
// if (!st.ok()) {
|
|
|
|
|
|
// return st;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// EncodeFixed32(ts_string, (int32_t)curtime);
|
|
|
|
|
|
// val_with_ts->append(val.data(), val.size());
|
|
|
|
|
|
// val_with_ts->append(ts_string, kTSLength);
|
|
|
|
|
|
// return st;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
std::string val_with_ts; |
|
|
std::string val_with_ts; |
|
|
val_with_ts.reserve(value.size() + kTSLength); |
|
|
val_with_ts.reserve(value.size() + kTSLength); |
|
@ -1256,12 +1247,6 @@ Status DBImpl::Put(const WriteOptions& options, const Slice& key, |
|
|
|
|
|
|
|
|
// 将 expiration_time 追加到 val_with_ts
|
|
|
// 将 expiration_time 追加到 val_with_ts
|
|
|
val_with_ts.append(ts_string,kTSLength); |
|
|
val_with_ts.append(ts_string,kTSLength); |
|
|
// std::cout << "val_with_ts in hex: ";
|
|
|
|
|
|
// for (unsigned char c : val_with_ts) {
|
|
|
|
|
|
// std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)c << " ";
|
|
|
|
|
|
// }
|
|
|
|
|
|
// std::cout << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
return DB::Put(options, key, Slice(val_with_ts)); |
|
|
return DB::Put(options, key, Slice(val_with_ts)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1569,45 +1554,24 @@ void DBImpl::AppendTS(const Slice& val, std::string* val_with_ts,uint64_t ttl) { |
|
|
* @return timestamp in val,and remove timestamp from val |
|
|
* @return timestamp in val,and remove timestamp from val |
|
|
*/ |
|
|
*/ |
|
|
uint64_t DBImpl::GetTS(std::string* val) { |
|
|
uint64_t DBImpl::GetTS(std::string* val) { |
|
|
//uint64_t expiration_time;
|
|
|
|
|
|
// 输出 val 的十六进制表示
|
|
|
|
|
|
// std::cout << "befor decode,val in hex: ";
|
|
|
|
|
|
// for (unsigned char c : *val) {
|
|
|
|
|
|
// std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)c << " ";
|
|
|
|
|
|
// }
|
|
|
|
|
|
// std::cout << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
auto expiration_time = DecodeFixed64(val->data() + val->size() - kTSLength); |
|
|
auto expiration_time = DecodeFixed64(val->data() + val->size() - kTSLength); |
|
|
//memcpy(&expiration_time, val->data() + val->size() - sizeof(TIMESTAMP), sizeof(TIMESTAMP));
|
|
|
|
|
|
|
|
|
|
|
|
val->resize(val->size() - kTSLength); |
|
|
val->resize(val->size() - kTSLength); |
|
|
// std::cout << "after decode,val in hex: ";
|
|
|
|
|
|
// for (unsigned char c : *val) {
|
|
|
|
|
|
// std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)c << " ";
|
|
|
|
|
|
// }
|
|
|
|
|
|
// std::cout << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
return expiration_time; |
|
|
return expiration_time; |
|
|
|
|
|
|
|
|
// Status DBWithTTLImpl::StripTS(PinnableSlice* pinnable_val) {
|
|
|
|
|
|
// if (pinnable_val->size() < kTSLength) {
|
|
|
|
|
|
// return Status::Corruption("Bad timestamp in key-value");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // Erasing characters which hold the TS
|
|
|
|
|
|
// pinnable_val->remove_suffix(kTSLength);
|
|
|
|
|
|
// return Status::OK();
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
} |
|
|
Status DBImpl::CheckIsExpire(std::string* value) { |
|
|
Status DBImpl::CheckIsExpire(std::string* value) { |
|
|
//debug 用
|
|
|
//debug 用
|
|
|
auto a = env_->NowMicros(); |
|
|
auto a = env_->NowMicros(); |
|
|
auto b = GetTS(value); |
|
|
auto b = GetTS(value); |
|
|
// std::cout<<"get current time"<<a<<std::endl;
|
|
|
|
|
|
// std::cout << "get ts from val"<<b<<std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
if(a > b){ |
|
|
if(a > b){ |
|
|
return Status::Expire("Expire",Slice()); |
|
|
return Status::Expire("Expire",Slice()); |
|
|
} |
|
|
} |
|
|
return Status(); |
|
|
return Status(); |
|
|
// if(env_->GetCurrentTime() > GetTS(value)){
|
|
|
|
|
|
// return Status::Expire("Expire",Slice());
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|