From de98fd88e3b9e4ac5c8114aada07635256d9e3ae Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Thu, 12 Jul 2018 19:33:59 -0700 Subject: [PATCH] Support compaction filter in db_bench (#4106) Summary: Right now there is no support for enabling compaction filter in db_bench, we should add support for that to facilitate testing of compaction filter. This PR adds a compaction filter called KeepFilter and make `Filter` always returns false, essentially a noop compaction filter. This will allow us to test compaction filter code path without having to support arbitrary compaction filters Pull Request resolved: https://github.com/facebook/rocksdb/pull/4106 Differential Revision: D8828517 Pulled By: miasantreble fbshipit-source-id: 9ad76d04103eaa9d00da98334b4a39e542d26c41 --- tools/db_bench_tool.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 20abdd56e..7c6fb162a 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -525,6 +525,9 @@ DEFINE_bool(read_cache_direct_write, true, DEFINE_bool(read_cache_direct_read, true, "Whether to use Direct IO for reading from read cache"); +DEFINE_bool(use_keep_filter, false, + "Whether to use a noop compaction filter"); + static bool ValidateCacheNumshardbits(const char* flagname, int32_t value) { if (value >= 20) { fprintf(stderr, "Invalid value for --%s: %d, must be < 20\n", @@ -2199,6 +2202,17 @@ class Benchmark { std::shared_ptr timestamp_emulator_; }; + class KeepFilter : public CompactionFilter { + public: + virtual bool Filter(int /*level*/, const Slice& /*key*/, + const Slice& /*value*/, std::string* /*new_value*/, + bool* /*value_changed*/) const override { + return false; + } + + virtual const char* Name() const override { return "KeepFilter"; } + }; + std::shared_ptr NewCache(int64_t capacity) { if (capacity <= 0) { return nullptr; @@ -3427,6 +3441,12 @@ void VerifyDBFromDB(std::string& truth_db_name) { } options.wal_dir = wal_dir; } + + // KeepFilter is a noop filter, this can be used to test compaction filter + if (FLAGS_use_keep_filter) { + options.compaction_filter = new KeepFilter(); + fprintf(stdout, "A noop compaction filter is used\n"); + } } void Open(Options* opts) {