diff --git a/HISTORY.md b/HISTORY.md index 44ff73632..0946d441e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -15,13 +15,12 @@ * Added Env::GetThreadPoolQueueLen(), which returns the waiting queue length of thread pools * Added a command "checkconsistency" in ldb tool, which checks if file system state matches DB state (file existence and file sizes) -* CompactionFilter::Context is now CompactionFilterContext. It is shared by CompactionFilter and CompactionFilterV2 ### New Features * If we find one truncated record at the end of the MANIFEST or WAL files, we will ignore it. We assume that writers of these records were interrupted and that we can safely ignore it. -* Now compaction filter has a V2 interface. It buffers the kv-pairs sharing the same key prefix, process them in batches, and return the batched results back to DB. +* Now compaction filter has a V2 interface. It buffers the kv-pairs sharing the same key prefix, process them in batches, and return the batched results back to DB. The new interface uses a new structure CompactionFilterContext for the same purpose as CompactionFilter::Context in V1. * Geo-spatial support for locations and radial-search. ## 2.7.0 (01/28/2014) diff --git a/db/db_impl.cc b/db/db_impl.cc index e532d5b17..c6481ce9c 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -117,6 +117,14 @@ struct DBImpl::CompactionState { total_bytes(0) { } + // Create a client visible context of this compaction + CompactionFilter::Context GetFilterContextV1() { + CompactionFilter::Context context; + context.is_full_compaction = compaction->IsFullCompaction(); + context.is_manual_compaction = compaction->IsManualCompaction(); + return context; + } + // Create a client visible context of this compaction CompactionFilterContext GetFilterContext() { CompactionFilterContext context; @@ -2545,7 +2553,7 @@ Status DBImpl::ProcessKeyValueCompaction( auto compaction_filter = options_.compaction_filter; std::unique_ptr compaction_filter_from_factory = nullptr; if (!compaction_filter) { - auto context = compact->GetFilterContext(); + auto context = compact->GetFilterContextV1(); compaction_filter_from_factory = options_.compaction_filter_factory->CreateCompactionFilter(context); compaction_filter = compaction_filter_from_factory.get(); diff --git a/db/db_test.cc b/db/db_test.cc index 1e8846376..0695b5cc7 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2483,7 +2483,7 @@ class KeepFilterFactory : public CompactionFilterFactory { : check_context_(check_context) {} virtual std::unique_ptr CreateCompactionFilter( - const CompactionFilterContext& context) override { + const CompactionFilter::Context& context) override { if (check_context_) { ASSERT_EQ(expect_full_compaction_.load(), context.is_full_compaction); ASSERT_EQ(expect_manual_compaction_.load(), context.is_manual_compaction); @@ -2500,7 +2500,7 @@ class KeepFilterFactory : public CompactionFilterFactory { class DeleteFilterFactory : public CompactionFilterFactory { public: virtual std::unique_ptr CreateCompactionFilter( - const CompactionFilterContext& context) override { + const CompactionFilter::Context& context) override { if (context.is_manual_compaction) { return std::unique_ptr(new DeleteFilter()); } else { @@ -2516,7 +2516,7 @@ class ChangeFilterFactory : public CompactionFilterFactory { explicit ChangeFilterFactory() {} virtual std::unique_ptr CreateCompactionFilter( - const CompactionFilterContext& context) override { + const CompactionFilter::Context& context) override { return std::unique_ptr(new ChangeFilter()); } diff --git a/include/rocksdb/compaction_filter.h b/include/rocksdb/compaction_filter.h index f54ee620c..59b050923 100644 --- a/include/rocksdb/compaction_filter.h +++ b/include/rocksdb/compaction_filter.h @@ -31,6 +31,15 @@ struct CompactionFilterContext { class CompactionFilter { public: + // Context information of a compaction run + 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() {} // The compaction process invokes this @@ -105,7 +114,7 @@ class CompactionFilterFactory { virtual ~CompactionFilterFactory() { } virtual std::unique_ptr CreateCompactionFilter( - const CompactionFilterContext& context) = 0; + const CompactionFilter::Context& context) = 0; // Returns a name that identifies this compaction filter factory. virtual const char* Name() const = 0; @@ -115,8 +124,8 @@ class CompactionFilterFactory { // return any filter class DefaultCompactionFilterFactory : public CompactionFilterFactory { public: - virtual std::unique_ptr - CreateCompactionFilter(const CompactionFilterContext& context) override { + virtual std::unique_ptr CreateCompactionFilter( + const CompactionFilter::Context& context) override { return std::unique_ptr(nullptr); } diff --git a/utilities/ttl/db_ttl.h b/utilities/ttl/db_ttl.h index d23ef88cf..519ae32c7 100644 --- a/utilities/ttl/db_ttl.h +++ b/utilities/ttl/db_ttl.h @@ -192,7 +192,7 @@ class TtlCompactionFilterFactory : public CompactionFilterFactory { user_comp_filter_factory_(comp_filter_factory) { } virtual std::unique_ptr CreateCompactionFilter( - const CompactionFilterContext& context) { + const CompactionFilter::Context& context) { return std::unique_ptr( new TtlCompactionFilter( ttl_, diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index a981cceb8..789128729 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -283,9 +283,8 @@ class TtlTest { kNewValue_(kNewValue) { } - virtual std::unique_ptr - CreateCompactionFilter( - const CompactionFilterContext& context) override { + virtual std::unique_ptr CreateCompactionFilter( + const CompactionFilter::Context& context) override { return std::unique_ptr( new TestFilter(kSampleSize_, kNewValue_)); }