Skip to content

Commit

Permalink
Merge pull request #386 from ivanabc:master
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 250702492
  • Loading branch information
cmumford committed May 30, 2019
2 parents 72a38ff + 63d5315 commit 4cb80b7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,32 @@ void DBImpl::DeleteObsoleteFiles() {
return;
}

const uint64_t log_number = versions_->LogNumber();
const uint64_t prev_log_number = versions_->PrevLogNumber();
const uint64_t manifest_file_number = versions_->ManifestFileNumber();

// Make a set of all of the live files
std::set<uint64_t> live = pending_outputs_;
versions_->AddLiveFiles(&live);

std::vector<std::string> filenames;
env_->GetChildren(dbname_, &filenames); // Ignoring errors on purpose

// Unlock while deleting obsolete files
mutex_.Unlock();
uint64_t number;
FileType type;
for (size_t i = 0; i < filenames.size(); i++) {
if (ParseFileName(filenames[i], &number, &type)) {
bool keep = true;
switch (type) {
case kLogFile:
keep = ((number >= versions_->LogNumber()) ||
(number == versions_->PrevLogNumber()));
keep = ((number >= log_number) || (number == prev_log_number));
break;
case kDescriptorFile:
// Keep my manifest file, and any newer incarnations'
// (in case there is a race that allows other incarnations)
keep = (number >= versions_->ManifestFileNumber());
keep = (number >= manifest_file_number);
break;
case kTableFile:
keep = (live.find(number) != live.end());
Expand All @@ -275,6 +281,7 @@ void DBImpl::DeleteObsoleteFiles() {
}
}
}
mutex_.Lock();
}

Status DBImpl::Recover(VersionEdit* edit, bool* save_manifest) {
Expand Down

0 comments on commit 4cb80b7

Please sign in to comment.