[RocksDB][Performance Branch]Iterator Cleanup method only tries to find obsolete files if it has the last reference to a version

Summary: When deconstructing an iterator, no need to check obsolete file if it doesn't hold last reference of any version.

Test Plan: make all check

Reviewers: haobo, igor, dhruba, kailiu

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D14595
This commit is contained in:
Siying Dong 2013-12-11 11:56:36 -08:00
parent f37a59769b
commit aaf9c6203c
3 changed files with 10 additions and 5 deletions

View File

@ -2515,9 +2515,10 @@ static void CleanupIteratorState(void* arg1, void* arg2) {
deletion_state.memtables_to_free.push_back(m); deletion_state.memtables_to_free.push_back(m);
} }
} }
state->version->Unref(); if (state->version->Unref()) {
// fast path FindObsoleteFiles // fast path FindObsoleteFiles
state->db->FindObsoleteFiles(deletion_state, false, true); state->db->FindObsoleteFiles(deletion_state, false, true);
}
state->mu->Unlock(); state->mu->Unlock();
state->db->PurgeObsoleteFiles(deletion_state); state->db->PurgeObsoleteFiles(deletion_state);
delete state; delete state;

View File

@ -591,13 +591,15 @@ void Version::Ref() {
++refs_; ++refs_;
} }
void Version::Unref() { bool Version::Unref() {
assert(this != &vset_->dummy_versions_); assert(this != &vset_->dummy_versions_);
assert(refs_ >= 1); assert(refs_ >= 1);
--refs_; --refs_;
if (refs_ == 0) { if (refs_ == 0) {
delete this; delete this;
return true;
} }
return false;
} }
bool Version::OverlapInLevel(int level, bool Version::OverlapInLevel(int level,

View File

@ -89,7 +89,9 @@ class Version {
// Reference count management (so Versions do not disappear out from // Reference count management (so Versions do not disappear out from
// under live iterators) // under live iterators)
void Ref(); void Ref();
void Unref(); // Decrease reference count. Delete the object if no reference left
// and return true. Otherwise, return false.
bool Unref();
void GetOverlappingInputs( void GetOverlappingInputs(
int level, int level,