|
|
@ -591,7 +591,7 @@ void DBImpl::CompactRange(const Slice* begin, const Slice* end) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
max_level_with_files = config::kNumLevels - 1; //TODO:强制合并所有level中的sst,但是这么做不是很优雅
|
|
|
|
// max_level_with_files = config::kNumLevels - 1; //TODO:强制合并所有level中的sst,但是这么做不是很优雅
|
|
|
|
TEST_CompactMemTable(); // TODO(sanjay): Skip if memtable does not overlap
|
|
|
|
for (int level = 0; level < max_level_with_files; level++) { |
|
|
|
TEST_CompactRange(level, begin, end); |
|
|
@ -706,6 +706,31 @@ void DBImpl::BackgroundCall() { |
|
|
|
background_work_finished_signal_.SignalAll(); |
|
|
|
} |
|
|
|
|
|
|
|
bool DBImpl::RemoveExpireTable() { |
|
|
|
bool remove = false; |
|
|
|
VersionEdit edit; |
|
|
|
time_t nowTime; |
|
|
|
time(&nowTime); |
|
|
|
Version *base = versions_->current(); |
|
|
|
base->Ref(); |
|
|
|
for(int level = 0; level < config::kNumLevels; level ++) { |
|
|
|
const std::vector<FileMetaData*> &files = versions_->current()->Files(level); |
|
|
|
for(auto meta:files) { |
|
|
|
if(meta->largest_deadtime < nowTime) { |
|
|
|
remove = true; |
|
|
|
edit.RemoveFile(level,meta->number); |
|
|
|
std::cout<<"remove file : "<<meta->number<<" from level : "<<level<<std::endl; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(remove) { |
|
|
|
versions_->LogAndApply(&edit,&mutex_); |
|
|
|
RemoveObsoleteFiles(); |
|
|
|
} |
|
|
|
base->Unref(); |
|
|
|
return remove; |
|
|
|
} |
|
|
|
|
|
|
|
void DBImpl::BackgroundCompaction() { |
|
|
|
mutex_.AssertHeld(); |
|
|
|
|
|
|
@ -714,6 +739,10 @@ void DBImpl::BackgroundCompaction() { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if(RemoveExpireTable()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Compaction* c; |
|
|
|
bool is_manual = (manual_compaction_ != nullptr); |
|
|
|
InternalKey manual_end; |
|
|
|