@ -32,6 +32,7 @@
# include "table/block_hash_index.h"
# include "table/block_prefix_index.h"
# include "table/format.h"
# include "table/internal_iterator.h"
# include "table/meta_blocks.h"
# include "table/two_level_iterator.h"
# include "table/get_context.h"
@ -146,8 +147,8 @@ class BlockBasedTable::IndexReader {
// Create an iterator for index access.
// An iter is passed in, if it is not null, update this one and return it
// If it is null, create a new Iterator
virtual Iterator * NewIterator (
BlockIter * iter = nullptr , bool total_order_seek = true ) = 0 ;
virtual InternalI terator * NewIterator ( BlockIter * iter = nullptr ,
bool total_order_seek = true ) = 0 ;
// The size of the index.
virtual size_t size ( ) const = 0 ;
@ -187,8 +188,8 @@ class BinarySearchIndexReader : public IndexReader {
return s ;
}
virtual Iterator * NewIterator (
BlockIter * iter = nullptr , bool dont_care = true ) override {
virtual InternalI terator * NewIterator ( BlockIter * iter = nullptr ,
bool dont_care = true ) override {
return index_block_ - > NewIterator ( comparator_ , iter , true ) ;
}
@ -219,7 +220,8 @@ class HashIndexReader : public IndexReader {
const Footer & footer , RandomAccessFileReader * file ,
Env * env , const Comparator * comparator ,
const BlockHandle & index_handle ,
Iterator * meta_index_iter , IndexReader * * index_reader ,
InternalIterator * meta_index_iter ,
IndexReader * * index_reader ,
bool hash_index_allow_collision ) {
std : : unique_ptr < Block > index_block ;
auto s = ReadBlockFromFile ( file , footer , ReadOptions ( ) , index_handle ,
@ -298,8 +300,8 @@ class HashIndexReader : public IndexReader {
return Status : : OK ( ) ;
}
virtual Iterator * NewIterator (
BlockIter * iter = nullptr , bool total_order_seek = true ) override {
virtual InternalI terator * NewIterator ( BlockIter * iter = nullptr ,
bool total_order_seek = true ) override {
return index_block_ - > NewIterator ( comparator_ , iter , total_order_seek ) ;
}
@ -512,7 +514,7 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
// Read meta index
std : : unique_ptr < Block > meta ;
std : : unique_ptr < Iterator > meta_iter ;
std : : unique_ptr < InternalI terator > meta_iter ;
s = ReadMetaBlock ( rep , & meta , & meta_iter ) ;
if ( ! s . ok ( ) ) {
return s ;
@ -580,7 +582,8 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
assert ( table_options . block_cache ! = nullptr ) ;
// Hack: Call NewIndexIterator() to implicitly add index to the
// block_cache
unique_ptr < Iterator > iter ( new_table - > NewIndexIterator ( ReadOptions ( ) ) ) ;
unique_ptr < InternalIterator > iter (
new_table - > NewIndexIterator ( ReadOptions ( ) ) ) ;
s = iter - > status ( ) ;
if ( s . ok ( ) ) {
@ -652,10 +655,9 @@ size_t BlockBasedTable::ApproximateMemoryUsage() const {
// Load the meta-block from the file. On success, return the loaded meta block
// and its iterator.
Status BlockBasedTable : : ReadMetaBlock (
Rep * rep ,
std : : unique_ptr < Block > * meta_block ,
std : : unique_ptr < Iterator > * iter ) {
Status BlockBasedTable : : ReadMetaBlock ( Rep * rep ,
std : : unique_ptr < Block > * meta_block ,
std : : unique_ptr < InternalIterator > * iter ) {
// TODO(sanjay): Skip this if footer.metaindex_handle() size indicates
// it is an empty block.
// TODO: we never really verify check sum for meta index block
@ -898,8 +900,8 @@ BlockBasedTable::CachableEntry<FilterBlockReader> BlockBasedTable::GetFilter(
return { filter , cache_handle } ;
}
Iterator * BlockBasedTable : : NewIndexIterator ( const ReadOptions & read_options ,
BlockIter * input_iter ) {
InternalI terator * BlockBasedTable : : NewIndexIterator (
const ReadOptions & read_options , BlockIter * input_iter ) {
// index reader has already been pre-populated.
if ( rep_ - > index_reader ) {
return rep_ - > index_reader - > NewIterator (
@ -922,7 +924,7 @@ Iterator* BlockBasedTable::NewIndexIterator(const ReadOptions& read_options,
input_iter - > SetStatus ( Status : : Incomplete ( " no blocking io " ) ) ;
return input_iter ;
} else {
return NewErrorIterator ( Status : : Incomplete ( " no blocking io " ) ) ;
return NewErrorInternalI terator ( Status : : Incomplete ( " no blocking io " ) ) ;
}
}
@ -942,7 +944,7 @@ Iterator* BlockBasedTable::NewIndexIterator(const ReadOptions& read_options,
input_iter - > SetStatus ( s ) ;
return input_iter ;
} else {
return NewErrorIterator ( s ) ;
return NewErrorInternalI terator ( s ) ;
}
}
@ -965,8 +967,8 @@ Iterator* BlockBasedTable::NewIndexIterator(const ReadOptions& read_options,
// into an iterator over the contents of the corresponding block.
// If input_iter is null, new a iterator
// If input_iter is not null, update this iter and return it
Iterator * BlockBasedTable : : NewDataBlockIterator ( Rep * rep ,
const ReadOptions & ro , const Slice & index_value ,
InternalI terator * BlockBasedTable : : NewDataBlockIterator (
Rep * rep , const ReadOptions & ro , const Slice & index_value ,
BlockIter * input_iter ) {
PERF_TIMER_GUARD ( new_table_block_iter_nanos ) ;
@ -987,7 +989,7 @@ Iterator* BlockBasedTable::NewDataBlockIterator(Rep* rep,
input_iter - > SetStatus ( s ) ;
return input_iter ;
} else {
return NewErrorIterator ( s ) ;
return NewErrorInternalI terator ( s ) ;
}
}
@ -1040,7 +1042,7 @@ Iterator* BlockBasedTable::NewDataBlockIterator(Rep* rep,
input_iter - > SetStatus ( Status : : Incomplete ( " no blocking io " ) ) ;
return input_iter ;
} else {
return NewErrorIterator ( Status : : Incomplete ( " no blocking io " ) ) ;
return NewErrorInternalI terator ( Status : : Incomplete ( " no blocking io " ) ) ;
}
}
std : : unique_ptr < Block > block_value ;
@ -1051,7 +1053,7 @@ Iterator* BlockBasedTable::NewDataBlockIterator(Rep* rep,
}
}
Iterator * iter ;
InternalI terator * iter ;
if ( block . value ! = nullptr ) {
iter = block . value - > NewIterator ( & rep - > internal_comparator , input_iter ) ;
if ( block . cache_handle ! = nullptr ) {
@ -1065,7 +1067,7 @@ Iterator* BlockBasedTable::NewDataBlockIterator(Rep* rep,
input_iter - > SetStatus ( s ) ;
iter = input_iter ;
} else {
iter = NewErrorIterator ( s ) ;
iter = NewErrorInternalI terator ( s ) ;
}
}
return iter ;
@ -1080,7 +1082,7 @@ class BlockBasedTable::BlockEntryIteratorState : public TwoLevelIteratorState {
table_ ( table ) ,
read_options_ ( read_options ) { }
Iterator * NewSecondaryIterator ( const Slice & index_value ) override {
InternalI terator * NewSecondaryIterator ( const Slice & index_value ) override {
return NewDataBlockIterator ( table_ - > rep_ , read_options_ , index_value ) ;
}
@ -1138,7 +1140,7 @@ bool BlockBasedTable::PrefixMayMatch(const Slice& internal_key) {
// Then, try find it within each block
if ( may_match ) {
unique_ptr < Iterator > iiter ( NewIndexIterator ( no_io_read_options ) ) ;
unique_ptr < InternalI terator > iiter ( NewIndexIterator ( no_io_read_options ) ) ;
iiter - > Seek ( internal_prefix ) ;
if ( ! iiter - > Valid ( ) ) {
@ -1184,8 +1186,8 @@ bool BlockBasedTable::PrefixMayMatch(const Slice& internal_key) {
return may_match ;
}
Iterator * BlockBasedTable : : NewIterator ( const ReadOptions & read_options ,
Arena * arena ) {
InternalI terator * BlockBasedTable : : NewIterator ( const ReadOptions & read_options ,
Arena * arena ) {
return NewTwoLevelIterator ( new BlockEntryIteratorState ( this , read_options ) ,
NewIndexIterator ( read_options ) , arena ) ;
}
@ -1326,7 +1328,7 @@ Status BlockBasedTable::Prefetch(const Slice* const begin,
bool BlockBasedTable : : TEST_KeyInCache ( const ReadOptions & options ,
const Slice & key ) {
std : : unique_ptr < Iterator > iiter ( NewIndexIterator ( options ) ) ;
std : : unique_ptr < InternalI terator > iiter ( NewIndexIterator ( options ) ) ;
iiter - > Seek ( key ) ;
assert ( iiter - > Valid ( ) ) ;
CachableEntry < Block > block ;
@ -1361,8 +1363,8 @@ bool BlockBasedTable::TEST_KeyInCache(const ReadOptions& options,
// 3. options
// 4. internal_comparator
// 5. index_type
Status BlockBasedTable : : CreateIndexReader ( IndexReader * * index_reader ,
Iterator * preloaded_meta_index_iter ) {
Status BlockBasedTable : : CreateIndexReader (
IndexReader * * index_reader , Internal Iterator* preloaded_meta_index_iter ) {
// Some old version of block-based tables don't have index type present in
// table properties. If that's the case we can safely use the kBinarySearch.
auto index_type_on_file = BlockBasedTableOptions : : kBinarySearch ;
@ -1396,7 +1398,7 @@ Status BlockBasedTable::CreateIndexReader(IndexReader** index_reader,
}
case BlockBasedTableOptions : : kHashSearch : {
std : : unique_ptr < Block > meta_guard ;
std : : unique_ptr < Iterator > meta_iter_guard ;
std : : unique_ptr < InternalI terator > meta_iter_guard ;
auto meta_index_iter = preloaded_meta_index_iter ;
if ( meta_index_iter = = nullptr ) {
auto s = ReadMetaBlock ( rep_ , & meta_guard , & meta_iter_guard ) ;
@ -1430,7 +1432,7 @@ Status BlockBasedTable::CreateIndexReader(IndexReader** index_reader,
}
uint64_t BlockBasedTable : : ApproximateOffsetOf ( const Slice & key ) {
unique_ptr < Iterator > index_iter ( NewIndexIterator ( ReadOptions ( ) ) ) ;
unique_ptr < InternalI terator > index_iter ( NewIndexIterator ( ReadOptions ( ) ) ) ;
index_iter - > Seek ( key ) ;
uint64_t result ;
@ -1484,7 +1486,7 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file) {
" Metaindex Details: \n "
" -------------------------------------- \n " ) ;
std : : unique_ptr < Block > meta ;
std : : unique_ptr < Iterator > meta_iter ;
std : : unique_ptr < InternalI terator > meta_iter ;
Status s = ReadMetaBlock ( rep_ , & meta , & meta_iter ) ;
if ( s . ok ( ) ) {
for ( meta_iter - > SeekToFirst ( ) ; meta_iter - > Valid ( ) ; meta_iter - > Next ( ) ) {
@ -1567,7 +1569,8 @@ Status BlockBasedTable::DumpIndexBlock(WritableFile* out_file) {
" Index Details: \n "
" -------------------------------------- \n " ) ;
std : : unique_ptr < Iterator > blockhandles_iter ( NewIndexIterator ( ReadOptions ( ) ) ) ;
std : : unique_ptr < InternalIterator > blockhandles_iter (
NewIndexIterator ( ReadOptions ( ) ) ) ;
Status s = blockhandles_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
out_file - > Append ( " Can not read Index Block \n \n " ) ;
@ -1608,7 +1611,8 @@ Status BlockBasedTable::DumpIndexBlock(WritableFile* out_file) {
}
Status BlockBasedTable : : DumpDataBlocks ( WritableFile * out_file ) {
std : : unique_ptr < Iterator > blockhandles_iter ( NewIndexIterator ( ReadOptions ( ) ) ) ;
std : : unique_ptr < InternalIterator > blockhandles_iter (
NewIndexIterator ( ReadOptions ( ) ) ) ;
Status s = blockhandles_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
out_file - > Append ( " Can not read Index Block \n \n " ) ;
@ -1630,7 +1634,7 @@ Status BlockBasedTable::DumpDataBlocks(WritableFile* out_file) {
out_file - > Append ( " \n " ) ;
out_file - > Append ( " -------------------------------------- \n " ) ;
std : : unique_ptr < Iterator > datablock_iter ;
std : : unique_ptr < InternalI terator > datablock_iter ;
datablock_iter . reset (
NewDataBlockIterator ( rep_ , ReadOptions ( ) , blockhandles_iter - > value ( ) ) ) ;
s = datablock_iter - > status ( ) ;