@ -2019,8 +2019,9 @@ IndexBlockIter* BlockBasedTable::InitBlockIterator<IndexBlockIter>(
// If input_iter is null, new a iterator
// If input_iter is null, new a iterator
// If input_iter is not null, update this iter and return it
// If input_iter is not null, update this iter and return it
template < typename TBlockIter >
template < typename TBlockIter >
TBlockIter * BlockBasedTable : : NewDataBlockIterator (
TBlockIter * BlockBasedTable : : NewDataBlockIterator ( const ReadOptions & ro ,
const ReadOptions & ro , CachableEntry < Block > & block , TBlockIter * input_iter ,
CachableEntry < Block > & block ,
TBlockIter * input_iter ,
Status s ) const {
Status s ) const {
PERF_TIMER_GUARD ( new_table_block_iter_nanos ) ;
PERF_TIMER_GUARD ( new_table_block_iter_nanos ) ;
@ -2167,11 +2168,10 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache(
SequenceNumber seq_no = rep_ - > get_global_seqno ( block_type ) ;
SequenceNumber seq_no = rep_ - > get_global_seqno ( block_type ) ;
// If filling cache is allowed and a cache is configured, try to put the
// If filling cache is allowed and a cache is configured, try to put the
// block to the cache.
// block to the cache.
s = PutDataBlockToCache ( key , ckey , block_cache , block_cache_compressed ,
s = PutDataBlockToCache (
block_entry , contents ,
key , ckey , block_cache , block_cache_compressed , block_entry ,
raw_block_comp_type , uncompression_dict , seq_no ,
contents , raw_block_comp_type , uncompression_dict , seq_no ,
GetMemoryAllocator ( rep_ - > table_options ) ,
GetMemoryAllocator ( rep_ - > table_options ) , block_type , get_context ) ;
block_type , get_context ) ;
}
}
}
}
}
}
@ -2344,12 +2344,10 @@ void BlockBasedTable::RetrieveMultipleBlocks(
// BlockContents so it can free the memory
// BlockContents so it can free the memory
assert ( req . result . data ( ) = = req . scratch ) ;
assert ( req . result . data ( ) = = req . scratch ) ;
std : : unique_ptr < char [ ] > raw_block ( req . scratch ) ;
std : : unique_ptr < char [ ] > raw_block ( req . scratch ) ;
raw_block_contents = BlockContents ( std : : move ( raw_block ) ,
raw_block_contents = BlockContents ( std : : move ( raw_block ) , handle . size ( ) ) ;
handle . size ( ) ) ;
} else {
} else {
// We used the scratch buffer, so no need to free anything
// We used the scratch buffer, so no need to free anything
raw_block_contents = BlockContents ( Slice ( req . scratch ,
raw_block_contents = BlockContents ( Slice ( req . scratch , handle . size ( ) ) ) ;
handle . size ( ) ) ) ;
}
}
# ifndef NDEBUG
# ifndef NDEBUG
raw_block_contents . is_raw_block = true ;
raw_block_contents . is_raw_block = true ;
@ -2370,10 +2368,10 @@ void BlockBasedTable::RetrieveMultipleBlocks(
// MaybeReadBlockAndLoadToCache will insert into the block caches if
// MaybeReadBlockAndLoadToCache will insert into the block caches if
// necessary. Since we're passing the raw block contents, it will
// necessary. Since we're passing the raw block contents, it will
// avoid looking up the block cache
// avoid looking up the block cache
s = MaybeReadBlockAndLoadToCache ( nullptr , options , handle ,
s = MaybeReadBlockAndLoadToCache (
uncompression_dict , block_entry , BlockType : : kData ,
nullptr , options , handle , uncompression_dict , block_entry ,
mget_iter - > get_context , & lookup_data_block _context ,
BlockType : : kData , mget_iter - > get _context,
& raw_block_contents ) ;
& lookup_data_block_context , & raw_block_contents ) ;
} else {
} else {
CompressionType compression_type =
CompressionType compression_type =
raw_block_contents . get_compression_type ( ) ;
raw_block_contents . get_compression_type ( ) ;
@ -2382,23 +2380,24 @@ void BlockBasedTable::RetrieveMultipleBlocks(
UncompressionContext context ( compression_type ) ;
UncompressionContext context ( compression_type ) ;
UncompressionInfo info ( context , uncompression_dict , compression_type ) ;
UncompressionInfo info ( context , uncompression_dict , compression_type ) ;
s = UncompressBlockContents ( info , req . result . data ( ) , handle . size ( ) ,
s = UncompressBlockContents ( info , req . result . data ( ) , handle . size ( ) ,
& contents , footer . version ( ) , rep_ - > ioptions ,
& contents , footer . version ( ) ,
memory_allocator ) ;
rep_ - > ioptions , memory_allocator ) ;
} else {
} else {
if ( scratch ! = nullptr ) {
if ( scratch ! = nullptr ) {
// If we used the scratch buffer, then the contents need to be
// If we used the scratch buffer, then the contents need to be
// copied to heap
// copied to heap
Slice raw = Slice ( req . result . data ( ) , handle . size ( ) ) ;
Slice raw = Slice ( req . result . data ( ) , handle . size ( ) ) ;
contents = BlockContents ( CopyBufferToHeap (
contents = BlockContents (
GetMemoryAllocator ( rep_ - > table_options ) , raw ) ,
CopyBufferToHeap ( GetMemoryAllocator ( rep_ - > table_options ) , raw ) ,
handle . size ( ) ) ;
handle . size ( ) ) ;
} else {
} else {
contents = std : : move ( raw_block_contents ) ;
contents = std : : move ( raw_block_contents ) ;
}
}
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
( * results ) [ idx_in_batch ] . SetOwnedValue ( new Block ( std : : move ( contents ) ,
( * results ) [ idx_in_batch ] . SetOwnedValue (
global_seqno , read_amp_bytes_per_bit , ioptions . statistics ) ) ;
new Block ( std : : move ( contents ) , global_seqno ,
read_amp_bytes_per_bit , ioptions . statistics ) ) ;
}
}
}
}
}
}
@ -3036,7 +3035,8 @@ void BlockBasedTableIterator<TBlockIter, TValue>::CheckOutOfBound() {
}
}
template < class TBlockIter , typename TValue >
template < class TBlockIter , typename TValue >
void BlockBasedTableIterator < TBlockIter , TValue > : : CheckDataBlockWithinUpperBound ( ) {
void BlockBasedTableIterator < TBlockIter ,
TValue > : : CheckDataBlockWithinUpperBound ( ) {
if ( read_options_ . iterate_upper_bound ! = nullptr & &
if ( read_options_ . iterate_upper_bound ! = nullptr & &
block_iter_points_to_real_block_ ) {
block_iter_points_to_real_block_ ) {
data_block_within_upper_bound_ =
data_block_within_upper_bound_ =
@ -3047,7 +3047,8 @@ void BlockBasedTableIterator<TBlockIter, TValue>::CheckDataBlockWithinUpperBound
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 , TableReaderCaller caller , size_t compaction_readahead_size ) {
Arena * arena , bool skip_filters , TableReaderCaller caller ,
size_t compaction_readahead_size ) {
BlockCacheLookupContext lookup_context { caller } ;
BlockCacheLookupContext lookup_context { caller } ;
bool need_upper_bound_check =
bool need_upper_bound_check =
PrefixExtractorChanged ( rep_ - > table_properties . get ( ) , prefix_extractor ) ;
PrefixExtractorChanged ( rep_ - > table_properties . get ( ) , prefix_extractor ) ;
@ -3068,10 +3069,11 @@ InternalIterator* BlockBasedTable::NewIterator(
arena - > AllocateAligned ( sizeof ( BlockBasedTableIterator < DataBlockIter > ) ) ;
arena - > AllocateAligned ( sizeof ( BlockBasedTableIterator < DataBlockIter > ) ) ;
return new ( mem ) BlockBasedTableIterator < DataBlockIter > (
return new ( mem ) BlockBasedTableIterator < DataBlockIter > (
this , read_options , rep_ - > internal_comparator ,
this , read_options , rep_ - > internal_comparator ,
NewIndexIterator ( read_options , need_upper_bound_check & &
NewIndexIterator (
read_options ,
need_upper_bound_check & &
rep_ - > index_type = = BlockBasedTableOptions : : kHashSearch ,
rep_ - > index_type = = BlockBasedTableOptions : : kHashSearch ,
/*input_iter=*/ nullptr , /*get_context=*/ nullptr ,
/*input_iter=*/ nullptr , /*get_context=*/ nullptr , & lookup_context ) ,
& lookup_context ) ,
! skip_filters & & ! read_options . total_order_seek & &
! skip_filters & & ! read_options . total_order_seek & &
prefix_extractor ! = nullptr ,
prefix_extractor ! = nullptr ,
need_upper_bound_check , prefix_extractor , BlockType : : kData , caller ,
need_upper_bound_check , prefix_extractor , BlockType : : kData , caller ,