Avoid populating live set if we don't need to

Summary: Also changed some comments

Test Plan: ./deletefile_test

Reviewers: haobo

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D14091
main
Igor Canadi 11 years ago
parent a0ce3fd00a
commit 29c931f70b
  1. 47
      db/db_impl.cc

@ -451,6 +451,22 @@ void DBImpl::FindObsoleteFiles(DeletionState& deletion_state,
return; return;
} }
bool doing_the_full_scan = false;
// logic for figurint out if we're doing the full scan
if (no_full_scan) {
doing_the_full_scan = false;
} else if (force || options_.delete_obsolete_files_period_micros == 0) {
doing_the_full_scan = true;
} else {
const uint64_t now_micros = env_->NowMicros();
if (delete_obsolete_files_last_run_ +
options_.delete_obsolete_files_period_micros < now_micros) {
doing_the_full_scan = true;
delete_obsolete_files_last_run_ = now_micros;
}
}
// get obsolete files // get obsolete files
versions_->GetObsoleteFiles(&deletion_state.sst_delete_files); versions_->GetObsoleteFiles(&deletion_state.sst_delete_files);
@ -459,31 +475,19 @@ void DBImpl::FindObsoleteFiles(DeletionState& deletion_state,
deletion_state.log_number = versions_->LogNumber(); deletion_state.log_number = versions_->LogNumber();
deletion_state.prev_log_number = versions_->PrevLogNumber(); deletion_state.prev_log_number = versions_->PrevLogNumber();
// TODO we should not be catching live files here, if (!doing_the_full_scan && !deletion_state.HaveSomethingToDelete()) {
// version_->GetObsoleteFiles() should tell us the truth, which // avoid filling up sst_live if we're sure that we
// files are to be deleted. However, it does not, so we do // are not going to do the full scan and that we don't have
// this to be safe, i.e. never delete files that could be // anything to delete at the moment
// live return;
}
// don't delete live files
deletion_state.sst_live.assign(pending_outputs_.begin(), deletion_state.sst_live.assign(pending_outputs_.begin(),
pending_outputs_.end()); pending_outputs_.end());
versions_->AddLiveFiles(&deletion_state.sst_live); versions_->AddLiveFiles(&deletion_state.sst_live);
// if no_full_scan, never do the full scan if (doing_the_full_scan) {
if (no_full_scan) {
return;
}
// if force == true, always fall through and do the full scan
// if force == false, do the full scan only every
// options_.delete_obsolete_files_period_micros
if (!force && options_.delete_obsolete_files_period_micros != 0) {
const uint64_t now_micros = env_->NowMicros();
if (delete_obsolete_files_last_run_ +
options_.delete_obsolete_files_period_micros > now_micros) {
return;
}
delete_obsolete_files_last_run_ = now_micros;
}
// set of all files in the directory // set of all files in the directory
env_->GetChildren(dbname_, &deletion_state.all_files); // Ignore errors env_->GetChildren(dbname_, &deletion_state.all_files); // Ignore errors
@ -498,6 +502,7 @@ void DBImpl::FindObsoleteFiles(DeletionState& deletion_state,
); );
} }
} }
}
// Diffs the files listed in filenames and those that do not // Diffs the files listed in filenames and those that do not
// belong to live files are posibly removed. Also, removes all the // belong to live files are posibly removed. Also, removes all the

Loading…
Cancel
Save