[column families] Implement refcounting ColumnFamilyData

Summary: We don't want to delete ColumnFamilyData object if somebody has references to it.

Test Plan: `make check` for now, but will need to implement bigger column family test case

Reviewers: dhruba, haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D15111
This commit is contained in:
Igor Canadi 2014-01-13 09:21:37 -08:00
parent 151f9e144f
commit a107691711
2 changed files with 22 additions and 3 deletions

View File

@ -1163,7 +1163,7 @@ VersionSet::~VersionSet() {
cfd.second->current->Unref();
// List must be empty
assert(cfd.second->dummy_versions.next_ == &cfd.second->dummy_versions);
delete cfd.second;
cfd.second->Unref();
}
for (auto file : obsolete_files_) {
delete file;
@ -3059,7 +3059,8 @@ void VersionSet::DropColumnFamily(VersionEdit* edit) {
cfd->second->current->Unref();
// List must be empty
assert(cfd->second->dummy_versions.next_ == &cfd->second->dummy_versions);
delete cfd->second;
// might delete itself
cfd->second->Unref();
column_family_data_.erase(cfd);
}

View File

@ -223,11 +223,29 @@ struct ColumnFamilyData {
Version dummy_versions; // Head of circular doubly-linked list of versions.
Version* current; // == dummy_versions.prev_
ColumnFamilyOptions options;
int refs;
void Ref() {
++refs;
}
void Unref() {
assert(refs > 0);
if (refs == 1) {
delete this;
} else {
--refs;
}
}
ColumnFamilyData(const std::string& name,
VersionSet* vset,
const ColumnFamilyOptions& options)
: name(name), dummy_versions(vset), current(nullptr), options(options) {}
: name(name),
dummy_versions(vset),
current(nullptr),
options(options),
refs(1) {}
~ColumnFamilyData() {}
};