@ -62,6 +62,10 @@ extern const std::string kHashIndexPrefixesMetadataBlock;
typedef BlockBasedTable : : IndexReader IndexReader ;
typedef BlockBasedTable : : IndexReader IndexReader ;
// Found that 256 KB readahead size provides the best performance, based on
// experiments, for auto readahead. Experiment data is in PR #3282.
const size_t BlockBasedTable : : kMaxAutoReadaheadSize = 256 * 1024 ;
BlockBasedTable : : ~ BlockBasedTable ( ) {
BlockBasedTable : : ~ BlockBasedTable ( ) {
delete rep_ ;
delete rep_ ;
}
}
@ -2854,13 +2858,6 @@ void BlockBasedTableIterator<TBlockIter, TValue>::Prev() {
FindKeyBackward ( ) ;
FindKeyBackward ( ) ;
}
}
// Found that 256 KB readahead size provides the best performance, based on
// experiments, for auto readahead. Experiment data is in PR #3282.
template < class TBlockIter , typename TValue >
const size_t
BlockBasedTableIterator < TBlockIter , TValue > : : kMaxAutoReadaheadSize =
256 * 1024 ;
template < class TBlockIter , typename TValue >
template < class TBlockIter , typename TValue >
void BlockBasedTableIterator < TBlockIter , TValue > : : InitDataBlock ( ) {
void BlockBasedTableIterator < TBlockIter , TValue > : : InitDataBlock ( ) {
BlockHandle data_block_handle = index_iter_ - > value ( ) . handle ;
BlockHandle data_block_handle = index_iter_ - > value ( ) . handle ;
@ -2883,7 +2880,8 @@ void BlockBasedTableIterator<TBlockIter, TValue>::InitDataBlock() {
if ( read_options_ . readahead_size = = 0 ) {
if ( read_options_ . readahead_size = = 0 ) {
// Implicit auto readahead
// Implicit auto readahead
num_file_reads_ + + ;
num_file_reads_ + + ;
if ( num_file_reads_ > kMinNumFileReadsToStartAutoReadahead ) {
if ( num_file_reads_ >
BlockBasedTable : : kMinNumFileReadsToStartAutoReadahead ) {
if ( ! rep - > file - > use_direct_io ( ) & &
if ( ! rep - > file - > use_direct_io ( ) & &
( data_block_handle . offset ( ) +
( data_block_handle . offset ( ) +
static_cast < size_t > ( data_block_handle . size ( ) ) +
static_cast < size_t > ( data_block_handle . size ( ) ) +
@ -2897,14 +2895,14 @@ void BlockBasedTableIterator<TBlockIter, TValue>::InitDataBlock() {
readahead_size_ ) ;
readahead_size_ ) ;
// Keep exponentially increasing readahead size until
// Keep exponentially increasing readahead size until
// kMaxAutoReadaheadSize.
// kMaxAutoReadaheadSize.
readahead_size_ =
readahead_size_ = std : : min ( BlockBasedTable : : kMaxAutoReadaheadSize ,
std : : min ( kMaxAutoReadaheadSize , readahead_size_ * 2 ) ;
readahead_size_ * 2 ) ;
} else if ( rep - > file - > use_direct_io ( ) & & ! prefetch_buffer_ ) {
} else if ( rep - > file - > use_direct_io ( ) & & ! prefetch_buffer_ ) {
// Direct I/O
// Direct I/O
// Let FilePrefetchBuffer take care of the readahead.
// Let FilePrefetchBuffer take care of the readahead.
prefetch_buffer_ . reset (
prefetch_buffer_ . reset ( new FilePrefetchBuffer (
new FilePrefetchBuffer ( rep - > file . get ( ) , kInitAutoReadaheadSize ,
rep - > file . get ( ) , BlockBasedTable : : kInitAutoReadaheadSize ,
kMaxAutoReadaheadSize ) ) ;
BlockBasedTable : : kMaxAutoReadaheadSize ) ) ;
}
}
}
}
} else if ( ! prefetch_buffer_ ) {
} else if ( ! prefetch_buffer_ ) {
@ -3707,7 +3705,8 @@ Status BlockBasedTable::Prefetch(const Slice* const begin,
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
Status BlockBasedTable : : VerifyChecksum ( TableReaderCaller caller ) {
Status BlockBasedTable : : VerifyChecksum ( const ReadOptions & read_options ,
TableReaderCaller caller ) {
Status s ;
Status s ;
// Check Meta blocks
// Check Meta blocks
std : : unique_ptr < Block > meta ;
std : : unique_ptr < Block > meta ;
@ -3725,7 +3724,7 @@ Status BlockBasedTable::VerifyChecksum(TableReaderCaller caller) {
IndexBlockIter iiter_on_stack ;
IndexBlockIter iiter_on_stack ;
BlockCacheLookupContext context { caller } ;
BlockCacheLookupContext context { caller } ;
InternalIteratorBase < IndexValue > * iiter = NewIndexIterator (
InternalIteratorBase < IndexValue > * iiter = NewIndexIterator (
ReadOptions ( ) , /*need_upper_bound_chec k=*/false , & iiter_on_stack ,
read_options , /*disable_prefix_see k=*/false , & iiter_on_stack ,
/*get_context=*/ nullptr , & context ) ;
/*get_context=*/ nullptr , & context ) ;
std : : unique_ptr < InternalIteratorBase < IndexValue > > iiter_unique_ptr ;
std : : unique_ptr < InternalIteratorBase < IndexValue > > iiter_unique_ptr ;
if ( iiter ! = & iiter_on_stack ) {
if ( iiter ! = & iiter_on_stack ) {
@ -3735,13 +3734,22 @@ Status BlockBasedTable::VerifyChecksum(TableReaderCaller caller) {
// error opening index iterator
// error opening index iterator
return iiter - > status ( ) ;
return iiter - > status ( ) ;
}
}
s = VerifyChecksumInBlocks ( iiter ) ;
s = VerifyChecksumInBlocks ( read_options , iiter ) ;
return s ;
return s ;
}
}
Status BlockBasedTable : : VerifyChecksumInBlocks (
Status BlockBasedTable : : VerifyChecksumInBlocks (
const ReadOptions & read_options ,
InternalIteratorBase < IndexValue > * index_iter ) {
InternalIteratorBase < IndexValue > * index_iter ) {
Status s ;
Status s ;
// We are scanning the whole file, so no need to do exponential
// increasing of the buffer size.
size_t readahead_size = ( read_options . readahead_size ! = 0 )
? read_options . readahead_size
: kMaxAutoReadaheadSize ;
FilePrefetchBuffer prefetch_buffer ( rep_ - > file . get ( ) , readahead_size ,
readahead_size ) ;
for ( index_iter - > SeekToFirst ( ) ; index_iter - > Valid ( ) ; index_iter - > Next ( ) ) {
for ( index_iter - > SeekToFirst ( ) ; index_iter - > Valid ( ) ; index_iter - > Next ( ) ) {
s = index_iter - > status ( ) ;
s = index_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -3750,9 +3758,9 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
BlockHandle handle = index_iter - > value ( ) . handle ;
BlockHandle handle = index_iter - > value ( ) . handle ;
BlockContents contents ;
BlockContents contents ;
BlockFetcher block_fetcher (
BlockFetcher block_fetcher (
rep_ - > file . get ( ) , nullptr /* prefetch buffer */ , rep_ - > footer ,
rep_ - > file . get ( ) , & prefetch_buffer , rep_ - > footer , ReadOptions ( ) , handle ,
ReadOptions ( ) , handle , & contents , rep_ - > ioptions ,
& contents , rep_ - > ioptions , false /* decompress */ ,
false /* decompress */ , false /* maybe_compressed*/ , BlockType : : kData ,
false /*maybe_compressed*/ , BlockType : : kData ,
UncompressionDict : : GetEmptyDict ( ) , rep_ - > persistent_cache_options ) ;
UncompressionDict : : GetEmptyDict ( ) , rep_ - > persistent_cache_options ) ;
s = block_fetcher . ReadBlockContents ( ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {