|
|
@ -57,6 +57,8 @@ struct DBImpl::CompactionState { |
|
|
|
uint64_t number; |
|
|
|
uint64_t file_size; |
|
|
|
InternalKey smallest, largest; |
|
|
|
// uint64_t now = static_cast<uint64_t>(time(nullptr)); // 合并发起的时间
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
Output* current_output() { return &outputs[outputs.size() - 1]; } |
|
|
@ -923,12 +925,13 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
|
std::string current_user_key; |
|
|
|
bool has_current_user_key = false; |
|
|
|
SequenceNumber last_sequence_for_key = kMaxSequenceNumber; |
|
|
|
time_t now = time(nullptr); // 获得当前时间
|
|
|
|
uint64_t now_time=static_cast<uint64_t>(now); |
|
|
|
while (input->Valid() && !shutting_down_.load(std::memory_order_acquire)) { |
|
|
|
auto x=input->value(); // 获取键值对 value
|
|
|
|
uint64_t ttl=*(uint64_t*)(x.data()+x.size()-sizeof(uint64_t));// 将 TTL 从 new_data 的末尾取出
|
|
|
|
time_t now = time(nullptr); // 获得当前时间
|
|
|
|
// 如果 TTL 超过当前时间,说明数据已经过期
|
|
|
|
if(ttl < static_cast<uint64_t>(now)){ |
|
|
|
if(ttl < now_time){ |
|
|
|
Log(options_.info_log, "delete record for ttl"); |
|
|
|
input->Next(); // 将 input 指向下一个键值对
|
|
|
|
continue; |
|
|
|