@ -10,6 +10,7 @@
# include <cstring>
# include <iomanip>
# include <sstream>
# include <string>
# include "cache/cache_entry_roles.h"
# include "cache/cache_reservation_manager.h"
@ -27,7 +28,17 @@
namespace ROCKSDB_NAMESPACE {
namespace {
using BFP = BloomFilterPolicy ;
std : : shared_ptr < const FilterPolicy > Create ( double bits_per_key ,
const std : : string & name ) {
return BloomLikeFilterPolicy : : Create ( name , bits_per_key ) ;
}
const std : : string kLegacyBloom = test : : LegacyBloomFilterPolicy : : kName ( ) ;
const std : : string kDeprecatedBlock =
DeprecatedBlockBasedBloomFilterPolicy : : kName ( ) ;
const std : : string kFastLocalBloom = test : : FastLocalBloomFilterPolicy : : kName ( ) ;
const std : : string kStandard128Ribbon =
test : : Standard128RibbonFilterPolicy : : kName ( ) ;
const std : : string kAutoBloom = BloomFilterPolicy : : kName ( ) ;
} // namespace
// DB tests related to bloom filter.
@ -38,12 +49,13 @@ class DBBloomFilterTest : public DBTestBase {
: DBTestBase ( " db_bloom_filter_test " , /*env_do_fsync=*/ true ) { }
} ;
class DBBloomFilterTestWithParam : public DBTestBase ,
public testing : : WithParamInterface <
std : : tuple < BFP : : Mode , bool , uint32_t > > {
class DBBloomFilterTestWithParam
: public DBTestBase ,
public testing : : WithParamInterface <
std : : tuple < std : : string , bool , uint32_t > > {
// public testing::WithParamInterface<bool> {
protected :
BFP : : Mode bfp_impl_ ;
std : : string bfp_impl_ ;
bool partition_filters_ ;
uint32_t format_version_ ;
@ -90,7 +102,7 @@ TEST_P(DBBloomFilterTestDefFormatVersion, KeyMayExist) {
ReadOptions ropts ;
std : : string value ;
anon : : OptionsOverride options_override ;
options_override . filter_policy . reset ( new BFP ( 20 , bfp_impl_ ) ) ;
options_override . filter_policy = Create ( 20 , bfp_impl_ ) ;
options_override . partition_filters = partition_filters_ ;
options_override . metadata_block_size = 32 ;
Options options = CurrentOptions ( options_override ) ;
@ -477,7 +489,7 @@ TEST_P(DBBloomFilterTestWithParam, BloomFilter) {
// trigger reset of table_factory
BlockBasedTableOptions table_options ;
table_options . no_block_cache = true ;
table_options . filter_policy . reset ( new BFP ( 10 , bfp_impl_ ) ) ;
table_options . filter_policy = Create ( 10 , bfp_impl_ ) ;
table_options . partition_filters = partition_filters_ ;
if ( partition_filters_ ) {
table_options . index_type =
@ -573,11 +585,10 @@ class AlwaysTrueBitsBuilder : public FilterBitsBuilder {
size_t ApproximateNumEntries ( size_t ) override { return SIZE_MAX ; }
} ;
class AlwaysTrueFilterPolicy : public BloomFilterPolicy {
class AlwaysTrueFilterPolicy : public BloomLike FilterPolicy {
public :
explicit AlwaysTrueFilterPolicy ( bool skip )
: BloomFilterPolicy ( /* ignored */ 10 , /* ignored */ BFP : : kAutoBloom ) ,
skip_ ( skip ) { }
: BloomLikeFilterPolicy ( /* ignored */ 10 ) , skip_ ( skip ) { }
FilterBitsBuilder * GetBuilderWithContext (
const FilterBuildingContext & ) const override {
@ -588,6 +599,10 @@ class AlwaysTrueFilterPolicy : public BloomFilterPolicy {
}
}
std : : string GetId ( ) const override {
return " rocksdb.test.AlwaysTrueFilterPolicy " ;
}
private :
bool skip_ ;
} ;
@ -636,7 +651,7 @@ TEST_P(DBBloomFilterTestWithParam, SkipFilterOnEssentiallyZeroBpk) {
// Test 1: bits per key < 0.5 means skip filters -> no filter
// constructed or read.
table_options . filter_policy . reset ( new BFP ( 0.4 , bfp_impl_ ) ) ;
table_options . filter_policy = Create ( 0.4 , bfp_impl_ ) ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
DestroyAndReopen ( options ) ;
PutAndGetFn ( ) ;
@ -724,25 +739,23 @@ TEST_P(DBBloomFilterTestWithParam, SkipFilterOnEssentiallyZeroBpk) {
INSTANTIATE_TEST_CASE_P (
FormatDef , DBBloomFilterTestDefFormatVersion ,
: : testing : : Values (
std : : make_tuple ( BFP : : kDeprecatedBlock , false ,
test : : kDefaultFormatVersion ) ,
std : : make_tuple ( BFP : : kAutoBloom , true , test : : kDefaultFormatVersion ) ,
std : : make_tuple ( BFP : : kAutoBloom , false , test : : kDefaultFormatVersion ) ) ) ;
std : : make_tuple ( kDeprecatedBlock , false , test : : kDefaultFormatVersion ) ,
std : : make_tuple ( kAutoBloom , true , test : : kDefaultFormatVersion ) ,
std : : make_tuple ( kAutoBloom , false , test : : kDefaultFormatVersion ) ) ) ;
INSTANTIATE_TEST_CASE_P (
FormatDef , DBBloomFilterTestWithParam ,
: : testing : : Values (
std : : make_tuple ( BFP : : kDeprecatedBlock , false ,
test : : kDefaultFormatVersion ) ,
std : : make_tuple ( BFP : : kAutoBloom , true , test : : kDefaultFormatVersion ) ,
std : : make_tuple ( BFP : : kAutoBloom , false , test : : kDefaultFormatVersion ) ) ) ;
std : : make_tuple ( kDeprecatedBlock , false , test : : kDefaultFormatVersion ) ,
std : : make_tuple ( kAutoBloom , true , test : : kDefaultFormatVersion ) ,
std : : make_tuple ( kAutoBloom , false , test : : kDefaultFormatVersion ) ) ) ;
INSTANTIATE_TEST_CASE_P (
FormatLatest , DBBloomFilterTestWithParam ,
: : testing : : Values (
std : : make_tuple ( BFP : : kDeprecatedBlock , false , kLatestFormatVersion ) ,
std : : make_tuple ( BFP : : kAutoBloom , true , kLatestFormatVersion ) ,
std : : make_tuple ( BFP : : kAutoBloom , false , kLatestFormatVersion ) ) ) ;
std : : make_tuple ( kDeprecatedBlock , false , kLatestFormatVersion ) ,
std : : make_tuple ( kAutoBloom , true , kLatestFormatVersion ) ,
std : : make_tuple ( kAutoBloom , false , kLatestFormatVersion ) ) ) ;
# endif // !defined(ROCKSDB_VALGRIND_RUN) || defined(ROCKSDB_FULL_VALGRIND_RUN)
TEST_F ( DBBloomFilterTest , BloomFilterRate ) {
@ -941,7 +954,7 @@ using FilterConstructionReserveMemoryHash = uint64_t;
class DBFilterConstructionReserveMemoryTestWithParam
: public DBTestBase ,
public testing : : WithParamInterface <
std : : tuple < bool , BloomFilterPolicy : : Mode , bool , bool > > {
std : : tuple < bool , std : : string , bool , bool > > {
public :
DBFilterConstructionReserveMemoryTestWithParam ( )
: DBTestBase ( " db_bloom_filter_tests " ,
@ -951,9 +964,8 @@ class DBFilterConstructionReserveMemoryTestWithParam
policy_ ( std : : get < 1 > ( GetParam ( ) ) ) ,
partition_filters_ ( std : : get < 2 > ( GetParam ( ) ) ) ,
detect_filter_construct_corruption_ ( std : : get < 3 > ( GetParam ( ) ) ) {
if ( ! reserve_table_builder_memory_ | |
policy_ = = BloomFilterPolicy : : Mode : : kDeprecatedBlock | |
policy_ = = BloomFilterPolicy : : Mode : : kLegacyBloom ) {
if ( ! reserve_table_builder_memory_ | | policy_ = = kDeprecatedBlock | |
policy_ = = kLegacyBloom ) {
// For these cases, we only interested in whether filter construction
// cache resevation happens instead of its accuracy. Therefore we don't
// need many keys.
@ -966,7 +978,7 @@ class DBFilterConstructionReserveMemoryTestWithParam
// two partitions.
num_key_ = 18 * CacheReservationManager : : GetDummyEntrySize ( ) /
sizeof ( FilterConstructionReserveMemoryHash ) ;
} else if ( policy_ = = BloomFilterPolicy : : Mode : : kFastLocalBloom ) {
} else if ( policy_ = = kFastLocalBloom ) {
// For Bloom Filter + FullFilter case, since we design the num_key_ to
// make hash entry cache reservation be a multiple of dummy entries, the
// correct behavior of charging final filter on top of it will trigger at
@ -995,7 +1007,7 @@ class DBFilterConstructionReserveMemoryTestWithParam
constexpr std : : size_t kCacheCapacity = 100 * 1024 * 1024 ;
table_options . reserve_table_builder_memory = reserve_table_builder_memory_ ;
table_options . filter_policy . reset ( new BloomFilterPolicy ( 10 , policy_ ) ) ;
table_options . filter_policy = Create ( 10 , policy_ ) ;
table_options . partition_filters = partition_filters_ ;
if ( table_options . partition_filters ) {
table_options . index_type =
@ -1023,7 +1035,7 @@ class DBFilterConstructionReserveMemoryTestWithParam
bool ReserveTableBuilderMemory ( ) { return reserve_table_builder_memory_ ; }
BloomFilterPolicy : : Mode GetFilterPolicy ( ) { return policy_ ; }
std : : string GetFilterPolicy ( ) { return policy_ ; }
bool PartitionFilters ( ) { return partition_filters_ ; }
@ -1035,7 +1047,7 @@ class DBFilterConstructionReserveMemoryTestWithParam
private :
std : : size_t num_key_ ;
bool reserve_table_builder_memory_ ;
BloomFilterPolicy : : Mode policy_ ;
std : : string policy_ ;
bool partition_filters_ ;
std : : shared_ptr < FilterConstructResPeakTrackingCache > cache_ ;
bool detect_filter_construct_corruption_ ;
@ -1043,32 +1055,20 @@ class DBFilterConstructionReserveMemoryTestWithParam
INSTANTIATE_TEST_CASE_P (
BlockBasedTableOptions , DBFilterConstructionReserveMemoryTestWithParam ,
: : testing : : Values (
std : : make_tuple ( false , BloomFilterPolicy : : Mode : : kFastLocalBloom , false ,
false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kFastLocalBloom , false ,
false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kFastLocalBloom , false ,
true ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kFastLocalBloom , true ,
false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kFastLocalBloom , true ,
true ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kStandard128Ribbon ,
false , false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kStandard128Ribbon ,
false , true ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kStandard128Ribbon , true ,
false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kStandard128Ribbon , true ,
true ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kDeprecatedBlock , false ,
false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kLegacyBloom , false ,
false ) ) ) ;
: : testing : : Values ( std : : make_tuple ( false , kFastLocalBloom , false , false ) ,
std : : make_tuple ( true , kFastLocalBloom , false , false ) ,
std : : make_tuple ( true , kFastLocalBloom , false , true ) ,
std : : make_tuple ( true , kFastLocalBloom , true , false ) ,
std : : make_tuple ( true , kFastLocalBloom , true , true ) ,
std : : make_tuple ( true , kStandard128Ribbon , false , false ) ,
std : : make_tuple ( true , kStandard128Ribbon , false , true ) ,
std : : make_tuple ( true , kStandard128Ribbon , true , false ) ,
std : : make_tuple ( true , kStandard128Ribbon , true , true ) ,
std : : make_tuple ( true , kDeprecatedBlock , false , false ) ,
std : : make_tuple ( true , kLegacyBloom , false , false ) ) ) ;
// TODO: Speed up this test.
// The current test inserts many keys (on the scale of dummy entry size)
@ -1126,7 +1126,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
ASSERT_OK ( Flush ( ) ) ;
bool reserve_table_builder_memory = ReserveTableBuilderMemory ( ) ;
BloomFilterPolicy : : Mode policy = GetFilterPolicy ( ) ;
std : : string policy = GetFilterPolicy ( ) ;
bool partition_filters = PartitionFilters ( ) ;
bool detect_filter_construct_corruption =
table_options . detect_filter_construct_corruption ;
@ -1141,12 +1141,11 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
return ;
}
if ( policy = = BloomFilterPolicy : : Mode : : kDeprecatedBlock | |
policy = = BloomFilterPolicy : : Mode : : kLegacyBloom ) {
if ( policy = = kDeprecatedBlock | | policy = = kLegacyBloom ) {
EXPECT_EQ ( filter_construction_cache_res_peaks . size ( ) , 0 )
< < " There shouldn't be filter construction cache reservation as this "
" feature does not support BloomFilterPolicy::Mode:: kDeprecatedBlock "
" nor BloomFilterPolicy::Mode:: kLegacyBloom " ;
" feature does not support kDeprecatedBlock "
" nor kLegacyBloom " ;
return ;
}
@ -1162,17 +1161,17 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
const std : : size_t predicted_hash_entries_cache_res_dummy_entry_num =
predicted_hash_entries_cache_res / kDummyEntrySize ;
const std : : size_t predicted_final_filter_cache_res =
static_cast < std : : size_t > ( std : : ceil (
1.0 * predicted_hash_entries_cache_res_dummy_entry_num / 6 *
( policy = = BloomFilterPolicy : : Mode : : kStandard128Ribbon ? 0.7 : 1 ) ) ) *
static_cast < std : : size_t > (
std : : ceil ( 1.0 * predicted_hash_entries_cache_res_dummy_entry_num / 6 *
( policy = = kStandard128Ribbon ? 0.7 : 1 ) ) ) *
kDummyEntrySize ;
const std : : size_t predicted_banding_cache_res =
static_cast < std : : size_t > (
std : : ceil ( predicted_hash_entries_cache_res_dummy_entry_num * 2.5 ) ) *
kDummyEntrySize ;
if ( policy = = BloomFilterPolicy : : Mode : : kFastLocalBloom ) {
/* BloomFilterPolicy::Mode:: kFastLocalBloom + FullFilter
if ( policy = = kFastLocalBloom ) {
/* kFastLocalBloom + FullFilter
* p0
* / \
* b / \
@ -1186,13 +1185,13 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
* multiple of dummy entries so that reservation for ( p0 - b )
* will trigger at least another dummy entry insertion .
*
* BloomFilterPolicy : : Mode : : kFastLocalBloom + FullFilter +
* kFastLocalBloom + FullFilter +
* detect_filter_construct_corruption
* The peak p0 stays the same as
* ( BloomFilterPolicy : : Mode : : kFastLocalBloom + FullFilter ) but just lasts
* ( kFastLocalBloom + FullFilter ) but just lasts
* longer since we release hash entries reservation later .
*
* BloomFilterPolicy : : Mode : : kFastLocalBloom + PartitionedFilter
* kFastLocalBloom + PartitionedFilter
* p1
* / \
* p0 b ' / \
@ -1209,17 +1208,17 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
* + parittioned final filter1 + parittioned final filter2
* = hash entries + final filter
*
* BloomFilterPolicy : : Mode : : kFastLocalBloom + PartitionedFilter +
* kFastLocalBloom + PartitionedFilter +
* detect_filter_construct_corruption
* The peak p0 , p1 stay the same as
* ( BloomFilterPolicy : : Mode : : kFastLocalBloom + PartitionedFilter ) but just
* ( kFastLocalBloom + PartitionedFilter ) but just
* last longer since we release hash entries reservation later .
*
*/
if ( ! partition_filters ) {
EXPECT_EQ ( filter_construction_cache_res_peaks . size ( ) , 1 )
< < " Filter construction cache reservation should have only 1 peak in "
" case: BloomFilterPolicy::Mode:: kFastLocalBloom + FullFilter " ;
" case: kFastLocalBloom + FullFilter " ;
std : : size_t filter_construction_cache_res_peak =
filter_construction_cache_res_peaks [ 0 ] ;
EXPECT_GT ( filter_construction_cache_res_peak ,
@ -1239,7 +1238,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
} else {
EXPECT_GE ( filter_construction_cache_res_peaks . size ( ) , 2 )
< < " Filter construction cache reservation should have multiple peaks "
" in case: BloomFilterPolicy::Mode:: kFastLocalBloom + "
" in case: kFastLocalBloom + "
" PartitionedFilter " ;
std : : size_t predicted_filter_construction_cache_res_increments_sum =
predicted_hash_entries_cache_res + predicted_final_filter_cache_res ;
@ -1251,8 +1250,8 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
}
}
if ( policy = = BloomFilterPolicy : : Mode : : kStandard128Ribbon ) {
/* BloomFilterPolicy::Mode:: kStandard128Ribbon + FullFilter
if ( policy = = kStandard128Ribbon ) {
/* kStandard128Ribbon + FullFilter
* p0
* / \ p1
* / \ / \
@ -1266,7 +1265,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
* will trigger at least another dummy entry insertion
* ( or equivelantly to saying , creating another peak ) .
*
* BloomFilterPolicy : : Mode : : kStandard128Ribbon + FullFilter +
* kStandard128Ribbon + FullFilter +
* detect_filter_construct_corruption
*
* new p0
@ -1287,7 +1286,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
* entries reserveration ( like p0 - b ' previously ) until after final filter
* creation and post - verification
*
* BloomFilterPolicy : : Mode : : kStandard128Ribbon + PartitionedFilter
* kStandard128Ribbon + PartitionedFilter
* p3
* p0 / \ p4
* / \ p1 / \ / \
@ -1306,7 +1305,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
* + parittioned final filter1 + parittioned final filter2
* = hash entries + banding + final filter
*
* BloomFilterPolicy : : Mode : : kStandard128Ribbon + PartitionedFilter +
* kStandard128Ribbon + PartitionedFilter +
* detect_filter_construct_corruption
*
* new p3
@ -1347,7 +1346,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
if ( ! detect_filter_construct_corruption ) {
EXPECT_EQ ( filter_construction_cache_res_peaks . size ( ) , 2 )
< < " Filter construction cache reservation should have 2 peaks in "
" case: BloomFilterPolicy::Mode:: kStandard128Ribbon + "
" case: kStandard128Ribbon + "
" FullFilter. "
" The second peak is resulted from charging the final filter "
" after "
@ -1366,7 +1365,7 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
} else {
EXPECT_EQ ( filter_construction_cache_res_peaks . size ( ) , 1 )
< < " Filter construction cache reservation should have 1 peaks in "
" case: BloomFilterPolicy::Mode:: kStandard128Ribbon + FullFilter "
" case: kStandard128Ribbon + FullFilter "
" + detect_filter_construct_corruption. "
" The previous second peak now disappears since we don't "
" decrease the hash entry reservation "
@ -1388,13 +1387,13 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
EXPECT_GE ( filter_construction_cache_res_peaks . size ( ) , 3 )
< < " Filter construction cache reservation should have more than 3 "
" peaks "
" in case: BloomFilterPolicy::Mode:: kStandard128Ribbon + "
" in case: kStandard128Ribbon + "
" PartitionedFilter " ;
} else {
EXPECT_GE ( filter_construction_cache_res_peaks . size ( ) , 2 )
< < " Filter construction cache reservation should have more than 2 "
" peaks "
" in case: BloomFilterPolicy::Mode:: kStandard128Ribbon + "
" in case: kStandard128Ribbon + "
" PartitionedFilter + detect_filter_construct_corruption " ;
}
std : : size_t predicted_filter_construction_cache_res_increments_sum =
@ -1412,8 +1411,8 @@ TEST_P(DBFilterConstructionReserveMemoryTestWithParam, ReserveMemory) {
class DBFilterConstructionCorruptionTestWithParam
: public DBTestBase ,
public testing : : WithParamInterface <
std : : tuple < bool /* detect_filter_construct_corruption */ ,
BloomFilterPolicy : : Mode , bool /* partition_filters */ > > {
std : : tuple < bool /* detect_filter_construct_corruption */ , std : : string ,
bool /* partition_filters */ > > {
public :
DBFilterConstructionCorruptionTestWithParam ( )
: DBTestBase ( " db_bloom_filter_tests " ,
@ -1422,8 +1421,7 @@ class DBFilterConstructionCorruptionTestWithParam
BlockBasedTableOptions GetBlockBasedTableOptions ( ) {
BlockBasedTableOptions table_options ;
table_options . detect_filter_construct_corruption = std : : get < 0 > ( GetParam ( ) ) ;
table_options . filter_policy . reset (
new BloomFilterPolicy ( 10 , std : : get < 1 > ( GetParam ( ) ) ) ) ;
table_options . filter_policy = Create ( 10 , std : : get < 1 > ( GetParam ( ) ) ) ;
table_options . partition_filters = std : : get < 2 > ( GetParam ( ) ) ;
if ( table_options . partition_filters ) {
table_options . index_type =
@ -1444,14 +1442,11 @@ class DBFilterConstructionCorruptionTestWithParam
INSTANTIATE_TEST_CASE_P (
DBFilterConstructionCorruptionTestWithParam ,
DBFilterConstructionCorruptionTestWithParam ,
: : testing : : Values (
std : : make_tuple ( false , BloomFilterPolicy : : Mode : : kFastLocalBloom , false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kFastLocalBloom , false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kFastLocalBloom , true ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kStandard128Ribbon ,
false ) ,
std : : make_tuple ( true , BloomFilterPolicy : : Mode : : kStandard128Ribbon ,
true ) ) ) ;
: : testing : : Values ( std : : make_tuple ( false , kFastLocalBloom , false ) ,
std : : make_tuple ( true , kFastLocalBloom , false ) ,
std : : make_tuple ( true , kFastLocalBloom , true ) ,
std : : make_tuple ( true , kStandard128Ribbon , false ) ,
std : : make_tuple ( true , kStandard128Ribbon , true ) ) ) ;
TEST_P ( DBFilterConstructionCorruptionTestWithParam , DetectCorruption ) {
Options options = CurrentOptions ( ) ;
@ -2139,16 +2134,12 @@ INSTANTIATE_TEST_CASE_P(DBBloomFilterTestVaryPrefixAndFormatVer,
# ifndef ROCKSDB_LITE
namespace {
namespace BFP2 {
// Extends BFP::Mode with option to use Plain table
using PseudoMode = int ;
static constexpr PseudoMode kPlainTable = - 1 ;
} // namespace BFP2
static const std : : string kPlainTable = " test_PlainTableBloom " ;
} // namespace
class BloomStatsTestWithParam
: public DBBloomFilterTest ,
public testing : : WithParamInterface < std : : tuple < BFP2 : : PseudoMode , bool > > {
public testing : : WithParamInterface < std : : tuple < std : : string , bool > > {
public :
BloomStatsTestWithParam ( ) {
bfp_impl_ = std : : get < 0 > ( GetParam ( ) ) ;
@ -2159,7 +2150,7 @@ class BloomStatsTestWithParam
ROCKSDB_NAMESPACE : : NewFixedPrefixTransform ( 4 ) ) ;
options_ . memtable_prefix_bloom_size_ratio =
8.0 * 1024.0 / static_cast < double > ( options_ . write_buffer_size ) ;
if ( bfp_impl_ = = BFP2 : : kPlainTable ) {
if ( bfp_impl_ = = kPlainTable ) {
assert ( ! partition_filters_ ) ; // not supported in plain table
PlainTableOptions table_options ;
options_ . table_factory . reset ( NewPlainTableFactory ( table_options ) ) ;
@ -2167,13 +2158,12 @@ class BloomStatsTestWithParam
BlockBasedTableOptions table_options ;
table_options . hash_index_allow_collision = false ;
if ( partition_filters_ ) {
assert ( bfp_impl_ ! = BFP : : kDeprecatedBlock ) ;
assert ( bfp_impl_ ! = kDeprecatedBlock ) ;
table_options . partition_filters = partition_filters_ ;
table_options . index_type =
BlockBasedTableOptions : : IndexType : : kTwoLevelIndexSearch ;
}
table_options . filter_policy . reset (
new BFP ( 10 , static_cast < BFP : : Mode > ( bfp_impl_ ) ) ) ;
table_options . filter_policy = Create ( 10 , bfp_impl_ ) ;
options_ . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
}
options_ . env = env_ ;
@ -2191,7 +2181,7 @@ class BloomStatsTestWithParam
static void SetUpTestCase ( ) { }
static void TearDownTestCase ( ) { }
BFP2 : : PseudoMode bfp_impl_ ;
std : : string bfp_impl_ ;
bool partition_filters_ ;
Options options_ ;
} ;
@ -2295,7 +2285,7 @@ TEST_P(BloomStatsTestWithParam, BloomStatsTestWithIter) {
ASSERT_EQ ( value3 , iter - > value ( ) . ToString ( ) ) ;
// The seek doesn't check block-based bloom filter because last index key
// starts with the same prefix we're seeking to.
uint64_t expected_hits = bfp_impl_ = = BFP : : kDeprecatedBlock ? 1 : 2 ;
uint64_t expected_hits = bfp_impl_ = = kDeprecatedBlock ? 1 : 2 ;
ASSERT_EQ ( expected_hits , get_perf_context ( ) - > bloom_sst_hit_count ) ;
iter - > Seek ( key2 ) ;
@ -2307,12 +2297,12 @@ TEST_P(BloomStatsTestWithParam, BloomStatsTestWithIter) {
INSTANTIATE_TEST_CASE_P (
BloomStatsTestWithParam , BloomStatsTestWithParam ,
: : testing : : Values ( std : : make_tuple ( BFP : : kDeprecatedBlock , false ) ,
std : : make_tuple ( BFP : : kLegacyBloom , false ) ,
std : : make_tuple ( BFP : : kLegacyBloom , true ) ,
std : : make_tuple ( BFP : : kFastLocalBloom , false ) ,
std : : make_tuple ( BFP : : kFastLocalBloom , true ) ,
std : : make_tuple ( BFP2 : : kPlainTable , false ) ) ) ;
: : testing : : Values ( std : : make_tuple ( kDeprecatedBlock , false ) ,
std : : make_tuple ( kLegacyBloom , false ) ,
std : : make_tuple ( kLegacyBloom , true ) ,
std : : make_tuple ( kFastLocalBloom , false ) ,
std : : make_tuple ( kFastLocalBloom , true ) ,
std : : make_tuple ( kPlainTable , false ) ) ) ;
namespace {
void PrefixScanInit ( DBBloomFilterTest * dbtest ) {
@ -2620,8 +2610,8 @@ int CountIter(std::unique_ptr<Iterator>& iter, const Slice& key) {
// into the same string, or 2) the transformed seek key is of the same length
// as the upper bound and two keys are adjacent according to the comparator.
TEST_F ( DBBloomFilterTest , DynamicBloomFilterUpperBound ) {
for ( auto bfp_impl : BFP : : kAllFixedImpls ) {
int using_full_builder = bfp_impl ! = BFP : : kDeprecatedBlock ;
for ( const auto & bfp_impl : BloomLike Filter Policy : : GetAllFixedImpls ( ) ) {
int using_full_builder = bfp_impl ! = kDeprecatedBlock ;
Options options ;
options . create_if_missing = true ;
options . env = CurrentOptions ( ) . env ;
@ -2631,7 +2621,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterUpperBound) {
// Enable prefix bloom for SST files
BlockBasedTableOptions table_options ;
table_options . cache_index_and_filter_blocks = true ;
table_options . filter_policy . reset ( new BFP ( 10 , bfp_impl ) ) ;
table_options . filter_policy = Create ( 10 , bfp_impl ) ;
table_options . index_shortening = BlockBasedTableOptions : :
IndexShorteningMode : : kShortenSeparatorsAndSuccessor ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
@ -2752,8 +2742,8 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterUpperBound) {
// Create multiple SST files each with a different prefix_extractor config,
// verify iterators can read all SST files using the latest config.
TEST_F ( DBBloomFilterTest , DynamicBloomFilterMultipleSST ) {
for ( auto bfp_impl : BFP : : kAllFixedImpls ) {
int using_full_builder = bfp_impl ! = BFP : : kDeprecatedBlock ;
for ( const auto & bfp_impl : BloomLike Filter Policy : : GetAllFixedImpls ( ) ) {
int using_full_builder = bfp_impl ! = kDeprecatedBlock ;
Options options ;
options . env = CurrentOptions ( ) . env ;
options . create_if_missing = true ;
@ -2762,7 +2752,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterMultipleSST) {
options . statistics = CreateDBStatistics ( ) ;
// Enable prefix bloom for SST files
BlockBasedTableOptions table_options ;
table_options . filter_policy . reset ( new BFP ( 10 , bfp_impl ) ) ;
table_options . filter_policy = Create ( 10 , bfp_impl ) ;
table_options . cache_index_and_filter_blocks = true ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
DestroyAndReopen ( options ) ;
@ -2888,7 +2878,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterMultipleSST) {
// as expected
TEST_F ( DBBloomFilterTest , DynamicBloomFilterNewColumnFamily ) {
int iteration = 0 ;
for ( auto bfp_impl : BFP : : kAllFixedImpls ) {
for ( const auto & bfp_impl : BloomLike Filter Policy : : GetAllFixedImpls ( ) ) {
Options options = CurrentOptions ( ) ;
options . create_if_missing = true ;
options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ;
@ -2897,7 +2887,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterNewColumnFamily) {
// Enable prefix bloom for SST files
BlockBasedTableOptions table_options ;
table_options . cache_index_and_filter_blocks = true ;
table_options . filter_policy . reset ( new BFP ( 10 , bfp_impl ) ) ;
table_options . filter_policy = Create ( 10 , bfp_impl ) ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
CreateAndReopenWithCF ( { " pikachu " + std : : to_string ( iteration ) } , options ) ;
ReadOptions read_options ;
@ -2944,7 +2934,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterNewColumnFamily) {
// Verify it's possible to change prefix_extractor at runtime and iterators
// behaves as expected
TEST_F ( DBBloomFilterTest , DynamicBloomFilterOptions ) {
for ( auto bfp_impl : BFP : : kAllFixedImpls ) {
for ( const auto & bfp_impl : BloomLike Filter Policy : : GetAllFixedImpls ( ) ) {
Options options ;
options . env = CurrentOptions ( ) . env ;
options . create_if_missing = true ;
@ -2954,7 +2944,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterOptions) {
// Enable prefix bloom for SST files
BlockBasedTableOptions table_options ;
table_options . cache_index_and_filter_blocks = true ;
table_options . filter_policy . reset ( new BFP ( 10 , bfp_impl ) ) ;
table_options . filter_policy = Create ( 10 , bfp_impl ) ;
options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ;
DestroyAndReopen ( options ) ;