@@ -83,12 +83,13 @@ Status ReadBlockFromFile(
83
83
bool do_uncompress, bool maybe_compressed, BlockType block_type,
84
84
const UncompressionDict& uncompression_dict,
85
85
const PersistentCacheOptions& cache_options, SequenceNumber global_seqno,
86
- size_t read_amp_bytes_per_bit, MemoryAllocator* memory_allocator) {
86
+ size_t read_amp_bytes_per_bit, MemoryAllocator* memory_allocator,
87
+ bool for_compaction = false ) {
87
88
BlockContents contents;
88
- BlockFetcher block_fetcher (file, prefetch_buffer, footer, options, handle,
89
- &contents, ioptions, do_uncompress ,
90
- maybe_compressed, block_type, uncompression_dict,
91
- cache_options, memory_allocator);
89
+ BlockFetcher block_fetcher (
90
+ file, prefetch_buffer, footer, options, handle, &contents, ioptions,
91
+ do_uncompress, maybe_compressed, block_type, uncompression_dict,
92
+ cache_options, memory_allocator, nullptr , for_compaction );
92
93
Status s = block_fetcher.ReadBlockContents ();
93
94
if (s.ok ()) {
94
95
result->reset (new Block (std::move (contents), global_seqno,
@@ -1906,7 +1907,7 @@ CachableEntry<FilterBlockReader> BlockBasedTable::GetFilter(
1906
1907
1907
1908
if (!is_a_filter_partition && rep_->filter_entry .IsCached ()) {
1908
1909
return {rep_->filter_entry .GetValue (), /* cache=*/ nullptr ,
1909
- /* cache_handle=*/ nullptr , /* own_value=*/ false };
1910
+ /* cache_handle=*/ nullptr , /* own_value=*/ false };
1910
1911
}
1911
1912
1912
1913
PERF_TIMER_GUARD (read_filter_block_nanos);
@@ -2075,7 +2076,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
2075
2076
const ReadOptions& ro, const BlockHandle& handle, TBlockIter* input_iter,
2076
2077
BlockType block_type, bool key_includes_seq, bool index_key_is_full,
2077
2078
GetContext* get_context, BlockCacheLookupContext* lookup_context, Status s,
2078
- FilePrefetchBuffer* prefetch_buffer) const {
2079
+ FilePrefetchBuffer* prefetch_buffer, bool for_compaction ) const {
2079
2080
PERF_TIMER_GUARD (new_table_block_iter_nanos);
2080
2081
2081
2082
TBlockIter* iter = input_iter != nullptr ? input_iter : new TBlockIter;
@@ -2094,7 +2095,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
2094
2095
2095
2096
CachableEntry<Block> block;
2096
2097
s = RetrieveBlock (prefetch_buffer, ro, handle, uncompression_dict, &block,
2097
- block_type, get_context, lookup_context);
2098
+ block_type, get_context, lookup_context, for_compaction );
2098
2099
2099
2100
if (!s.ok ()) {
2100
2101
assert (block.IsEmpty ());
@@ -2144,6 +2145,7 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
2144
2145
s = block_cache->Insert (unique_key, nullptr ,
2145
2146
block.GetValue ()->ApproximateMemoryUsage (),
2146
2147
nullptr , &cache_handle);
2148
+
2147
2149
if (s.ok ()) {
2148
2150
assert (cache_handle != nullptr );
2149
2151
iter->RegisterCleanup (&ForceReleaseCachedEntry, block_cache,
@@ -2297,7 +2299,8 @@ Status BlockBasedTable::RetrieveBlock(
2297
2299
FilePrefetchBuffer* prefetch_buffer, const ReadOptions& ro,
2298
2300
const BlockHandle& handle, const UncompressionDict& uncompression_dict,
2299
2301
CachableEntry<Block>* block_entry, BlockType block_type,
2300
- GetContext* get_context, BlockCacheLookupContext* lookup_context) const {
2302
+ GetContext* get_context, BlockCacheLookupContext* lookup_context,
2303
+ bool for_compaction) const {
2301
2304
assert (block_entry);
2302
2305
assert (block_entry->IsEmpty ());
2303
2306
@@ -2340,7 +2343,7 @@ Status BlockBasedTable::RetrieveBlock(
2340
2343
block_type == BlockType::kData
2341
2344
? rep_->table_options .read_amp_bytes_per_bit
2342
2345
: 0 ,
2343
- GetMemoryAllocator (rep_->table_options ));
2346
+ GetMemoryAllocator (rep_->table_options ), for_compaction );
2344
2347
}
2345
2348
2346
2349
if (!s.ok ()) {
@@ -2714,13 +2717,18 @@ void BlockBasedTableIterator<TBlockIter, TValue>::InitDataBlock() {
2714
2717
rep->file .get (), read_options_.readahead_size ,
2715
2718
read_options_.readahead_size ));
2716
2719
}
2720
+ } else if (!prefetch_buffer_) {
2721
+ prefetch_buffer_.reset (
2722
+ new FilePrefetchBuffer (rep->file .get (), compaction_readahead_size_,
2723
+ compaction_readahead_size_));
2717
2724
}
2718
2725
2719
2726
Status s;
2720
2727
table_->NewDataBlockIterator <TBlockIter>(
2721
2728
read_options_, data_block_handle, &block_iter_, block_type_,
2722
2729
key_includes_seq_, index_key_is_full_,
2723
- /* get_context=*/ nullptr , &lookup_context_, s, prefetch_buffer_.get ());
2730
+ /* get_context=*/ nullptr , &lookup_context_, s, prefetch_buffer_.get (),
2731
+ for_compaction_);
2724
2732
block_iter_points_to_real_block_ = true ;
2725
2733
}
2726
2734
}
@@ -2806,7 +2814,8 @@ void BlockBasedTableIterator<TBlockIter, TValue>::CheckOutOfBound() {
2806
2814
2807
2815
InternalIterator* BlockBasedTable::NewIterator (
2808
2816
const ReadOptions& read_options, const SliceTransform* prefix_extractor,
2809
- Arena* arena, bool skip_filters, bool for_compaction) {
2817
+ Arena* arena, bool skip_filters, bool for_compaction,
2818
+ size_t compaction_readahead_size) {
2810
2819
BlockCacheLookupContext lookup_context{
2811
2820
for_compaction ? BlockCacheLookupCaller::kCompaction
2812
2821
: BlockCacheLookupCaller::kUserIterator };
@@ -2823,7 +2832,8 @@ InternalIterator* BlockBasedTable::NewIterator(
2823
2832
!skip_filters && !read_options.total_order_seek &&
2824
2833
prefix_extractor != nullptr ,
2825
2834
need_upper_bound_check, prefix_extractor, BlockType::kData ,
2826
- true /* key_includes_seq*/ , true /* index_key_is_full*/ , for_compaction);
2835
+ true /* key_includes_seq*/ , true /* index_key_is_full*/ , for_compaction,
2836
+ compaction_readahead_size);
2827
2837
} else {
2828
2838
auto * mem =
2829
2839
arena->AllocateAligned (sizeof (BlockBasedTableIterator<DataBlockIter>));
@@ -2835,7 +2845,8 @@ InternalIterator* BlockBasedTable::NewIterator(
2835
2845
!skip_filters && !read_options.total_order_seek &&
2836
2846
prefix_extractor != nullptr ,
2837
2847
need_upper_bound_check, prefix_extractor, BlockType::kData ,
2838
- true /* key_includes_seq*/ , true /* index_key_is_full*/ , for_compaction);
2848
+ true /* key_includes_seq*/ , true /* index_key_is_full*/ , for_compaction,
2849
+ compaction_readahead_size);
2839
2850
}
2840
2851
}
2841
2852
0 commit comments