Compaction Filter V1 to use old context struct to keep backward compatible

Summary: The previous change D15087 changed existing compaction filter, which makes the commonly used class not backward compatible. Revert the older interface. Use a new interface for V2 instead.

Test Plan: make all check

Reviewers: haobo, yhchiang, igor

CC: danguo, dhruba, ljin, igor, leveldb

Differential Revision: https://reviews.facebook.net/D17223
This commit is contained in:
sdong 2014-04-02 14:48:53 -07:00
parent 284c365b77
commit 4af1954fd6
6 changed files with 28 additions and 13 deletions

View File

@ -15,13 +15,12 @@
* Added Env::GetThreadPoolQueueLen(), which returns the waiting queue length of thread pools * Added Env::GetThreadPoolQueueLen(), which returns the waiting queue length of thread pools
* Added a command "checkconsistency" in ldb tool, which checks * Added a command "checkconsistency" in ldb tool, which checks
if file system state matches DB state (file existence and file sizes) 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 ### New Features
* If we find one truncated record at the end of the MANIFEST or WAL files, * 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 we will ignore it. We assume that writers of these records were interrupted
and that we can safely ignore it. 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. * Geo-spatial support for locations and radial-search.
## 2.7.0 (01/28/2014) ## 2.7.0 (01/28/2014)

View File

@ -117,6 +117,14 @@ struct DBImpl::CompactionState {
total_bytes(0) { 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 // Create a client visible context of this compaction
CompactionFilterContext GetFilterContext() { CompactionFilterContext GetFilterContext() {
CompactionFilterContext context; CompactionFilterContext context;
@ -2545,7 +2553,7 @@ Status DBImpl::ProcessKeyValueCompaction(
auto compaction_filter = options_.compaction_filter; auto compaction_filter = options_.compaction_filter;
std::unique_ptr<CompactionFilter> compaction_filter_from_factory = nullptr; std::unique_ptr<CompactionFilter> compaction_filter_from_factory = nullptr;
if (!compaction_filter) { if (!compaction_filter) {
auto context = compact->GetFilterContext(); auto context = compact->GetFilterContextV1();
compaction_filter_from_factory = compaction_filter_from_factory =
options_.compaction_filter_factory->CreateCompactionFilter(context); options_.compaction_filter_factory->CreateCompactionFilter(context);
compaction_filter = compaction_filter_from_factory.get(); compaction_filter = compaction_filter_from_factory.get();

View File

@ -2483,7 +2483,7 @@ class KeepFilterFactory : public CompactionFilterFactory {
: check_context_(check_context) {} : check_context_(check_context) {}
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter( virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
const CompactionFilterContext& context) override { const CompactionFilter::Context& context) override {
if (check_context_) { if (check_context_) {
ASSERT_EQ(expect_full_compaction_.load(), context.is_full_compaction); ASSERT_EQ(expect_full_compaction_.load(), context.is_full_compaction);
ASSERT_EQ(expect_manual_compaction_.load(), context.is_manual_compaction); ASSERT_EQ(expect_manual_compaction_.load(), context.is_manual_compaction);
@ -2500,7 +2500,7 @@ class KeepFilterFactory : public CompactionFilterFactory {
class DeleteFilterFactory : public CompactionFilterFactory { class DeleteFilterFactory : public CompactionFilterFactory {
public: public:
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter( virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
const CompactionFilterContext& context) override { const CompactionFilter::Context& context) override {
if (context.is_manual_compaction) { if (context.is_manual_compaction) {
return std::unique_ptr<CompactionFilter>(new DeleteFilter()); return std::unique_ptr<CompactionFilter>(new DeleteFilter());
} else { } else {
@ -2516,7 +2516,7 @@ class ChangeFilterFactory : public CompactionFilterFactory {
explicit ChangeFilterFactory() {} explicit ChangeFilterFactory() {}
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter( virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
const CompactionFilterContext& context) override { const CompactionFilter::Context& context) override {
return std::unique_ptr<CompactionFilter>(new ChangeFilter()); return std::unique_ptr<CompactionFilter>(new ChangeFilter());
} }

View File

@ -31,6 +31,15 @@ struct CompactionFilterContext {
class CompactionFilter { class CompactionFilter {
public: 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() {} virtual ~CompactionFilter() {}
// The compaction process invokes this // The compaction process invokes this
@ -105,7 +114,7 @@ class CompactionFilterFactory {
virtual ~CompactionFilterFactory() { } virtual ~CompactionFilterFactory() { }
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter( virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
const CompactionFilterContext& context) = 0; const CompactionFilter::Context& context) = 0;
// Returns a name that identifies this compaction filter factory. // Returns a name that identifies this compaction filter factory.
virtual const char* Name() const = 0; virtual const char* Name() const = 0;
@ -115,8 +124,8 @@ class CompactionFilterFactory {
// return any filter // return any filter
class DefaultCompactionFilterFactory : public CompactionFilterFactory { class DefaultCompactionFilterFactory : public CompactionFilterFactory {
public: public:
virtual std::unique_ptr<CompactionFilter> virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
CreateCompactionFilter(const CompactionFilterContext& context) override { const CompactionFilter::Context& context) override {
return std::unique_ptr<CompactionFilter>(nullptr); return std::unique_ptr<CompactionFilter>(nullptr);
} }

View File

@ -192,7 +192,7 @@ class TtlCompactionFilterFactory : public CompactionFilterFactory {
user_comp_filter_factory_(comp_filter_factory) { } user_comp_filter_factory_(comp_filter_factory) { }
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter( virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
const CompactionFilterContext& context) { const CompactionFilter::Context& context) {
return std::unique_ptr<TtlCompactionFilter>( return std::unique_ptr<TtlCompactionFilter>(
new TtlCompactionFilter( new TtlCompactionFilter(
ttl_, ttl_,

View File

@ -283,9 +283,8 @@ class TtlTest {
kNewValue_(kNewValue) { kNewValue_(kNewValue) {
} }
virtual std::unique_ptr<CompactionFilter> virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
CreateCompactionFilter( const CompactionFilter::Context& context) override {
const CompactionFilterContext& context) override {
return std::unique_ptr<CompactionFilter>( return std::unique_ptr<CompactionFilter>(
new TestFilter(kSampleSize_, kNewValue_)); new TestFilter(kSampleSize_, kNewValue_));
} }