|
|
@ -61,6 +61,7 @@ struct DBImpl::CompactionState { |
|
|
|
uint64_t number; |
|
|
|
uint64_t file_size; |
|
|
|
InternalKey smallest, largest; |
|
|
|
TIMESTAMP old_ts,new_ts; |
|
|
|
}; |
|
|
|
|
|
|
|
Output* current_output() { return &outputs[outputs.size() - 1]; } |
|
|
@ -536,11 +537,15 @@ Status DBImpl::WriteLevel0Table(MemTable* mem, VersionEdit* edit, |
|
|
|
if (s.ok() && meta.file_size > 0) { |
|
|
|
const Slice min_user_key = meta.smallest.user_key(); |
|
|
|
const Slice max_user_key = meta.largest.user_key(); |
|
|
|
const TIMESTAMP new_ts = meta.newer_ts; |
|
|
|
const TIMESTAMP old_ts = meta.oldest_ts; |
|
|
|
if (base != nullptr) { |
|
|
|
level = base->PickLevelForMemTableOutput(min_user_key, max_user_key); |
|
|
|
level = base->PickLevelForMemTableOutput(min_user_key, max_user_key);// TODO :基于timestamp和size和seek的新的选择规则
|
|
|
|
} |
|
|
|
// edit->AddFile(level, meta.number, meta.file_size, meta.smallest,
|
|
|
|
// meta.largest);
|
|
|
|
edit->AddFile(level, meta.number, meta.file_size, meta.smallest, |
|
|
|
meta.largest); |
|
|
|
meta.largest,old_ts,new_ts); |
|
|
|
} |
|
|
|
|
|
|
|
CompactionStats stats; |
|
|
@ -744,8 +749,10 @@ void DBImpl::BackgroundCompaction() { |
|
|
|
assert(c->num_input_files(0) == 1); |
|
|
|
FileMetaData* f = c->input(0, 0); |
|
|
|
c->edit()->RemoveFile(c->level(), f->number); |
|
|
|
// c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest,
|
|
|
|
// f->largest);
|
|
|
|
c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest, |
|
|
|
f->largest); |
|
|
|
f->largest,f->oldest_ts,f->newer_ts); |
|
|
|
status = versions_->LogAndApply(c->edit(), &mutex_); |
|
|
|
if (!status.ok()) { |
|
|
|
RecordBackgroundError(status); |
|
|
@ -819,6 +826,8 @@ Status DBImpl::OpenCompactionOutputFile(CompactionState* compact) { |
|
|
|
out.number = file_number; |
|
|
|
out.smallest.Clear(); |
|
|
|
out.largest.Clear(); |
|
|
|
out.old_ts = UINT64_MAX; |
|
|
|
out.new_ts = 0; |
|
|
|
compact->outputs.push_back(out); |
|
|
|
mutex_.Unlock(); |
|
|
|
} |
|
|
@ -924,6 +933,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
|
input->SeekToFirst(); |
|
|
|
Status status; |
|
|
|
ParsedInternalKey ikey; |
|
|
|
TIMESTAMP ts = 0; |
|
|
|
std::string current_user_key; |
|
|
|
bool has_current_user_key = false; |
|
|
|
SequenceNumber last_sequence_for_key = kMaxSequenceNumber; |
|
|
@ -949,7 +959,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
auto a = DecodeFixed64(input->value().data() + input->value().size() - kTSLength); |
|
|
|
//auto a = DecodeFixed64(input->value().data() + input->value().size() - kTSLength);//debug
|
|
|
|
// Handle key/value, add to state, etc.
|
|
|
|
bool drop = false; |
|
|
|
if (!ParseInternalKey(key, &ikey)) { |
|
|
@ -981,7 +991,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
|
// few iterations of this loop (by rule (A) above).
|
|
|
|
// Therefore this deletion marker is obsolete and can be dropped.
|
|
|
|
drop = true; |
|
|
|
}else if(DecodeFixed64(input->value().data() + input->value().size() - kTSLength) < env_->NowMicros()){ |
|
|
|
}else if((ts = DecodeFixed64(input->value().data() + input->value().size() - kTSLength)) < env_->NowMicros()){ |
|
|
|
|
|
|
|
drop = true; |
|
|
|
} |
|
|
@ -1010,6 +1020,10 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
|
compact->current_output()->smallest.DecodeFrom(key); |
|
|
|
} |
|
|
|
compact->current_output()->largest.DecodeFrom(key); |
|
|
|
assert(ts != 0); |
|
|
|
//auto b = compact->current_output()->old_ts;
|
|
|
|
compact->current_output()->old_ts = std::min(compact->current_output()->old_ts,ts); |
|
|
|
compact->current_output()->new_ts = std::max(compact->current_output()->new_ts,ts); |
|
|
|
compact->builder->Add(key, input->value()); |
|
|
|
|
|
|
|
// Close output file if it is big enough
|
|
|
@ -1156,7 +1170,7 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key, |
|
|
|
} else if (imm != nullptr && imm->Get(lkey, value, &s)) { |
|
|
|
// Done
|
|
|
|
} else { |
|
|
|
//stats.now_ts = this->env_->NowMicros();
|
|
|
|
stats.now_ts = this->env_->NowMicros(); |
|
|
|
s = current->Get(options, lkey, value, &stats); |
|
|
|
have_stat_update = true; |
|
|
|
} |
|
|
|