CompactionContext to include is_manual_compaction

Summary: Added a bit more information to compaction context, requested by internal team at FB.

Test Plan: Modified CompactionFilter test to make sure is_manual_compaction is properly set.

Reviewers: haobo

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D16095
This commit is contained in:
Igor Canadi 2014-02-12 12:24:18 -08:00
parent 994c327b86
commit ca5f1a225a
7 changed files with 20 additions and 1 deletions

View File

@ -6,6 +6,7 @@
* Removed arena.h from public header files. * Removed arena.h from public header files.
* By default, checksums are verified on every read from database * By default, checksums are verified on every read from database
* Added is_manual_compaction to CompactionFilter::Context
## 2.7.0 (01/28/2014) ## 2.7.0 (01/28/2014)

View File

@ -39,6 +39,7 @@ Compaction::Compaction(Version* input_version, int level, int out_level,
score_(0), score_(0),
bottommost_level_(false), bottommost_level_(false),
is_full_compaction_(false), is_full_compaction_(false),
is_manual_compaction_(false),
level_ptrs_(std::vector<size_t>(number_levels_)) { level_ptrs_(std::vector<size_t>(number_levels_)) {
input_version_->Ref(); input_version_->Ref();

View File

@ -78,6 +78,9 @@ class Compaction {
// Does this compaction include all sst files? // Does this compaction include all sst files?
bool IsFullCompaction() { return is_full_compaction_; } bool IsFullCompaction() { return is_full_compaction_; }
// Was this compaction triggered manually by the client?
bool IsManualCompaction() { return is_manual_compaction_; }
private: private:
friend class CompactionPicker; friend class CompactionPicker;
friend class UniversalCompactionPicker; friend class UniversalCompactionPicker;
@ -117,6 +120,9 @@ class Compaction {
// Does this compaction include all sst files? // Does this compaction include all sst files?
bool is_full_compaction_; 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 // level_ptrs_ holds indices into input_version_->levels_: our state
// is that we are positioned at one of the file ranges for each // 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 // higher level than the ones involved in this compaction (i.e. for

View File

@ -361,6 +361,9 @@ Compaction* CompactionPicker::CompactRange(Version* version, int input_level,
// Is this compaction creating a file at the bottommost level // Is this compaction creating a file at the bottommost level
c->SetupBottomMostLevel(true); c->SetupBottomMostLevel(true);
c->is_manual_compaction_ = true;
return c; return c;
} }

View File

@ -112,6 +112,7 @@ struct DBImpl::CompactionState {
CompactionFilter::Context GetFilterContext() { CompactionFilter::Context GetFilterContext() {
CompactionFilter::Context context; CompactionFilter::Context context;
context.is_full_compaction = compaction->IsFullCompaction(); context.is_full_compaction = compaction->IsFullCompaction();
context.is_manual_compaction = compaction->IsManualCompaction();
return context; return context;
} }
}; };

View File

@ -2973,7 +2973,11 @@ class DeleteFilterFactory : public CompactionFilterFactory {
public: public:
virtual std::unique_ptr<CompactionFilter> virtual std::unique_ptr<CompactionFilter>
CreateCompactionFilter(const CompactionFilter::Context& context) override { CreateCompactionFilter(const CompactionFilter::Context& context) override {
return std::unique_ptr<CompactionFilter>(new DeleteFilter()); if (context.is_manual_compaction) {
return std::unique_ptr<CompactionFilter>(new DeleteFilter());
} else {
return std::unique_ptr<CompactionFilter>(nullptr);
}
} }
virtual const char* Name() const override { virtual const char* Name() const override {

View File

@ -25,6 +25,9 @@ class CompactionFilter {
struct Context { struct Context {
// Does this compaction run include all data files // Does this compaction run include all data files
bool is_full_compaction; 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() {}