@ -83,12 +83,13 @@ Status ReadBlockFromFile(
bool do_uncompress , bool maybe_compressed , BlockType block_type ,
bool do_uncompress , bool maybe_compressed , BlockType block_type ,
const UncompressionDict & uncompression_dict ,
const UncompressionDict & uncompression_dict ,
const PersistentCacheOptions & cache_options , SequenceNumber global_seqno ,
const PersistentCacheOptions & cache_options , SequenceNumber global_seqno ,
size_t read_amp_bytes_per_bit , MemoryAllocator * memory_allocator ) {
size_t read_amp_bytes_per_bit , MemoryAllocator * memory_allocator ,
bool for_compaction = false ) {
BlockContents contents ;
BlockContents contents ;
BlockFetcher block_fetcher ( file , prefetch_buffer , footer , options , handle ,
BlockFetcher block_fetcher (
& contents , ioptions , do_uncompres s ,
file , prefetch_buffer , footer , options , handle , & contents , ioption s,
maybe_compressed , block_type , uncompression_dict ,
do_uncompress , maybe_compressed , block_type , uncompression_dict ,
cache_options , memory_allocator ) ;
cache_options , memory_allocator , nullptr , for_compaction ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
result - > reset ( new Block ( std : : move ( contents ) , global_seqno ,
result - > reset ( new Block ( std : : move ( contents ) , global_seqno ,
@ -2075,7 +2076,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
const ReadOptions & ro , const BlockHandle & handle , TBlockIter * input_iter ,
const ReadOptions & ro , const BlockHandle & handle , TBlockIter * input_iter ,
BlockType block_type , bool key_includes_seq , bool index_key_is_full ,
BlockType block_type , bool key_includes_seq , bool index_key_is_full ,
GetContext * get_context , BlockCacheLookupContext * lookup_context , Status s ,
GetContext * get_context , BlockCacheLookupContext * lookup_context , Status s ,
FilePrefetchBuffer * prefetch_buffer ) const {
FilePrefetchBuffer * prefetch_buffer , bool for_compaction ) const {
PERF_TIMER_GUARD ( new_table_block_iter_nanos ) ;
PERF_TIMER_GUARD ( new_table_block_iter_nanos ) ;
TBlockIter * iter = input_iter ! = nullptr ? input_iter : new TBlockIter ;
TBlockIter * iter = input_iter ! = nullptr ? input_iter : new TBlockIter ;
@ -2094,7 +2095,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
CachableEntry < Block > block ;
CachableEntry < Block > block ;
s = RetrieveBlock ( prefetch_buffer , ro , handle , uncompression_dict , & block ,
s = RetrieveBlock ( prefetch_buffer , ro , handle , uncompression_dict , & block ,
block_type , get_context , lookup_context ) ;
block_type , get_context , lookup_context , for_compaction ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
assert ( block . IsEmpty ( ) ) ;
assert ( block . IsEmpty ( ) ) ;
@ -2144,6 +2145,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
s = block_cache - > Insert ( unique_key , nullptr ,
s = block_cache - > Insert ( unique_key , nullptr ,
block . GetValue ( ) - > ApproximateMemoryUsage ( ) ,
block . GetValue ( ) - > ApproximateMemoryUsage ( ) ,
nullptr , & cache_handle ) ;
nullptr , & cache_handle ) ;
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
assert ( cache_handle ! = nullptr ) ;
assert ( cache_handle ! = nullptr ) ;
iter - > RegisterCleanup ( & ForceReleaseCachedEntry , block_cache ,
iter - > RegisterCleanup ( & ForceReleaseCachedEntry , block_cache ,
@ -2297,7 +2299,8 @@ Status BlockBasedTable::RetrieveBlock(
FilePrefetchBuffer * prefetch_buffer , const ReadOptions & ro ,
FilePrefetchBuffer * prefetch_buffer , const ReadOptions & ro ,
const BlockHandle & handle , const UncompressionDict & uncompression_dict ,
const BlockHandle & handle , const UncompressionDict & uncompression_dict ,
CachableEntry < Block > * block_entry , BlockType block_type ,
CachableEntry < Block > * block_entry , BlockType block_type ,
GetContext * get_context , BlockCacheLookupContext * lookup_context ) const {
GetContext * get_context , BlockCacheLookupContext * lookup_context ,
bool for_compaction ) const {
assert ( block_entry ) ;
assert ( block_entry ) ;
assert ( block_entry - > IsEmpty ( ) ) ;
assert ( block_entry - > IsEmpty ( ) ) ;
@ -2340,7 +2343,7 @@ Status BlockBasedTable::RetrieveBlock(
block_type = = BlockType : : kData
block_type = = BlockType : : kData
? rep_ - > table_options . read_amp_bytes_per_bit
? rep_ - > table_options . read_amp_bytes_per_bit
: 0 ,
: 0 ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
GetMemoryAllocator ( rep_ - > table_options ) , for_compaction ) ;
}
}
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -2714,13 +2717,18 @@ void BlockBasedTableIterator<TBlockIter, TValue>::InitDataBlock() {
rep - > file . get ( ) , read_options_ . readahead_size ,
rep - > file . get ( ) , read_options_ . readahead_size ,
read_options_ . readahead_size ) ) ;
read_options_ . readahead_size ) ) ;
}
}
} else if ( ! prefetch_buffer_ ) {
prefetch_buffer_ . reset (
new FilePrefetchBuffer ( rep - > file . get ( ) , compaction_readahead_size_ ,
compaction_readahead_size_ ) ) ;
}
}
Status s ;
Status s ;
table_ - > NewDataBlockIterator < TBlockIter > (
table_ - > NewDataBlockIterator < TBlockIter > (
read_options_ , data_block_handle , & block_iter_ , block_type_ ,
read_options_ , data_block_handle , & block_iter_ , block_type_ ,
key_includes_seq_ , index_key_is_full_ ,
key_includes_seq_ , index_key_is_full_ ,
/*get_context=*/ nullptr , & lookup_context_ , s , prefetch_buffer_ . get ( ) ) ;
/*get_context=*/ nullptr , & lookup_context_ , s , prefetch_buffer_ . get ( ) ,
for_compaction_ ) ;
block_iter_points_to_real_block_ = true ;
block_iter_points_to_real_block_ = true ;
}
}
}
}
@ -2806,7 +2814,8 @@ void BlockBasedTableIterator<TBlockIter, TValue>::CheckOutOfBound() {
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 ,
size_t compaction_readahead_size ) {
BlockCacheLookupContext lookup_context {
BlockCacheLookupContext lookup_context {
for_compaction ? BlockCacheLookupCaller : : kCompaction
for_compaction ? BlockCacheLookupCaller : : kCompaction
: BlockCacheLookupCaller : : kUserIterator } ;
: BlockCacheLookupCaller : : kUserIterator } ;
@ -2823,7 +2832,8 @@ InternalIterator* BlockBasedTable::NewIterator(
! 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 ,
need_upper_bound_check , prefix_extractor , BlockType : : kData ,
true /*key_includes_seq*/ , true /*index_key_is_full*/ , for_compaction ) ;
true /*key_includes_seq*/ , true /*index_key_is_full*/ , for_compaction ,
compaction_readahead_size ) ;
} else {
} else {
auto * mem =
auto * mem =
arena - > AllocateAligned ( sizeof ( BlockBasedTableIterator < DataBlockIter > ) ) ;
arena - > AllocateAligned ( sizeof ( BlockBasedTableIterator < DataBlockIter > ) ) ;
@ -2835,7 +2845,8 @@ InternalIterator* BlockBasedTable::NewIterator(
! 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 ,
need_upper_bound_check , prefix_extractor , BlockType : : kData ,
true /*key_includes_seq*/ , true /*index_key_is_full*/ , for_compaction ) ;
true /*key_includes_seq*/ , true /*index_key_is_full*/ , for_compaction ,
compaction_readahead_size ) ;
}
}
}
}