mirror of
https://github.com/google/leveldb.git
synced 2025-01-01 04:20:11 +08:00
reduce lock's range in DeleteObsoleteFiles
This commit is contained in:
parent
77948e7eec
commit
e5f0a51fa4
@ -216,18 +216,26 @@ void DBImpl::MaybeIgnoreError(Status* s) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DBImpl::DeleteObsoleteFiles() {
|
void DBImpl::DeleteObsoleteFiles() {
|
||||||
|
mutex_.AssertHeld();
|
||||||
|
|
||||||
if (!bg_error_.ok()) {
|
if (!bg_error_.ok()) {
|
||||||
// After a background error, we don't know whether a new version may
|
// After a background error, we don't know whether a new version may
|
||||||
// or may not have been committed, so we cannot safely garbage collect.
|
// or may not have been committed, so we cannot safely garbage collect.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t log_number = versions_->LogNumber();
|
||||||
|
uint64_t prev_log_number = versions_->PrevLogNumber();
|
||||||
|
uint64_t manifest_file_number = versions_->ManifestFileNumber();
|
||||||
|
|
||||||
// Make a set of all of the live files
|
// Make a set of all of the live files
|
||||||
std::set<uint64_t> live = pending_outputs_;
|
std::set<uint64_t> live = pending_outputs_;
|
||||||
versions_->AddLiveFiles(&live);
|
versions_->AddLiveFiles(&live);
|
||||||
|
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
env_->GetChildren(dbname_, &filenames); // Ignoring errors on purpose
|
env_->GetChildren(dbname_, &filenames); // Ignoring errors on purpose
|
||||||
|
|
||||||
|
mutex_.Unlock();
|
||||||
uint64_t number;
|
uint64_t number;
|
||||||
FileType type;
|
FileType type;
|
||||||
for (size_t i = 0; i < filenames.size(); i++) {
|
for (size_t i = 0; i < filenames.size(); i++) {
|
||||||
@ -235,13 +243,13 @@ void DBImpl::DeleteObsoleteFiles() {
|
|||||||
bool keep = true;
|
bool keep = true;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case kLogFile:
|
case kLogFile:
|
||||||
keep = ((number >= versions_->LogNumber()) ||
|
keep = ((number >= log_number) ||
|
||||||
(number == versions_->PrevLogNumber()));
|
(number == prev_log_number));
|
||||||
break;
|
break;
|
||||||
case kDescriptorFile:
|
case kDescriptorFile:
|
||||||
// Keep my manifest file, and any newer incarnations'
|
// Keep my manifest file, and any newer incarnations'
|
||||||
// (in case there is a race that allows other incarnations)
|
// (in case there is a race that allows other incarnations)
|
||||||
keep = (number >= versions_->ManifestFileNumber());
|
keep = (number >= manifest_file_number);
|
||||||
break;
|
break;
|
||||||
case kTableFile:
|
case kTableFile:
|
||||||
keep = (live.find(number) != live.end());
|
keep = (live.find(number) != live.end());
|
||||||
@ -269,6 +277,7 @@ void DBImpl::DeleteObsoleteFiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mutex_.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status DBImpl::Recover(VersionEdit* edit) {
|
Status DBImpl::Recover(VersionEdit* edit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user