Skip to content

Commit d076cef

Browse files
committed
[column families] Get rid of VersionSet::current_ and keep current Version for each column family
Summary: The biggest change here is getting rid of current_ Version and adding a column_family_data->current Version to each column family. I have also fixed some smaller things in VersionSet that made it easier to implement Column family support. Test Plan: make check Reviewers: dhruba, haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D15105
1 parent 19e3ee6 commit d076cef

File tree

4 files changed

+427
-274
lines changed

4 files changed

+427
-274
lines changed

db/db_impl.cc

+11-10
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ Status DBImpl::Recover(
906906
}
907907
auto cf_data_iter = versions_->column_family_data_.find(cf_iter->second);
908908
assert(cf_data_iter != versions_->column_family_data_.end());
909-
cf_data_iter->second.options = cf.options;
909+
cf_data_iter->second->options = cf.options;
910910
}
911911

912912
SequenceNumber max_sequence(0);
@@ -2888,15 +2888,19 @@ Status DBImpl::CreateColumnFamily(const ColumnFamilyOptions& options,
28882888
Status s = versions_->LogAndApply(&edit, &mutex_);
28892889
if (s.ok()) {
28902890
// add to internal data structures
2891-
versions_->column_families_[column_family_name] = handle->id;
2892-
versions_->column_family_data_.insert(
2893-
{handle->id,
2894-
VersionSet::ColumnFamilyData(column_family_name, options)});
2891+
versions_->CreateColumnFamily(options, &edit);
28952892
}
28962893
return s;
28972894
}
28982895

28992896
Status DBImpl::DropColumnFamily(const ColumnFamilyHandle& column_family) {
2897+
// TODO this is not good. implement some sort of refcounting
2898+
// column family data and only delete when refcount goes to 0
2899+
// We don't want to delete column family if there is a compaction going on,
2900+
// or if there are some outstanding iterators
2901+
if (column_family.id == 0) {
2902+
return Status::InvalidArgument("Can't drop default column family");
2903+
}
29002904
VersionEdit edit(0);
29012905
edit.DropColumnFamily();
29022906
edit.SetColumnFamily(column_family.id);
@@ -2908,10 +2912,7 @@ Status DBImpl::DropColumnFamily(const ColumnFamilyHandle& column_family) {
29082912
Status s = versions_->LogAndApply(&edit, &mutex_);
29092913
if (s.ok()) {
29102914
// remove from internal data structures
2911-
auto cf_iter = versions_->column_families_.find(data_iter->second.name);
2912-
assert(cf_iter != versions_->column_families_.end());
2913-
versions_->column_families_.erase(cf_iter);
2914-
versions_->column_family_data_.erase(data_iter);
2915+
versions_->DropColumnFamily(&edit);
29152916
}
29162917
return s;
29172918
}
@@ -3931,7 +3932,7 @@ Status DB::OpenWithColumnFamilies(
39313932
}
39323933
impl->mutex_.Unlock();
39333934

3934-
if (options.compaction_style == kCompactionStyleUniversal) {
3935+
if (s.ok() && options.compaction_style == kCompactionStyleUniversal) {
39353936
int num_files;
39363937
for (int i = 1; i < impl->NumberLevels(); i++) {
39373938
num_files = impl->versions_->NumLevelFiles(i);

0 commit comments

Comments
 (0)