提交 a1076917 编写于 作者: I Igor Canadi

[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
上级 151f9e14
......@@ -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() {}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册