From f981e081393a440f086482dd5ef23473abbdbe04 Mon Sep 17 00:00:00 2001 From: Lei Jin Date: Tue, 28 Oct 2014 10:04:38 -0700 Subject: [PATCH] unfriend ColumnFamilyData from VersionSet Summary: as title Test Plan: make release will run full test on all stacked diffs before committing Reviewers: sdong, yhchiang, rven, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D27591 --- db/column_family.cc | 5 +++-- db/version_set.cc | 3 +++ db/version_set.h | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/db/column_family.cc b/db/column_family.cc index 0e83e98ab4..c47bbb12f9 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -304,8 +304,9 @@ ColumnFamilyData::~ColumnFamilyData() { if (dummy_versions_ != nullptr) { // List must be empty - assert(dummy_versions_->next_ == dummy_versions_); - delete dummy_versions_; + assert(dummy_versions_->TEST_Next() == dummy_versions_); + bool deleted __attribute__((unused)) = dummy_versions_->Unref(); + assert(deleted); } if (mem_ != nullptr) { diff --git a/db/version_set.cc b/db/version_set.cc index ec4df2823f..eab417a28f 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -2933,6 +2933,9 @@ ColumnFamilyData* VersionSet::CreateColumnFamily( assert(edit->is_column_family_add_); Version* dummy_versions = new Version(nullptr, this); + // Ref() dummy version once so that later we can call Unref() to delete it + // by avoiding calling "delete" explicitly (~Version is private) + dummy_versions->Ref(); auto new_cfd = column_family_set_->CreateColumnFamily( edit->column_family_name_, edit->column_family_, dummy_versions, cf_options); diff --git a/db/version_set.h b/db/version_set.h index 9a0c6733b4..8c20937d32 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -292,10 +292,14 @@ class Version { // seconds/minutes (because of concurrent compactions). static const size_t kNumberFilesToSort = 50; + // Return the next Version in the linked list. Used for debug only + Version* TEST_Next() const { + return next_; + } + private: friend class VersionSet; friend class DBImpl; - friend class ColumnFamilyData; friend class ForwardIterator; friend class InternalStats;