ca3b6c28c9
Summary: This change enables custom implementations of FilterPolicy to wrap a variety of NewBloomFilterPolicy and select among them based on contextual information such as table level and compaction style. * Moves FilterBuildingContext to public API and elaborates it with more useful data. (It would be nice to put more general options-like data, but at the time this object is constructed, we are using internal APIs ImmutableCFOptions and MutableCFOptions and don't have easy access to ColumnFamilyOptions that I can tell.) * Renames BloomFilterPolicy::GetFilterBitsBuilderInternal to GetBuilderWithContext, because it's now public. * Plumbs through the table's "level_at_creation" for filter building context. * Simplified some tests by adding GetBuilder() to MockBlockBasedTableTester. * Adds test as DBBloomFilterTest.ContextCustomFilterPolicy, including sample wrapper class LevelAndStyleCustomFilterPolicy. * Fixes a cross-test bug in DBBloomFilterTest.OptimizeFiltersForHits where it does not reset perf context. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6088 Test Plan: make check, valgrind on db_bloom_filter_test Differential Revision: D18697817 Pulled By: pdillinger fbshipit-source-id: 5f987a2d7b07cc7a33670bc08ca6b4ca698c1cf4
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
// Copyright (c) 2019-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
#pragma once
|
|
|
|
#include "rocksdb/filter_policy.h"
|
|
#include "table/block_based/block_based_filter_block.h"
|
|
#include "table/block_based/block_based_table_reader.h"
|
|
#include "table/block_based/filter_policy_internal.h"
|
|
|
|
namespace rocksdb {
|
|
namespace mock {
|
|
|
|
class MockBlockBasedTable : public BlockBasedTable {
|
|
public:
|
|
explicit MockBlockBasedTable(Rep* rep)
|
|
: BlockBasedTable(rep, nullptr /* block_cache_tracer */) {}
|
|
};
|
|
|
|
class MockBlockBasedTableTester {
|
|
static constexpr int kMockLevel = 0;
|
|
|
|
public:
|
|
Options options_;
|
|
ImmutableCFOptions ioptions_;
|
|
EnvOptions env_options_;
|
|
BlockBasedTableOptions table_options_;
|
|
InternalKeyComparator icomp_;
|
|
std::unique_ptr<BlockBasedTable> table_;
|
|
|
|
MockBlockBasedTableTester(const FilterPolicy *filter_policy)
|
|
: ioptions_(options_),
|
|
env_options_(options_),
|
|
icomp_(options_.comparator) {
|
|
table_options_.filter_policy.reset(filter_policy);
|
|
|
|
constexpr bool skip_filters = false;
|
|
constexpr bool immortal_table = false;
|
|
table_.reset(new MockBlockBasedTable(new BlockBasedTable::Rep(
|
|
ioptions_, env_options_, table_options_, icomp_, skip_filters,
|
|
kMockLevel, immortal_table)));
|
|
}
|
|
|
|
FilterBitsBuilder* GetBuilder() const {
|
|
FilterBuildingContext context(table_options_);
|
|
context.column_family_name = "mock_cf";
|
|
context.compaction_style = ioptions_.compaction_style;
|
|
context.level_at_creation = kMockLevel;
|
|
return BloomFilterPolicy::GetBuilderFromContext(context);
|
|
}
|
|
};
|
|
|
|
} // namespace mock
|
|
} // namespace rocksdb
|