@ -10,6 +10,7 @@
# include "table/block_based/block_based_filter_block.h"
# include "table/block_based/block_based_filter_block.h"
# include "rocksdb/filter_policy.h"
# include "rocksdb/filter_policy.h"
# include "table/block_based/block_based_table_reader.h"
# include "test_util/testharness.h"
# include "test_util/testharness.h"
# include "test_util/testutil.h"
# include "test_util/testutil.h"
# include "util/coding.h"
# include "util/coding.h"
@ -41,28 +42,58 @@ class TestHashFilter : public FilterPolicy {
}
}
} ;
} ;
class MockBlockBasedTable : public BlockBasedTable {
public :
explicit MockBlockBasedTable ( Rep * rep )
: BlockBasedTable ( rep , nullptr /* block_cache_tracer */ ) {
// Initialize what Open normally does as much as necessary for the test
rep - > cache_key_prefix_size = 10 ;
}
} ;
class FilterBlockTest : public testing : : Test {
class FilterBlockTest : public testing : : Test {
public :
public :
TestHashFilter policy_ ;
Options options_ ;
ImmutableCFOptions ioptions_ ;
EnvOptions env_options_ ;
BlockBasedTableOptions table_options_ ;
BlockBasedTableOptions table_options_ ;
InternalKeyComparator icomp_ ;
FilterBlockTest ( ) {
std : : unique_ptr < BlockBasedTable > table_ ;
table_options_ . filter_policy . reset ( new TestHashFilter ( ) ) ;
FilterBlockTest ( )
: ioptions_ ( options_ ) ,
env_options_ ( options_ ) ,
icomp_ ( options_ . comparator ) {
table_options_ . no_block_cache = true ;
table_options_ . filter_policy . reset ( new TestHashFilter ) ;
constexpr bool skip_filters = false ;
constexpr int level = 0 ;
constexpr bool immortal_table = false ;
table_ . reset ( new MockBlockBasedTable (
new BlockBasedTable : : Rep ( ioptions_ , env_options_ , table_options_ ,
icomp_ , skip_filters , level , immortal_table ) ) ) ;
}
}
} ;
} ;
TEST_F ( FilterBlockTest , EmptyBuilder ) {
TEST_F ( FilterBlockTest , EmptyBuilder ) {
BlockBasedFilterBlockBuilder builder ( nullptr , table_options_ ) ;
BlockBasedFilterBlockBuilder builder ( nullptr , table_options_ ) ;
BlockContents block ( builder . Finish ( ) ) ;
Slice slice ( builder . Finish ( ) ) ;
ASSERT_EQ ( " \\ x00 \\ x00 \\ x00 \\ x00 \\ x0b " , EscapeString ( block . data ) ) ;
ASSERT_EQ ( " \\ x00 \\ x00 \\ x00 \\ x00 \\ x0b " , EscapeString ( slice ) ) ;
BlockBasedFilterBlockReader reader ( nullptr , table_options_ , true ,
std : : move ( block ) , nullptr ) ;
CachableEntry < BlockContents > block (
new BlockContents ( slice ) , nullptr /* cache */ , nullptr /* cache_handle */ ,
true /* own_value */ ) ;
BlockBasedFilterBlockReader reader ( table_ . get ( ) , std : : move ( block ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch (
ASSERT_TRUE ( reader . KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch (
ASSERT_TRUE ( reader . KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100000 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
}
}
TEST_F ( FilterBlockTest , SingleChunk ) {
TEST_F ( FilterBlockTest , SingleChunk ) {
@ -77,30 +108,46 @@ TEST_F(FilterBlockTest, SingleChunk) {
builder . StartBlock ( 300 ) ;
builder . StartBlock ( 300 ) ;
builder . Add ( " hello " ) ;
builder . Add ( " hello " ) ;
ASSERT_EQ ( 5 , builder . NumAdded ( ) ) ;
ASSERT_EQ ( 5 , builder . NumAdded ( ) ) ;
BlockContents block ( builder . Finish ( ) ) ;
Slice slice ( builder . Finish ( ) ) ;
BlockBasedFilterBlockReader reader ( nullptr , table_options_ , true ,
std : : move ( block ) , nullptr ) ;
CachableEntry < BlockContents > block (
ASSERT_TRUE ( reader . KeyMayMatch (
new BlockContents ( slice ) , nullptr /* cache */ , nullptr /* cache_handle */ ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
true /* own_value */ ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch (
BlockBasedFilterBlockReader reader ( table_ . get ( ) , std : : move ( block ) ) ;
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
ASSERT_TRUE ( reader . KeyMayMatch ( " foo " , /*prefix_extractor=*/ nullptr ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*block_offset=*/ 100 ,
ASSERT_TRUE ( reader . KeyMayMatch (
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*get_context=*/ nullptr ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch (
ASSERT_TRUE ( reader . KeyMayMatch ( " bar " , /*prefix_extractor=*/ nullptr ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
ASSERT_TRUE ( reader . KeyMayMatch (
/*get_context=*/ nullptr ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*lookup_context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch ( " box " , /*prefix_extractor=*/ nullptr ,
/*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
/*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch ( " hello " , /*prefix_extractor=*/ nullptr ,
/*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
/*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch ( " foo " , /*prefix_extractor=*/ nullptr ,
/*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
/*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" missing " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" missing " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" other " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" other " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
}
}
TEST_F ( FilterBlockTest , MultiChunk ) {
TEST_F ( FilterBlockTest , MultiChunk ) {
@ -123,93 +170,139 @@ TEST_F(FilterBlockTest, MultiChunk) {
builder . Add ( " box " ) ;
builder . Add ( " box " ) ;
builder . Add ( " hello " ) ;
builder . Add ( " hello " ) ;
BlockContents block ( builder . Finish ( ) ) ;
Slice slice ( builder . Finish ( ) ) ;
BlockBasedFilterBlockReader reader ( nullptr , table_options_ , true ,
std : : move ( block ) , nullptr ) ;
CachableEntry < BlockContents > block (
new BlockContents ( slice ) , nullptr /* cache */ , nullptr /* cache_handle */ ,
true /* own_value */ ) ;
BlockBasedFilterBlockReader reader ( table_ . get ( ) , std : : move ( block ) ) ;
// Check first filter
// Check first filter
ASSERT_TRUE ( reader . KeyMayMatch (
ASSERT_TRUE ( reader . KeyMayMatch ( " foo " , /*prefix_extractor=*/ nullptr ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
ASSERT_TRUE ( reader . KeyMayMatch (
/*get_context=*/ nullptr ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 2000 ,
/*lookup_context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch ( " bar " , /*prefix_extractor=*/ nullptr ,
/*block_offset=*/ 2000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
/*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
// Check second filter
// Check second filter
ASSERT_TRUE ( reader . KeyMayMatch (
ASSERT_TRUE ( reader . KeyMayMatch ( " box " , /*prefix_extractor=*/ nullptr ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
/*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
// Check third filter (empty)
// Check third filter (empty)
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
// Check last filter
// Check last filter
ASSERT_TRUE ( reader . KeyMayMatch (
ASSERT_TRUE ( reader . KeyMayMatch ( " box " , /*prefix_extractor=*/ nullptr ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
ASSERT_TRUE ( reader . KeyMayMatch (
/*get_context=*/ nullptr ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*lookup_context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader . KeyMayMatch ( " hello " , /*prefix_extractor=*/ nullptr ,
/*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr ,
/*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader . KeyMayMatch (
ASSERT_TRUE ( ! reader . KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
}
}
// Test for block based filter block
// Test for block based filter block
// use new interface in FilterPolicy to create filter builder/reader
// use new interface in FilterPolicy to create filter builder/reader
class BlockBasedFilterBlockTest : public testing : : Test {
class BlockBasedFilterBlockTest : public testing : : Test {
public :
public :
Options options_ ;
ImmutableCFOptions ioptions_ ;
EnvOptions env_options_ ;
BlockBasedTableOptions table_options_ ;
BlockBasedTableOptions table_options_ ;
InternalKeyComparator icomp_ ;
BlockBasedFilterBlockTest ( ) {
std : : unique_ptr < BlockBasedTable > table_ ;
BlockBasedFilterBlockTest ( )
: ioptions_ ( options_ ) ,
env_options_ ( options_ ) ,
icomp_ ( options_ . comparator ) {
table_options_ . no_block_cache = true ;
table_options_ . filter_policy . reset ( NewBloomFilterPolicy ( 10 ) ) ;
table_options_ . filter_policy . reset ( NewBloomFilterPolicy ( 10 ) ) ;
}
~ BlockBasedFilterBlockTest ( ) override { }
constexpr bool skip_filters = false ;
constexpr int level = 0 ;
constexpr bool immortal_table = false ;
table_ . reset ( new MockBlockBasedTable (
new BlockBasedTable : : Rep ( ioptions_ , env_options_ , table_options_ ,
icomp_ , skip_filters , level , immortal_table ) ) ) ;
}
} ;
} ;
TEST_F ( BlockBasedFilterBlockTest , BlockBasedEmptyBuilder ) {
TEST_F ( BlockBasedFilterBlockTest , BlockBasedEmptyBuilder ) {
FilterBlockBuilder * builder =
FilterBlockBuilder * builder =
new BlockBasedFilterBlockBuilder ( nullptr , table_options_ ) ;
new BlockBasedFilterBlockBuilder ( nullptr , table_options_ ) ;
BlockContents block ( builder - > Finish ( ) ) ;
Slice slice ( builder - > Finish ( ) ) ;
ASSERT_EQ ( " \\ x00 \\ x00 \\ x00 \\ x00 \\ x0b " , EscapeString ( block . data ) ) ;
ASSERT_EQ ( " \\ x00 \\ x00 \\ x00 \\ x00 \\ x0b " , EscapeString ( slice ) ) ;
FilterBlockReader * reader = new BlockBasedFilterBlockReader (
nullptr , table_options_ , true , std : : move ( block ) , nullptr ) ;
CachableEntry < BlockContents > block (
new BlockContents ( slice ) , nullptr /* cache */ , nullptr /* cache_handle */ ,
true /* own_value */ ) ;
FilterBlockReader * reader =
new BlockBasedFilterBlockReader ( table_ . get ( ) , std : : move ( block ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 10000 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 10000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
delete builder ;
delete builder ;
delete reader ;
delete reader ;
@ -226,30 +319,42 @@ TEST_F(BlockBasedFilterBlockTest, BlockBasedSingleChunk) {
builder - > Add ( " box " ) ;
builder - > Add ( " box " ) ;
builder - > StartBlock ( 300 ) ;
builder - > StartBlock ( 300 ) ;
builder - > Add ( " hello " ) ;
builder - > Add ( " hello " ) ;
BlockContents block ( builder - > Finish ( ) ) ;
Slice slice ( builder - > Finish ( ) ) ;
FilterBlockReader * reader = new BlockBasedFilterBlockReader (
nullptr , table_options_ , true , std : : move ( block ) , nullptr ) ;
CachableEntry < BlockContents > block (
new BlockContents ( slice ) , nullptr /* cache */ , nullptr /* cache_handle */ ,
true /* own_value */ ) ;
FilterBlockReader * reader =
new BlockBasedFilterBlockReader ( table_ . get ( ) , std : : move ( block ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" missing " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" missing " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" other " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
" other " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
delete builder ;
delete builder ;
delete reader ;
delete reader ;
@ -276,65 +381,86 @@ TEST_F(BlockBasedFilterBlockTest, BlockBasedMultiChunk) {
builder - > Add ( " box " ) ;
builder - > Add ( " box " ) ;
builder - > Add ( " hello " ) ;
builder - > Add ( " hello " ) ;
BlockContents block ( builder - > Finish ( ) ) ;
Slice slice ( builder - > Finish ( ) ) ;
FilterBlockReader * reader = new BlockBasedFilterBlockReader (
nullptr , table_options_ , true , std : : move ( block ) , nullptr ) ;
CachableEntry < BlockContents > block (
new BlockContents ( slice ) , nullptr /* cache */ , nullptr /* cache_handle */ ,
true /* own_value */ ) ;
FilterBlockReader * reader =
new BlockBasedFilterBlockReader ( table_ . get ( ) , std : : move ( block ) ) ;
// Check first filter
// Check first filter
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 2000 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 2000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ uint64_t { 0 } ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
// Check second filter
// Check second filter
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 3100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
// Check third filter (empty)
// Check third filter (empty)
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 4100 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
// Check last filter
// Check last filter
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
" box " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( reader - > KeyMayMatch (
ASSERT_TRUE ( reader - > KeyMayMatch (
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
" hello " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
" foo " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
ASSERT_TRUE ( ! reader - > KeyMayMatch (
ASSERT_TRUE ( ! reader - > KeyMayMatch (
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
" bar " , /*prefix_extractor=*/ nullptr , /*block_offset=*/ 9000 ,
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*context=*/ nullptr ) ) ;
/*no_io=*/ false , /*const_ikey_ptr=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_context=*/ nullptr ) ) ;
delete builder ;
delete builder ;
delete reader ;
delete reader ;