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