@ -83,12 +83,13 @@ Status ReadBlockFromFile(
bool do_uncompress , bool maybe_compressed , BlockType block_type ,
const UncompressionDict & uncompression_dict ,
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 ;
BlockFetcher block_fetcher ( file , prefetch_buffer , footer , options , handle ,
& contents , ioptions , do_uncompres s ,
maybe_compressed , block_type , uncompression_dict ,
cache_options , memory_allocator ) ;
BlockFetcher block_fetcher (
file , prefetch_buffer , footer , options , handle , & contents , ioption s,
do_uncompress , maybe_compressed , block_type , uncompression_dict ,
cache_options , memory_allocator , nullptr , for_compaction ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
if ( s . ok ( ) ) {
result - > reset ( new Block ( std : : move ( contents ) , global_seqno ,
@ -1906,7 +1907,7 @@ CachableEntry<FilterBlockReader> BlockBasedTable::GetFilter(
if ( ! is_a_filter_partition & & rep_ - > filter_entry . IsCached ( ) ) {
return { rep_ - > filter_entry . GetValue ( ) , /*cache=*/ nullptr ,
/*cache_handle=*/ nullptr , /*own_value=*/ false } ;
/*cache_handle=*/ nullptr , /*own_value=*/ false } ;
}
PERF_TIMER_GUARD ( read_filter_block_nanos ) ;
@ -2075,7 +2076,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
const ReadOptions & ro , const BlockHandle & handle , TBlockIter * input_iter ,
BlockType block_type , bool key_includes_seq , bool index_key_is_full ,
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 ) ;
TBlockIter * iter = input_iter ! = nullptr ? input_iter : new TBlockIter ;
@ -2094,7 +2095,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
CachableEntry < Block > 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 ( ) ) {
assert ( block . IsEmpty ( ) ) ;
@ -2144,6 +2145,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
s = block_cache - > Insert ( unique_key , nullptr ,
block . GetValue ( ) - > ApproximateMemoryUsage ( ) ,
nullptr , & cache_handle ) ;
if ( s . ok ( ) ) {
assert ( cache_handle ! = nullptr ) ;
iter - > RegisterCleanup ( & ForceReleaseCachedEntry , block_cache ,
@ -2297,7 +2299,8 @@ Status BlockBasedTable::RetrieveBlock(
FilePrefetchBuffer * prefetch_buffer , const ReadOptions & ro ,
const BlockHandle & handle , const UncompressionDict & uncompression_dict ,
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 - > IsEmpty ( ) ) ;
@ -2340,7 +2343,7 @@ Status BlockBasedTable::RetrieveBlock(
block_type = = BlockType : : kData
? rep_ - > table_options . read_amp_bytes_per_bit
: 0 ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
GetMemoryAllocator ( rep_ - > table_options ) , for_compaction ) ;
}
if ( ! s . ok ( ) ) {
@ -2714,13 +2717,18 @@ void BlockBasedTableIterator<TBlockIter, TValue>::InitDataBlock() {
rep - > file . get ( ) , 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 ;
table_ - > NewDataBlockIterator < TBlockIter > (
read_options_ , data_block_handle , & block_iter_ , block_type_ ,
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 ;
}
}
@ -2806,7 +2814,8 @@ void BlockBasedTableIterator<TBlockIter, TValue>::CheckOutOfBound() {
InternalIterator * BlockBasedTable : : NewIterator (
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 {
for_compaction ? BlockCacheLookupCaller : : kCompaction
: BlockCacheLookupCaller : : kUserIterator } ;
@ -2823,7 +2832,8 @@ InternalIterator* BlockBasedTable::NewIterator(
! skip_filters & & ! read_options . total_order_seek & &
prefix_extractor ! = nullptr ,
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 {
auto * mem =
arena - > AllocateAligned ( sizeof ( BlockBasedTableIterator < DataBlockIter > ) ) ;
@ -2835,7 +2845,8 @@ InternalIterator* BlockBasedTable::NewIterator(
! skip_filters & & ! read_options . total_order_seek & &
prefix_extractor ! = nullptr ,
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 ) ;
}
}