mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Separate compaction filter for each compaction
Summary: If we have same compaction filter for each compaction, application cannot know about the different compaction processes. Later on, we can put in more details in compaction filter for the application to consume and use it according to its needs. For e.g. In the universal compaction, we have a compaction process involving all the files while others don't involve all the files. Applications may want to collect some stats only when during full compaction. Test Plan: run existing unit tests Reviewers: haobo, dhruba Reviewed By: dhruba CC: xinyaohu, leveldb Differential Revision: https://reviews.facebook.net/D12057
This commit is contained in:
@@ -20,9 +20,16 @@ DBWithTTL::DBWithTTL(const int32_t ttl,
|
||||
ttl_(ttl) {
|
||||
Options options_to_open = options;
|
||||
|
||||
ttl_comp_filter_.reset(new TtlCompactionFilter(ttl,
|
||||
options.compaction_filter));
|
||||
options_to_open.compaction_filter = ttl_comp_filter_.get();
|
||||
if (options.compaction_filter) {
|
||||
ttl_comp_filter_.reset(
|
||||
new TtlCompactionFilter(ttl, options.compaction_filter));
|
||||
options_to_open.compaction_filter = ttl_comp_filter_.get();
|
||||
} else {
|
||||
options_to_open.compaction_filter_factory =
|
||||
std::shared_ptr<CompactionFilterFactory>(
|
||||
new TtlCompactionFilterFactory(
|
||||
ttl, options.compaction_filter_factory));
|
||||
}
|
||||
|
||||
if (options.merge_operator) {
|
||||
ttl_merge_op_.reset(new TtlMergeOperator(options.merge_operator));
|
||||
|
||||
@@ -176,11 +176,19 @@ class TtlIterator : public Iterator {
|
||||
class TtlCompactionFilter : public CompactionFilter {
|
||||
|
||||
public:
|
||||
TtlCompactionFilter(int32_t ttl, const CompactionFilter* comp_filter)
|
||||
TtlCompactionFilter(
|
||||
int32_t ttl,
|
||||
const CompactionFilter* user_comp_filter,
|
||||
std::unique_ptr<const CompactionFilter>
|
||||
user_comp_filter_from_factory = nullptr)
|
||||
: ttl_(ttl),
|
||||
user_comp_filter_(comp_filter) {
|
||||
user_comp_filter_(user_comp_filter),
|
||||
user_comp_filter_from_factory_(std::move(user_comp_filter_from_factory)) {
|
||||
// Unlike the merge operator, compaction filter is necessary for TTL, hence
|
||||
// this would be called even if user doesn't specify any compaction-filter
|
||||
if (!user_comp_filter_) {
|
||||
user_comp_filter_ = user_comp_filter_from_factory_.get();
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Filter(int level,
|
||||
@@ -215,6 +223,32 @@ class TtlCompactionFilter : public CompactionFilter {
|
||||
private:
|
||||
int32_t ttl_;
|
||||
const CompactionFilter* user_comp_filter_;
|
||||
std::unique_ptr<const CompactionFilter> user_comp_filter_from_factory_;
|
||||
};
|
||||
|
||||
class TtlCompactionFilterFactory : public CompactionFilterFactory {
|
||||
public:
|
||||
TtlCompactionFilterFactory(
|
||||
int32_t ttl,
|
||||
std::shared_ptr<CompactionFilterFactory> comp_filter_factory)
|
||||
: ttl_(ttl),
|
||||
user_comp_filter_factory_(comp_filter_factory) { }
|
||||
|
||||
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter() {
|
||||
return std::unique_ptr<TtlCompactionFilter>(
|
||||
new TtlCompactionFilter(
|
||||
ttl_,
|
||||
nullptr,
|
||||
std::move(user_comp_filter_factory_->CreateCompactionFilter())));
|
||||
}
|
||||
|
||||
virtual const char* Name() const override {
|
||||
return "TtlCompactionFilterFactory";
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t ttl_;
|
||||
std::shared_ptr<CompactionFilterFactory> user_comp_filter_factory_;
|
||||
};
|
||||
|
||||
class TtlMergeOperator : public MergeOperator {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
|
||||
#include <memory>
|
||||
#include "leveldb/compaction_filter.h"
|
||||
#include "utilities/utility_db.h"
|
||||
#include "util/testharness.h"
|
||||
@@ -54,8 +55,9 @@ class TtlTest {
|
||||
|
||||
// Open with TestFilter compaction filter
|
||||
void OpenTtlWithTestCompaction(int32_t ttl) {
|
||||
test_comp_filter_.reset(new TestFilter(kSampleSize_, kNewValue_));
|
||||
options_.compaction_filter = test_comp_filter_.get();
|
||||
options_.compaction_filter_factory =
|
||||
std::shared_ptr<CompactionFilterFactory>(
|
||||
new TestFilterFactory(kSampleSize_, kNewValue_));
|
||||
OpenTtl(ttl);
|
||||
}
|
||||
|
||||
@@ -252,6 +254,29 @@ class TtlTest {
|
||||
const std::string kNewValue_;
|
||||
};
|
||||
|
||||
class TestFilterFactory : public CompactionFilterFactory {
|
||||
public:
|
||||
TestFilterFactory(const int64_t kSampleSize, const std::string kNewValue)
|
||||
: kSampleSize_(kSampleSize),
|
||||
kNewValue_(kNewValue) {
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<CompactionFilter>
|
||||
CreateCompactionFilter() override {
|
||||
return std::unique_ptr<CompactionFilter>(
|
||||
new TestFilter(kSampleSize_, kNewValue_));
|
||||
}
|
||||
|
||||
virtual const char* Name() const override {
|
||||
return "TestFilterFactory";
|
||||
}
|
||||
|
||||
private:
|
||||
const int64_t kSampleSize_;
|
||||
const std::string kNewValue_;
|
||||
};
|
||||
|
||||
|
||||
// Choose carefully so that Put, Gets & Compaction complete in 1 second buffer
|
||||
const int64_t kSampleSize_ = 100;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user