Bläddra i källkod

文件元数据增加deadtime的范围,并根据范围对文件在合并时候进行清除,可以解决手动合并不完全的情况

pull/1/head^2
cyq 3 veckor sedan
förälder
incheckning
086354f990
3 ändrade filer med 33 tillägg och 1 borttagningar
  1. +30
    -1
      db/db_impl.cc
  2. +1
    -0
      db/db_impl.h
  3. +2
    -0
      db/version_set.h

+ 30
- 1
db/db_impl.cc Visa fil

@ -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;

+ 1
- 0
db/db_impl.h Visa fil

@ -145,6 +145,7 @@ class DBImpl : public DB {
EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Status DoCompactionWork(CompactionState* compact)
EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool RemoveExpireTable(); //if remove some table thne return true otherwise return false
Status OpenCompactionOutputFile(CompactionState* compact);
Status FinishCompactionOutputFile(CompactionState* compact, Iterator* input);

+ 2
- 0
db/version_set.h Visa fil

@ -111,6 +111,8 @@ class Version {
int NumFiles(int level) const { return files_[level].size(); }
const std::vector<FileMetaData*>& Files(int level) const {return files_[level]; }
// Return a human readable string that describes this version's contents.
std::string DebugString() const;

Laddar…
Avbryt
Spara