[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:
parent
151f9e144f
commit
a107691711
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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() {}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user