diff --git a/HISTORY.md b/HISTORY.md index 102031b15..d48591ac5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,7 @@ * Removed arena.h from public header files. * By default, checksums are verified on every read from database +* Added is_manual_compaction to CompactionFilter::Context ## 2.7.0 (01/28/2014) diff --git a/db/compaction.cc b/db/compaction.cc index 536b7e233..d5ce99f74 100644 --- a/db/compaction.cc +++ b/db/compaction.cc @@ -39,6 +39,7 @@ Compaction::Compaction(Version* input_version, int level, int out_level, score_(0), bottommost_level_(false), is_full_compaction_(false), + is_manual_compaction_(false), level_ptrs_(std::vector(number_levels_)) { input_version_->Ref(); diff --git a/db/compaction.h b/db/compaction.h index efd6ef71f..ead1d87a2 100644 --- a/db/compaction.h +++ b/db/compaction.h @@ -78,6 +78,9 @@ class Compaction { // Does this compaction include all sst files? bool IsFullCompaction() { return is_full_compaction_; } + // Was this compaction triggered manually by the client? + bool IsManualCompaction() { return is_manual_compaction_; } + private: friend class CompactionPicker; friend class UniversalCompactionPicker; @@ -117,6 +120,9 @@ class Compaction { // Does this compaction include all sst files? bool is_full_compaction_; + // Is this compaction requested by the client? + bool is_manual_compaction_; + // level_ptrs_ holds indices into input_version_->levels_: our state // is that we are positioned at one of the file ranges for each // higher level than the ones involved in this compaction (i.e. for diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index 28cda9dac..96e149e86 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -361,6 +361,9 @@ Compaction* CompactionPicker::CompactRange(Version* version, int input_level, // Is this compaction creating a file at the bottommost level c->SetupBottomMostLevel(true); + + c->is_manual_compaction_ = true; + return c; } diff --git a/db/db_impl.cc b/db/db_impl.cc index 62341a4bf..df7451b8e 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -112,6 +112,7 @@ struct DBImpl::CompactionState { CompactionFilter::Context GetFilterContext() { CompactionFilter::Context context; context.is_full_compaction = compaction->IsFullCompaction(); + context.is_manual_compaction = compaction->IsManualCompaction(); return context; } }; diff --git a/db/db_test.cc b/db/db_test.cc index c477c8aae..e2344d825 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2973,7 +2973,11 @@ class DeleteFilterFactory : public CompactionFilterFactory { public: virtual std::unique_ptr CreateCompactionFilter(const CompactionFilter::Context& context) override { - return std::unique_ptr(new DeleteFilter()); + if (context.is_manual_compaction) { + return std::unique_ptr(new DeleteFilter()); + } else { + return std::unique_ptr(nullptr); + } } virtual const char* Name() const override { diff --git a/include/rocksdb/compaction_filter.h b/include/rocksdb/compaction_filter.h index f24132a6f..dfd2f928b 100644 --- a/include/rocksdb/compaction_filter.h +++ b/include/rocksdb/compaction_filter.h @@ -25,6 +25,9 @@ class CompactionFilter { struct Context { // Does this compaction run include all data files bool is_full_compaction; + // Is this compaction requested by the client (true), + // or is it occurring as an automatic compaction process + bool is_manual_compaction; }; virtual ~CompactionFilter() {}