Fix BaseReferencedVersionBuilder's destructor order

Summary: BaseReferencedVersionBuilder now unreference version before destructing VersionBuilder, which is wrong. Fix it.

Test Plan:
make all check
valgrind test to tests that used to fail

Reviewers: igor, yhchiang, rven, ljin

Reviewed By: ljin

Subscribers: leveldb, dhruba

Differential Revision: https://reviews.facebook.net/D28101
main
sdong 10 years ago
parent c76dcb44d4
commit f7e6c856ab
  1. 17
      db/version_set.cc

@ -515,19 +515,24 @@ class LevelFileIteratorState : public TwoLevelIteratorState {
// A wrapper of version builder which references the current version in // A wrapper of version builder which references the current version in
// constructor and unref it in the destructor. // constructor and unref it in the destructor.
// Both of the constructor and destructor need to be called inside DB Mutex.
class BaseReferencedVersionBuilder { class BaseReferencedVersionBuilder {
public: public:
explicit BaseReferencedVersionBuilder(ColumnFamilyData* cfd) explicit BaseReferencedVersionBuilder(ColumnFamilyData* cfd)
: version_builder_(cfd->current()->version_set()->GetEnvOptions(), : version_builder_(new VersionBuilder(
cfd->table_cache(), cfd->current()->storage_info()), cfd->current()->version_set()->GetEnvOptions(), cfd->table_cache(),
cfd->current()->storage_info())),
version_(cfd->current()) { version_(cfd->current()) {
version_->Ref(); version_->Ref();
} }
~BaseReferencedVersionBuilder() { version_->Unref(); } ~BaseReferencedVersionBuilder() {
VersionBuilder* GetVersionBuilder() { return &version_builder_; } delete version_builder_;
version_->Unref();
}
VersionBuilder* GetVersionBuilder() { return version_builder_; }
private: private:
VersionBuilder version_builder_; VersionBuilder* version_builder_;
Version* version_; Version* version_;
}; };
} // anonymous namespace } // anonymous namespace
@ -2322,7 +2327,7 @@ Status VersionSet::Recover(
for (auto cfd : *column_family_set_) { for (auto cfd : *column_family_set_) {
auto builders_iter = builders.find(cfd->GetID()); auto builders_iter = builders.find(cfd->GetID());
assert(builders_iter != builders.end()); assert(builders_iter != builders.end());
auto builder = builders_iter->second->GetVersionBuilder(); auto* builder = builders_iter->second->GetVersionBuilder();
if (db_options_->max_open_files == -1) { if (db_options_->max_open_files == -1) {
// unlimited table cache. Pre-load table handle now. // unlimited table cache. Pre-load table handle now.

Loading…
Cancel
Save