@ -161,7 +161,8 @@ class PartitionIndexReader : public IndexReader, public Cleanable {
static Status Create ( BlockBasedTable * table , RandomAccessFileReader * file ,
const Footer & footer , const BlockHandle & index_handle ,
const ImmutableCFOptions & ioptions ,
const Comparator * comparator , IndexReader * * index_reader ,
const InternalKeyComparator * icomparator ,
IndexReader * * index_reader ,
const PersistentCacheOptions & cache_options ,
const int level ) {
std : : unique_ptr < Block > index_block ;
@ -172,7 +173,7 @@ class PartitionIndexReader : public IndexReader, public Cleanable {
if ( s . ok ( ) ) {
* index_reader =
new PartitionIndexReader ( table , comparator , std : : move ( index_block ) ,
new PartitionIndexReader ( table , i comparator, std : : move ( index_block ) ,
ioptions . statistics , level ) ;
}
@ -196,8 +197,9 @@ class PartitionIndexReader : public IndexReader, public Cleanable {
}
return NewTwoLevelIterator (
new BlockBasedTable : : BlockEntryIteratorState (
table_ , ReadOptions ( ) , skip_filters , is_index , block_cache_cleaner ) ,
index_block_ - > NewIterator ( comparator_ , nullptr , true ) ) ;
table_ , ReadOptions ( ) , icomparator_ , skip_filters , is_index ,
block_cache_cleaner ) ,
index_block_ - > NewIterator ( icomparator_ , nullptr , true ) ) ;
// TODO(myabandeh): Update TwoLevelIterator to be able to make use of
// on-stack
// BlockIter while the state is on heap
@ -214,10 +216,11 @@ class PartitionIndexReader : public IndexReader, public Cleanable {
}
private :
PartitionIndexReader ( BlockBasedTable * table , const Comparator * comparator ,
PartitionIndexReader ( BlockBasedTable * table ,
const InternalKeyComparator * icomparator ,
std : : unique_ptr < Block > & & index_block , Statistics * stats ,
const int level )
: IndexReader ( comparator , stats ) ,
: IndexReader ( i comparator, stats ) ,
table_ ( table ) ,
index_block_ ( std : : move ( index_block ) ) ,
level_ ( level ) {
@ -239,8 +242,9 @@ class BinarySearchIndexReader : public IndexReader {
// unmodified.
static Status Create ( RandomAccessFileReader * file , const Footer & footer ,
const BlockHandle & index_handle ,
const ImmutableCFOptions & ioptions ,
const Comparator * comparator , IndexReader * * index_reader ,
const ImmutableCFOptions & ioptions ,
const InternalKeyComparator * icomparator ,
IndexReader * * index_reader ,
const PersistentCacheOptions & cache_options ) {
std : : unique_ptr < Block > index_block ;
auto s = ReadBlockFromFile (
@ -250,7 +254,7 @@ class BinarySearchIndexReader : public IndexReader {
if ( s . ok ( ) ) {
* index_reader = new BinarySearchIndexReader (
comparator , std : : move ( index_block ) , ioptions . statistics ) ;
i comparator, std : : move ( index_block ) , ioptions . statistics ) ;
}
return s ;
@ -258,7 +262,7 @@ class BinarySearchIndexReader : public IndexReader {
virtual InternalIterator * NewIterator ( BlockIter * iter = nullptr ,
bool dont_care = true ) override {
return index_block_ - > NewIterator ( comparator_ , iter , true ) ;
return index_block_ - > NewIterator ( i comparator_, iter , true ) ;
}
virtual size_t size ( ) const override { return index_block_ - > size ( ) ; }
@ -272,10 +276,10 @@ class BinarySearchIndexReader : public IndexReader {
}
private :
BinarySearchIndexReader ( const Comparator * comparator ,
BinarySearchIndexReader ( const InternalKey Comparator* i comparator,
std : : unique_ptr < Block > & & index_block ,
Statistics * stats )
: IndexReader ( comparator , stats ) , index_block_ ( std : : move ( index_block ) ) {
: IndexReader ( i comparator, stats ) , index_block_ ( std : : move ( index_block ) ) {
assert ( index_block_ ! = nullptr ) ;
}
std : : unique_ptr < Block > index_block_ ;
@ -288,7 +292,7 @@ class HashIndexReader : public IndexReader {
static Status Create ( const SliceTransform * hash_key_extractor ,
const Footer & footer , RandomAccessFileReader * file ,
const ImmutableCFOptions & ioptions ,
const Comparator * comparator ,
const InternalKey Comparator* i comparator,
const BlockHandle & index_handle ,
InternalIterator * meta_index_iter ,
IndexReader * * index_reader ,
@ -309,7 +313,7 @@ class HashIndexReader : public IndexReader {
// So, Create will succeed regardless, from this point on.
auto new_index_reader =
new HashIndexReader ( comparator , std : : move ( index_block ) ,
new HashIndexReader ( i comparator, std : : move ( index_block ) ,
ioptions . statistics ) ;
* index_reader = new_index_reader ;
@ -361,7 +365,7 @@ class HashIndexReader : public IndexReader {
virtual InternalIterator * NewIterator ( BlockIter * iter = nullptr ,
bool total_order_seek = true ) override {
return index_block_ - > NewIterator ( comparator_ , iter , total_order_seek ) ;
return index_block_ - > NewIterator ( i comparator_, iter , total_order_seek ) ;
}
virtual size_t size ( ) const override { return index_block_ - > size ( ) ; }
@ -376,9 +380,9 @@ class HashIndexReader : public IndexReader {
}
private :
HashIndexReader ( const Comparator * comparator ,
HashIndexReader ( const InternalKey Comparator* i comparator,
std : : unique_ptr < Block > & & index_block , Statistics * stats )
: IndexReader ( comparator , stats ) , index_block_ ( std : : move ( index_block ) ) {
: IndexReader ( i comparator, stats ) , index_block_ ( std : : move ( index_block ) ) {
assert ( index_block_ ! = nullptr ) ;
}
@ -1381,11 +1385,13 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache(
}
BlockBasedTable : : BlockEntryIteratorState : : BlockEntryIteratorState (
BlockBasedTable * table , const ReadOptions & read_options , bool skip_filters ,
bool is_index , Cleanable * block_cache_cleaner )
BlockBasedTable * table , const ReadOptions & read_options ,
const InternalKeyComparator * icomparator , bool skip_filters , bool is_index ,
Cleanable * block_cache_cleaner )
: TwoLevelIteratorState ( table - > rep_ - > ioptions . prefix_extractor ! = nullptr ) ,
table_ ( table ) ,
read_options_ ( read_options ) ,
icomparator_ ( icomparator ) ,
skip_filters_ ( skip_filters ) ,
is_index_ ( is_index ) ,
block_cache_cleaner_ ( block_cache_cleaner ) { }
@ -1424,6 +1430,19 @@ bool BlockBasedTable::BlockEntryIteratorState::PrefixMayMatch(
return table_ - > PrefixMayMatch ( internal_key ) ;
}
bool BlockBasedTable : : BlockEntryIteratorState : : KeyReachedUpperBound (
const Slice & internal_key ) {
bool reached_upper_bound = read_options_ . iterate_upper_bound ! = nullptr & &
icomparator_ ! = nullptr & &
icomparator_ - > user_comparator ( ) - > Compare (
ExtractUserKey ( internal_key ) ,
* read_options_ . iterate_upper_bound ) > = 0 ;
TEST_SYNC_POINT_CALLBACK (
" BlockBasedTable::BlockEntryIteratorState::KeyReachedUpperBound " ,
& reached_upper_bound ) ;
return reached_upper_bound ;
}
// This will be broken if the user specifies an unusual implementation
// of Options.comparator, or if the user specifies an unusual
// definition of prefixes in BlockBasedTableOptions.filter_policy.
@ -1526,11 +1545,11 @@ bool BlockBasedTable::PrefixMayMatch(const Slice& internal_key) {
return may_match ;
}
InternalIterator * BlockBasedTable : : NewIterator ( const ReadOptions & read_options ,
Arena * arena ,
bool skip_filters ) {
InternalIterator * BlockBasedTable : : NewIterator (
const ReadOptions & read_options , Arena * arena ,
const InternalKeyComparator * icomp , bool skip_filters ) {
return NewTwoLevelIterator (
new BlockEntryIteratorState ( this , read_options , skip_filters ) ,
new BlockEntryIteratorState ( this , read_options , icomp , skip_filters ) ,
NewIndexIterator ( read_options ) , arena ) ;
}
@ -1782,7 +1801,7 @@ Status BlockBasedTable::CreateIndexReader(
}
auto file = rep_ - > file . get ( ) ;
auto comparator = & rep_ - > internal_comparator ;
const InternalKeyComparator * i comparator = & rep_ - > internal_comparator ;
const Footer & footer = rep_ - > footer ;
if ( index_type_on_file = = BlockBasedTableOptions : : kHashSearch & &
rep_ - > ioptions . prefix_extractor = = nullptr ) {
@ -1796,12 +1815,12 @@ Status BlockBasedTable::CreateIndexReader(
switch ( index_type_on_file ) {
case BlockBasedTableOptions : : kTwoLevelIndexSearch : {
return PartitionIndexReader : : Create (
this , file , footer , footer . index_handle ( ) , rep_ - > ioptions , comparator ,
index_reader , rep_ - > persistent_cache_options , level ) ;
this , file , footer , footer . index_handle ( ) , rep_ - > ioptions ,
icomparator , i ndex_reader , rep_ - > persistent_cache_options , level ) ;
}
case BlockBasedTableOptions : : kBinarySearch : {
return BinarySearchIndexReader : : Create (
file , footer , footer . index_handle ( ) , rep_ - > ioptions , comparator ,
file , footer , footer . index_handle ( ) , rep_ - > ioptions , i comparator,
index_reader , rep_ - > persistent_cache_options ) ;
}
case BlockBasedTableOptions : : kHashSearch : {
@ -1817,7 +1836,7 @@ Status BlockBasedTable::CreateIndexReader(
" Unable to read the metaindex block. "
" Fall back to binary search index. " ) ;
return BinarySearchIndexReader : : Create (
file , footer , footer . index_handle ( ) , rep_ - > ioptions , comparator ,
file , footer , footer . index_handle ( ) , rep_ - > ioptions , i comparator,
index_reader , rep_ - > persistent_cache_options ) ;
}
meta_index_iter = meta_iter_guard . get ( ) ;
@ -1825,7 +1844,7 @@ Status BlockBasedTable::CreateIndexReader(
return HashIndexReader : : Create (
rep_ - > internal_prefix_transform . get ( ) , footer , file , rep_ - > ioptions ,
comparator , footer . index_handle ( ) , meta_index_iter , index_reader ,
i comparator, footer . index_handle ( ) , meta_index_iter , index_reader ,
rep_ - > hash_index_allow_collision , rep_ - > persistent_cache_options ) ;
}
default : {