public:
DBBloomFilterTestWithParam() : DBTestBase("/db_bloom_filter_tests") {}
- ~DBBloomFilterTestWithParam() {}
+ ~DBBloomFilterTestWithParam() override {}
void SetUp() override {
use_block_based_filter_ = std::get<0>(GetParam());
options.prefix_extractor =
std::make_shared<SliceTransformLimitedDomainGeneric>();
options.statistics = rocksdb::CreateDBStatistics();
+ get_perf_context()->EnablePerLevelPerfContext();
BlockBasedTableOptions bbto;
bbto.filter_policy.reset(NewBloomFilterPolicy(10, false));
if (partition_filters) {
ASSERT_EQ("foo", Get("barbarbar"));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 0);
+ ASSERT_EQ(
+ 0,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
ASSERT_EQ("foo2", Get("barbarbar2"));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 0);
+ ASSERT_EQ(
+ 0,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
ASSERT_EQ("NOT_FOUND", Get("barbarbar3"));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 0);
+ ASSERT_EQ(
+ 0,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
ASSERT_EQ("NOT_FOUND", Get("barfoofoo"));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 1);
+ ASSERT_EQ(
+ 1,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
ASSERT_EQ("NOT_FOUND", Get("foobarbar"));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 2);
+ ASSERT_EQ(
+ 2,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
ro.total_order_seek = true;
ASSERT_TRUE(db_->Get(ro, "foobarbar", &value).IsNotFound());
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 2);
+ ASSERT_EQ(
+ 2,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
+ get_perf_context()->Reset();
}
}
Options options = last_options_;
options.prefix_extractor.reset(NewFixedPrefixTransform(8));
options.statistics = rocksdb::CreateDBStatistics();
+ get_perf_context()->EnablePerLevelPerfContext();
BlockBasedTableOptions bbto;
bbto.filter_policy.reset(NewBloomFilterPolicy(10, false));
if (partition_filters) {
ro.total_order_seek = true;
ASSERT_TRUE(db_->Get(ro, "foobarbar", &value).IsNotFound());
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 2);
+ ASSERT_EQ(
+ 2,
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
+ get_perf_context()->Reset();
}
}
Options options = last_options_;
options.prefix_extractor.reset(NewFixedPrefixTransform(3));
options.statistics = rocksdb::CreateDBStatistics();
+ get_perf_context()->EnablePerLevelPerfContext();
BlockBasedTableOptions bbto;
bbto.filter_policy.reset(NewBloomFilterPolicy(10, false));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 12);
ASSERT_EQ("bar", Get("barfoo"));
ASSERT_EQ(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 12);
+ uint64_t bloom_filter_useful_all_levels = 0;
+ for (auto& kv : (*(get_perf_context()->level_to_perf_context))) {
+ if (kv.second.bloom_filter_useful > 0) {
+ bloom_filter_useful_all_levels += kv.second.bloom_filter_useful;
+ }
+ }
+ ASSERT_EQ(12, bloom_filter_useful_all_levels);
+ get_perf_context()->Reset();
}
}
} while (ChangeCompactOptions());
}
+#ifndef ROCKSDB_VALGRIND_RUN
INSTANTIATE_TEST_CASE_P(
FormatDef, DBBloomFilterTestDefFormatVersion,
::testing::Values(std::make_tuple(true, false, test::kDefaultFormatVersion),
std::make_tuple(false, true, test::kLatestFormatVersion),
std::make_tuple(false, false,
test::kLatestFormatVersion)));
+#endif // ROCKSDB_VALGRIND_RUN
TEST_F(DBBloomFilterTest, BloomFilterRate) {
while (ChangeFilterOptions()) {
Options options = CurrentOptions();
options.statistics = rocksdb::CreateDBStatistics();
+ get_perf_context()->EnablePerLevelPerfContext();
CreateAndReopenWithCF({"pikachu"}, options);
const int maxKey = 10000;
ASSERT_EQ("NOT_FOUND", Get(1, Key(i + 33333)));
}
ASSERT_GE(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), maxKey * 0.98);
+ ASSERT_GE(
+ (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful,
+ maxKey * 0.98);
+ get_perf_context()->Reset();
}
}
explicit WrappedBloom(int bits_per_key)
: filter_(NewBloomFilterPolicy(bits_per_key)), counter_(0) {}
- ~WrappedBloom() { delete filter_; }
+ ~WrappedBloom() override { delete filter_; }
const char* Name() const override { return "WrappedRocksDbFilterPolicy"; }
delete iter;
}
+TEST_F(DBBloomFilterTest, MemtableWholeKeyBloomFilter) {
+ // regression test for #2743. the range delete tombstones in memtable should
+ // be added even when Get() skips searching due to its prefix bloom filter
+ const int kMemtableSize = 1 << 20; // 1MB
+ const int kMemtablePrefixFilterSize = 1 << 13; // 8KB
+ const int kPrefixLen = 4;
+ Options options = CurrentOptions();
+ options.memtable_prefix_bloom_size_ratio =
+ static_cast<double>(kMemtablePrefixFilterSize) / kMemtableSize;
+ options.prefix_extractor.reset(rocksdb::NewFixedPrefixTransform(kPrefixLen));
+ options.write_buffer_size = kMemtableSize;
+ options.memtable_whole_key_filtering = false;
+ Reopen(options);
+ std::string key1("AAAABBBB");
+ std::string key2("AAAACCCC"); // not in DB
+ std::string key3("AAAADDDD");
+ std::string key4("AAAAEEEE");
+ std::string value1("Value1");
+ std::string value3("Value3");
+ std::string value4("Value4");
+
+ ASSERT_OK(Put(key1, value1, WriteOptions()));
+
+ // check memtable bloom stats
+ ASSERT_EQ("NOT_FOUND", Get(key2));
+ ASSERT_EQ(0, get_perf_context()->bloom_memtable_miss_count);
+ // same prefix, bloom filter false positive
+ ASSERT_EQ(1, get_perf_context()->bloom_memtable_hit_count);
+
+ // enable whole key bloom filter
+ options.memtable_whole_key_filtering = true;
+ Reopen(options);
+ // check memtable bloom stats
+ ASSERT_OK(Put(key3, value3, WriteOptions()));
+ ASSERT_EQ("NOT_FOUND", Get(key2));
+ // whole key bloom filter kicks in and determines it's a miss
+ ASSERT_EQ(1, get_perf_context()->bloom_memtable_miss_count);
+ ASSERT_EQ(1, get_perf_context()->bloom_memtable_hit_count);
+
+ // verify whole key filtering does not depend on prefix_extractor
+ options.prefix_extractor.reset();
+ Reopen(options);
+ // check memtable bloom stats
+ ASSERT_OK(Put(key4, value4, WriteOptions()));
+ ASSERT_EQ("NOT_FOUND", Get(key2));
+ // whole key bloom filter kicks in and determines it's a miss
+ ASSERT_EQ(2, get_perf_context()->bloom_memtable_miss_count);
+ ASSERT_EQ(1, get_perf_context()->bloom_memtable_hit_count);
+}
+
#ifndef ROCKSDB_LITE
class BloomStatsTestWithParam
: public DBBloomFilterTest,
DestroyAndReopen(options_);
}
- ~BloomStatsTestWithParam() {
+ ~BloomStatsTestWithParam() override {
get_perf_context()->Reset();
Destroy(options_);
}
ASSERT_OK(Put(key1, value1, WriteOptions()));
ASSERT_OK(Put(key3, value3, WriteOptions()));
- unique_ptr<Iterator> iter(dbfull()->NewIterator(ReadOptions()));
+ std::unique_ptr<Iterator> iter(dbfull()->NewIterator(ReadOptions()));
// check memtable bloom stats
iter->Seek(key1);
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
options.optimize_filters_for_hits = true;
options.statistics = rocksdb::CreateDBStatistics();
+ get_perf_context()->EnablePerLevelPerfContext();
CreateAndReopenWithCF({"mypikachu"}, options);
int numkeys = 200000;
// no bloom filter. Most keys be checked bloom filters twice.
ASSERT_GT(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 65000 * 2);
ASSERT_LT(TestGetTickerCount(options, BLOOM_FILTER_USEFUL), 120000 * 2);
+ uint64_t bloom_filter_useful_all_levels = 0;
+ for (auto& kv : (*(get_perf_context()->level_to_perf_context))) {
+ if (kv.second.bloom_filter_useful > 0) {
+ bloom_filter_useful_all_levels += kv.second.bloom_filter_useful;
+ }
+ }
+ ASSERT_GT(bloom_filter_useful_all_levels, 65000 * 2);
+ ASSERT_LT(bloom_filter_useful_all_levels, 120000 * 2);
for (int i = 0; i < numkeys; i += 2) {
ASSERT_EQ(Get(1, Key(i)), "val");
ASSERT_EQ(0, TestGetTickerCount(options, BLOCK_CACHE_FILTER_HIT));
ASSERT_EQ(2 /* index and data block */,
TestGetTickerCount(options, BLOCK_CACHE_ADD));
+ get_perf_context()->Reset();
}
int CountIter(std::unique_ptr<Iterator>& iter, const Slice& key) {