@ -2346,7 +2346,6 @@ void BlockBasedTableIterator<TBlockIter, TValue>::Seek(const Slice& target) {
block_iter_ . Seek ( target ) ;
block_iter_ . Seek ( target ) ;
FindKeyForward ( ) ;
FindKeyForward ( ) ;
CheckOutOfBound ( ) ;
assert (
assert (
! block_iter_ . Valid ( ) | |
! block_iter_ . Valid ( ) | |
( key_includes_seq_ & & icomp_ . Compare ( target , block_iter_ . key ( ) ) < = 0 ) | |
( key_includes_seq_ & & icomp_ . Compare ( target , block_iter_ . key ( ) ) < = 0 ) | |
@ -2410,7 +2409,6 @@ void BlockBasedTableIterator<TBlockIter, TValue>::SeekToFirst() {
InitDataBlock ( ) ;
InitDataBlock ( ) ;
block_iter_ . SeekToFirst ( ) ;
block_iter_ . SeekToFirst ( ) ;
FindKeyForward ( ) ;
FindKeyForward ( ) ;
CheckOutOfBound ( ) ;
}
}
template < class TBlockIter , typename TValue >
template < class TBlockIter , typename TValue >
@ -2493,24 +2491,18 @@ void BlockBasedTableIterator<TBlockIter, TValue>::InitDataBlock() {
template < class TBlockIter , typename TValue >
template < class TBlockIter , typename TValue >
void BlockBasedTableIterator < TBlockIter , TValue > : : FindKeyForward ( ) {
void BlockBasedTableIterator < TBlockIter , TValue > : : FindKeyForward ( ) {
assert ( ! is_out_of_bound_ ) ;
// TODO the while loop inherits from two-level-iterator. We don't know
// TODO the while loop inherits from two-level-iterator. We don't know
// whether a block can be empty so it can be replaced by an "if".
// whether a block can be empty so it can be replaced by an "if".
while ( ! block_iter_ . Valid ( ) ) {
while ( ! block_iter_ . Valid ( ) ) {
if ( ! block_iter_ . status ( ) . ok ( ) ) {
if ( ! block_iter_ . status ( ) . ok ( ) ) {
return ;
return ;
}
}
if ( read_options_ . iterate_upper_bound ! = nullptr & &
block_iter_points_to_real_block_ ) {
is_out_of_bound_ =
( user_comparator_ . Compare ( * read_options_ . iterate_upper_bound ,
ExtractUserKey ( index_iter_ - > key ( ) ) ) < = 0 ) ;
}
ResetDataIter ( ) ;
ResetDataIter ( ) ;
if ( is_out_of_bound_ ) {
// We used to check the current index key for upperbound.
// The next block is out of bound. No need to read it.
// It will only save a data reading for a small percentage of use cases,
TEST_SYNC_POINT_CALLBACK ( " BlockBasedTableIterator:out_of_bound " , nullptr ) ;
// so for code simplicity, we removed it. We can add it back if there is a
return ;
// significnat performance regression.
}
index_iter_ - > Next ( ) ;
index_iter_ - > Next ( ) ;
if ( index_iter_ - > Valid ( ) ) {
if ( index_iter_ - > Valid ( ) ) {
@ -2520,10 +2512,25 @@ void BlockBasedTableIterator<TBlockIter, TValue>::FindKeyForward() {
return ;
return ;
}
}
}
}
// Check upper bound on the current key
bool reached_upper_bound =
( read_options_ . iterate_upper_bound ! = nullptr & &
block_iter_points_to_real_block_ & & block_iter_ . Valid ( ) & &
user_comparator_ . Compare ( ExtractUserKey ( block_iter_ . key ( ) ) ,
* read_options_ . iterate_upper_bound ) > = 0 ) ;
TEST_SYNC_POINT_CALLBACK (
" BlockBasedTable::BlockEntryIteratorState::KeyReachedUpperBound " ,
& reached_upper_bound ) ;
if ( reached_upper_bound ) {
is_out_of_bound_ = true ;
return ;
}
}
}
template < class TBlockIter , typename TValue >
template < class TBlockIter , typename TValue >
void BlockBasedTableIterator < TBlockIter , TValue > : : FindKeyBackward ( ) {
void BlockBasedTableIterator < TBlockIter , TValue > : : FindKeyBackward ( ) {
assert ( ! is_out_of_bound_ ) ;
while ( ! block_iter_ . Valid ( ) ) {
while ( ! block_iter_ . Valid ( ) ) {
if ( ! block_iter_ . status ( ) . ok ( ) ) {
if ( ! block_iter_ . status ( ) . ok ( ) ) {
return ;
return ;
@ -2544,16 +2551,6 @@ void BlockBasedTableIterator<TBlockIter, TValue>::FindKeyBackward() {
// code simplicity.
// code simplicity.
}
}
template < class TBlockIter , typename TValue >
void BlockBasedTableIterator < TBlockIter , TValue > : : CheckOutOfBound ( ) {
if ( read_options_ . iterate_upper_bound ! = nullptr & &
block_iter_points_to_real_block_ & & block_iter_ . Valid ( ) ) {
is_out_of_bound_ =
user_comparator_ . Compare ( * read_options_ . iterate_upper_bound ,
ExtractUserKey ( block_iter_ . key ( ) ) ) < = 0 ;
}
}
InternalIterator * BlockBasedTable : : NewIterator (
InternalIterator * BlockBasedTable : : NewIterator (
const ReadOptions & read_options , const SliceTransform * prefix_extractor ,
const ReadOptions & read_options , const SliceTransform * prefix_extractor ,
Arena * arena , bool skip_filters , bool for_compaction ) {
Arena * arena , bool skip_filters , bool for_compaction ) {