@ -169,13 +169,23 @@ Status TableCache::FindTable(const EnvOptions& env_options,
InternalIterator * TableCache : : NewIterator (
InternalIterator * TableCache : : NewIterator (
const ReadOptions & options , const EnvOptions & env_options ,
const ReadOptions & options , const EnvOptions & env_options ,
const InternalKeyComparator & icomparator , const FileDescriptor & fd ,
const InternalKeyComparator & icomparator , const FileDescriptor & fd ,
TableReader * * table_reader_ptr , HistogramImpl * file_read_hist ,
RangeDelAggregator * range_del_agg , TableReader * * table_reader_ptr ,
bool for_compaction , Arena * arena , bool skip_filters , int level ,
HistogramImpl * file_read_hist , bool for_compaction , Arena * arena ,
RangeDelAggregator * range_del_agg /* = nullptr */ ,
bool skip_filters , int level ) {
bool is_range_del_only /* = false */ ) {
assert ( ! is_range_del_only | | range_del_agg ! = nullptr ) ;
PERF_TIMER_GUARD ( new_table_iterator_nanos ) ;
PERF_TIMER_GUARD ( new_table_iterator_nanos ) ;
if ( range_del_agg ! = nullptr & & ! options . ignore_range_deletions ) {
std : : unique_ptr < InternalIterator > range_del_iter ( NewRangeDeletionIterator (
options , icomparator , fd , file_read_hist , skip_filters , level ) ) ;
Status s = range_del_iter - > status ( ) ;
if ( s . ok ( ) ) {
s = range_del_agg - > AddTombstones ( std : : move ( range_del_iter ) ) ;
}
if ( ! s . ok ( ) ) {
return NewErrorInternalIterator ( s , arena ) ;
}
}
if ( table_reader_ptr ! = nullptr ) {
if ( table_reader_ptr ! = nullptr ) {
* table_reader_ptr = nullptr ;
* table_reader_ptr = nullptr ;
}
}
@ -185,18 +195,14 @@ InternalIterator* TableCache::NewIterator(
size_t readahead = 0 ;
size_t readahead = 0 ;
bool create_new_table_reader = false ;
bool create_new_table_reader = false ;
// pointless to create a new table reader for range tombstones only since the
if ( for_compaction ) {
// reader isn't reused
if ( ioptions_ . new_table_reader_for_compaction_inputs ) {
if ( ! is_range_del_only ) {
readahead = ioptions_ . compaction_readahead_size ;
if ( for_compaction ) {
create_new_table_reader = true ;
if ( ioptions_ . new_table_reader_for_compaction_inputs ) {
readahead = ioptions_ . compaction_readahead_size ;
create_new_table_reader = true ;
}
} else {
readahead = options . readahead_size ;
create_new_table_reader = readahead > 0 ;
}
}
} else {
readahead = options . readahead_size ;
create_new_table_reader = readahead > 0 ;
}
}
if ( create_new_table_reader ) {
if ( create_new_table_reader ) {
@ -223,40 +229,51 @@ InternalIterator* TableCache::NewIterator(
}
}
}
}
if ( range_del_agg ! = nullptr & & ! options . ignore_range_deletions ) {
InternalIterator * result =
std : : unique_ptr < InternalIterator > iter (
table_reader - > NewIterator ( options , arena , skip_filters ) ;
table_reader - > NewRangeTombstoneIterator ( options ) ) ;
if ( create_new_table_reader ) {
Status s = range_del_agg - > AddTombstones ( std : : move ( iter ) ) ;
assert ( handle = = nullptr ) ;
if ( ! s . ok ( ) ) {
result - > RegisterCleanup ( & DeleteTableReader , table_reader , nullptr ) ;
return NewErrorInternalIterator ( s , arena ) ;
} else if ( handle ! = nullptr ) {
}
result - > RegisterCleanup ( & UnrefEntry , cache_ , handle ) ;
}
}
InternalIterator * result = nullptr ;
if ( for_compaction ) {
if ( ! is_range_del_only ) {
table_reader - > SetupForCompaction ( ) ;
result = table_reader - > NewIterator ( options , arena , skip_filters ) ;
}
if ( create_new_table_reader ) {
if ( table_reader_ptr ! = nullptr ) {
assert ( handle = = nullptr ) ;
* table_reader_ptr = table_reader ;
result - > RegisterCleanup ( & DeleteTableReader , table_reader , nullptr ) ;
}
} else if ( handle ! = nullptr ) {
return result ;
result - > RegisterCleanup ( & UnrefEntry , cache_ , handle ) ;
}
}
if ( for_compaction ) {
InternalIterator * TableCache : : NewRangeDeletionIterator (
table_reader - > SetupForCompaction ( ) ;
const ReadOptions & options , const InternalKeyComparator & icmp ,
}
const FileDescriptor & fd , HistogramImpl * file_read_hist , bool skip_filters ,
if ( table_reader_ptr ! = nullptr ) {
int level ) {
* table_reader_ptr = table_reader ;
if ( options . ignore_range_deletions ) {
return NewEmptyInternalIterator ( ) ;
}
Status s ;
TableReader * table_reader = fd . table_reader ;
Cache : : Handle * cache_handle = nullptr ;
if ( table_reader = = nullptr ) {
s = FindTable ( env_options_ , icmp , fd , & cache_handle ,
options . read_tier = = kBlockCacheTier /* no_io */ ,
true /* record_read_stats */ , file_read_hist , skip_filters ,
level ) ;
if ( s . ok ( ) ) {
table_reader = GetTableReaderFromHandle ( cache_handle ) ;
}
}
} else {
}
assert ( ! create_new_table_reader ) ;
if ( s . ok ( ) ) {
// don't need the table reader at all since the iterator over the meta-block
auto * result = table_reader - > NewRangeTombstoneIterator ( options ) ;
// doesn't require it
if ( cache_handle ! = nullptr ) {
if ( handle ! = nullptr ) {
result - > RegisterCleanup ( & UnrefEntry , cache_ , cache_handle ) ;
UnrefEntry ( cache_ , handle ) ;
}
}
return result ;
}
}
return result ;
return NewErrorInternalIterator ( s ) ;
}
}
Status TableCache : : Get ( const ReadOptions & options ,
Status TableCache : : Get ( const ReadOptions & options ,
@ -264,6 +281,19 @@ Status TableCache::Get(const ReadOptions& options,
const FileDescriptor & fd , const Slice & k ,
const FileDescriptor & fd , const Slice & k ,
GetContext * get_context , HistogramImpl * file_read_hist ,
GetContext * get_context , HistogramImpl * file_read_hist ,
bool skip_filters , int level ) {
bool skip_filters , int level ) {
if ( get_context - > range_del_agg ( ) ! = nullptr & &
! options . ignore_range_deletions ) {
std : : unique_ptr < InternalIterator > range_del_iter ( NewRangeDeletionIterator (
options , internal_comparator , fd , file_read_hist , skip_filters , level ) ) ;
Status s = range_del_iter - > status ( ) ;
if ( s . ok ( ) ) {
s = get_context - > range_del_agg ( ) - > AddTombstones (
std : : move ( range_del_iter ) ) ;
}
if ( ! s . ok ( ) ) {
return s ;
}
}
TableReader * t = fd . table_reader ;
TableReader * t = fd . table_reader ;
Status s ;
Status s ;
Cache : : Handle * handle = nullptr ;
Cache : : Handle * handle = nullptr ;