From 643bbbf081d359fb71c2a53515d06dcb79dc38fe Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Mon, 8 Jun 2015 16:34:26 -0700 Subject: [PATCH] Use nullptr for default compaction_filter_factory Summary: Replacing the default value for compaction_filter_factory and compaction_filter_factory_v2 to be nullptr instead of DefaultCompactionFilterFactory / DefaultCompactionFilterFactoryV2 The reason for this is to be able to determine easily if we have compaction filter factory or not without depending on RTTI Test Plan: make check Reviewers: yoshinorim, ott, igor, sdong Reviewed By: sdong Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D39693 --- HISTORY.md | 1 + db/compaction.cc | 14 ++++++++++---- include/rocksdb/options.h | 4 ++-- util/options.cc | 10 +++++----- utilities/ttl/db_ttl_impl.h | 10 ++++++++-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2d8da1a65..acb1b43a2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ * Move listeners from ColumnFamilyOptions to DBOptions. * Add max_write_buffer_number_to_maintain option * DB::CompactRange()'s parameter reduce_level is changed to change_level, to allow users to move levels to lower levels if allowed. It can be used to migrate a DB from options.level_compaction_dynamic_level_bytes=false to options.level_compaction_dynamic_level_bytes.true. +* Change default value for options.compaction_filter_factory and options.compaction_filter_factory_v2 to nullptr instead of DefaultCompactionFilterFactory and DefaultCompactionFilterFactoryV2. ## 3.11.0 (5/19/2015) ### New Features diff --git a/db/compaction.cc b/db/compaction.cc index 6b6799cfc..02077923f 100644 --- a/db/compaction.cc +++ b/db/compaction.cc @@ -160,10 +160,8 @@ bool Compaction::IsTrivialMove() const { if (is_manual_compaction_ && (cfd_->ioptions()->compaction_filter != nullptr || - !dynamic_cast( - cfd_->ioptions()->compaction_filter_factory) || - !dynamic_cast( - cfd_->ioptions()->compaction_filter_factory_v2))) { + cfd_->ioptions()->compaction_filter_factory != nullptr || + cfd_->ioptions()->compaction_filter_factory_v2 != nullptr)) { // This is a manual compaction and we have a compaction filter that should // be executed, we cannot do a trivial move return false; @@ -360,6 +358,10 @@ uint64_t Compaction::OutputFilePreallocationSize() { } std::unique_ptr Compaction::CreateCompactionFilter() const { + if (!cfd_->ioptions()->compaction_filter_factory) { + return nullptr; + } + CompactionFilter::Context context; context.is_full_compaction = is_full_compaction_; context.is_manual_compaction = is_manual_compaction_; @@ -369,6 +371,10 @@ std::unique_ptr Compaction::CreateCompactionFilter() const { std::unique_ptr Compaction::CreateCompactionFilterV2() const { + if (!cfd_->ioptions()->compaction_filter_factory_v2) { + return nullptr; + } + CompactionFilterContext context; context.is_full_compaction = is_full_compaction_; context.is_manual_compaction = is_manual_compaction_; diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index fcd044a6e..31b94af41 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -189,13 +189,13 @@ struct ColumnFamilyOptions { // compaction is being used, each created CompactionFilter will only be used // from a single thread and so does not need to be thread-safe. // - // Default: a factory that doesn't provide any object + // Default: nullptr std::shared_ptr compaction_filter_factory; // Version TWO of the compaction_filter_factory // It supports rolling compaction // - // Default: a factory that doesn't provide any object + // Default: nullptr std::shared_ptr compaction_filter_factory_v2; // ------------------- diff --git a/util/options.cc b/util/options.cc index 3e3650dd7..57c0cab96 100644 --- a/util/options.cc +++ b/util/options.cc @@ -78,9 +78,8 @@ ColumnFamilyOptions::ColumnFamilyOptions() : comparator(BytewiseComparator()), merge_operator(nullptr), compaction_filter(nullptr), - compaction_filter_factory(std::shared_ptr( - new DefaultCompactionFilterFactory())), - compaction_filter_factory_v2(new DefaultCompactionFilterFactoryV2()), + compaction_filter_factory(nullptr), + compaction_filter_factory_v2(nullptr), write_buffer_size(4 << 20), max_write_buffer_number(2), min_write_buffer_number_to_merge(1), @@ -366,9 +365,10 @@ void ColumnFamilyOptions::Dump(Logger* log) const { Warn(log, " Options.compaction_filter: %s", compaction_filter ? compaction_filter->Name() : "None"); Warn(log, " Options.compaction_filter_factory: %s", - compaction_filter_factory->Name()); + compaction_filter_factory ? compaction_filter_factory->Name() : "None"); Warn(log, " Options.compaction_filter_factory_v2: %s", - compaction_filter_factory_v2->Name()); + compaction_filter_factory_v2 ? compaction_filter_factory_v2->Name() + : "None"); Warn(log, " Options.memtable_factory: %s", memtable_factory->Name()); Warn(log, " Options.table_factory: %s", table_factory->Name()); Warn(log, " table_factory options: %s", diff --git a/utilities/ttl/db_ttl_impl.h b/utilities/ttl/db_ttl_impl.h index 9abf6fc7f..84444e91c 100644 --- a/utilities/ttl/db_ttl_impl.h +++ b/utilities/ttl/db_ttl_impl.h @@ -188,9 +188,15 @@ class TtlCompactionFilterFactory : public CompactionFilterFactory { virtual std::unique_ptr CreateCompactionFilter( const CompactionFilter::Context& context) override { + std::unique_ptr user_comp_filter_from_factory = + nullptr; + if (user_comp_filter_factory_) { + user_comp_filter_from_factory = + user_comp_filter_factory_->CreateCompactionFilter(context); + } + return std::unique_ptr(new TtlCompactionFilter( - ttl_, env_, nullptr, - std::move(user_comp_filter_factory_->CreateCompactionFilter(context)))); + ttl_, env_, nullptr, std::move(user_comp_filter_from_factory))); } virtual const char* Name() const override {