@ -168,7 +168,7 @@ class Block {
BlockBasedTableOptions : : DataBlockIndexType IndexType ( ) const ;
BlockBasedTableOptions : : DataBlockIndexType IndexType ( ) const ;
// ucmp is a raw (i.e., not wrapped by `UserComparatorWrapper`) user key
// raw_ ucmp is a raw (i.e., not wrapped by `UserComparatorWrapper`) user key
// comparator.
// comparator.
//
//
// If iter is null, return new Iterator
// If iter is null, return new Iterator
@ -187,13 +187,13 @@ class Block {
// NOTE: for the hash based lookup, if a key prefix doesn't match any key,
// NOTE: for the hash based lookup, if a key prefix doesn't match any key,
// the iterator will simply be set as "invalid", rather than returning
// the iterator will simply be set as "invalid", rather than returning
// the key that is just pass the target key.
// the key that is just pass the target key.
DataBlockIter * NewDataIterator ( const Comparator * ucmp ,
DataBlockIter * NewDataIterator ( const Comparator * raw_ ucmp,
SequenceNumber global_seqno ,
SequenceNumber global_seqno ,
DataBlockIter * iter = nullptr ,
DataBlockIter * iter = nullptr ,
Statistics * stats = nullptr ,
Statistics * stats = nullptr ,
bool block_contents_pinned = false ) ;
bool block_contents_pinned = false ) ;
// ucmp is a raw (i.e., not wrapped by `UserComparatorWrapper`) user key
// raw_ ucmp is a raw (i.e., not wrapped by `UserComparatorWrapper`) user key
// comparator.
// comparator.
//
//
// key_includes_seq, default true, means that the keys are in internal key
// key_includes_seq, default true, means that the keys are in internal key
@ -208,7 +208,7 @@ class Block {
// first_internal_key. It affects data serialization format, so the same value
// first_internal_key. It affects data serialization format, so the same value
// have_first_key must be used when writing and reading index.
// have_first_key must be used when writing and reading index.
// It is determined by IndexType property of the table.
// It is determined by IndexType property of the table.
IndexBlockIter * NewIndexIterator ( const Comparator * ucmp ,
IndexBlockIter * NewIndexIterator ( const Comparator * raw_ ucmp,
SequenceNumber global_seqno ,
SequenceNumber global_seqno ,
IndexBlockIter * iter , Statistics * stats ,
IndexBlockIter * iter , Statistics * stats ,
bool total_order_seek , bool have_first_key ,
bool total_order_seek , bool have_first_key ,
@ -251,14 +251,13 @@ class Block {
template < class TValue >
template < class TValue >
class BlockIter : public InternalIteratorBase < TValue > {
class BlockIter : public InternalIteratorBase < TValue > {
public :
public :
void InitializeBase ( const Comparator * ucmp , const char * data ,
void InitializeBase ( const Comparator * raw_ ucmp, const char * data ,
uint32_t restarts , uint32_t num_restarts ,
uint32_t restarts , uint32_t num_restarts ,
SequenceNumber global_seqno , bool block_contents_pinned ) {
SequenceNumber global_seqno , bool block_contents_pinned ) {
assert ( data_ = = nullptr ) ; // Ensure it is called only once
assert ( data_ = = nullptr ) ; // Ensure it is called only once
assert ( num_restarts > 0 ) ; // Ensure the param is valid
assert ( num_restarts > 0 ) ; // Ensure the param is valid
ucmp_wrapper_ = UserComparatorWrapper ( ucmp ) ;
raw_ucmp_ = raw_ucmp ;
icmp_ = InternalKeyComparator ( ucmp , false /* named */ ) ;
data_ = data ;
data_ = data ;
restarts_ = restarts ;
restarts_ = restarts ;
num_restarts_ = num_restarts ;
num_restarts_ = num_restarts ;
@ -357,9 +356,6 @@ class BlockIter : public InternalIteratorBase<TValue> {
Cache : : Handle * cache_handle ( ) { return cache_handle_ ; }
Cache : : Handle * cache_handle ( ) { return cache_handle_ ; }
protected :
protected :
UserComparatorWrapper ucmp_wrapper_ ;
InternalKeyComparator icmp_ ;
const char * data_ ; // underlying block contents
const char * data_ ; // underlying block contents
uint32_t num_restarts_ ; // Number of uint32_t entries in restart array
uint32_t num_restarts_ ; // Number of uint32_t entries in restart array
@ -390,6 +386,12 @@ class BlockIter : public InternalIteratorBase<TValue> {
virtual void NextImpl ( ) = 0 ;
virtual void NextImpl ( ) = 0 ;
virtual void PrevImpl ( ) = 0 ;
virtual void PrevImpl ( ) = 0 ;
InternalKeyComparator icmp ( ) {
return InternalKeyComparator ( raw_ucmp_ , false /* named */ ) ;
}
UserComparatorWrapper ucmp ( ) { return UserComparatorWrapper ( raw_ucmp_ ) ; }
// Must be called every time a key is found that needs to be returned to user,
// Must be called every time a key is found that needs to be returned to user,
// and may be called when no key is found (as a no-op). Updates `key_`,
// and may be called when no key is found (as a no-op). Updates `key_`,
// `key_buf_`, and `key_pinned_` with info about the found key.
// `key_buf_`, and `key_pinned_` with info about the found key.
@ -419,15 +421,16 @@ class BlockIter : public InternalIteratorBase<TValue> {
int CompareCurrentKey ( const Slice & other ) {
int CompareCurrentKey ( const Slice & other ) {
if ( raw_key_ . IsUserKey ( ) ) {
if ( raw_key_ . IsUserKey ( ) ) {
assert ( global_seqno_ = = kDisableGlobalSequenceNumber ) ;
assert ( global_seqno_ = = kDisableGlobalSequenceNumber ) ;
return ucmp_wrapper_ . Compare ( raw_key_ . GetUserKey ( ) , other ) ;
return ucmp ( ) . Compare ( raw_key_ . GetUserKey ( ) , other ) ;
} else if ( global_seqno_ = = kDisableGlobalSequenceNumber ) {
} else if ( global_seqno_ = = kDisableGlobalSequenceNumber ) {
return icmp_ . Compare ( raw_key_ . GetInternalKey ( ) , other ) ;
return icmp ( ) . Compare ( raw_key_ . GetInternalKey ( ) , other ) ;
}
}
return icmp_ . Compare ( raw_key_ . GetInternalKey ( ) , global_seqno_ , other ,
return icmp ( ) . Compare ( raw_key_ . GetInternalKey ( ) , global_seqno_ , other ,
kDisableGlobalSequenceNumber ) ;
kDisableGlobalSequenceNumber ) ;
}
}
private :
private :
const Comparator * raw_ucmp_ ;
// Store the cache handle, if the block is cached. We need this since the
// Store the cache handle, if the block is cached. We need this since the
// only other place the handle is stored is as an argument to the Cleanable
// only other place the handle is stored is as an argument to the Cleanable
// function callback, which is hard to retrieve. When multiple value
// function callback, which is hard to retrieve. When multiple value
@ -472,20 +475,21 @@ class DataBlockIter final : public BlockIter<Slice> {
public :
public :
DataBlockIter ( )
DataBlockIter ( )
: BlockIter ( ) , read_amp_bitmap_ ( nullptr ) , last_bitmap_offset_ ( 0 ) { }
: BlockIter ( ) , read_amp_bitmap_ ( nullptr ) , last_bitmap_offset_ ( 0 ) { }
DataBlockIter ( const Comparator * ucmp , const char * data , uint32_t restarts ,
DataBlockIter ( const Comparator * raw_ ucmp, const char * data , uint32_t restarts ,
uint32_t num_restarts , SequenceNumber global_seqno ,
uint32_t num_restarts , SequenceNumber global_seqno ,
BlockReadAmpBitmap * read_amp_bitmap , bool block_contents_pinned ,
BlockReadAmpBitmap * read_amp_bitmap , bool block_contents_pinned ,
DataBlockHashIndex * data_block_hash_index )
DataBlockHashIndex * data_block_hash_index )
: DataBlockIter ( ) {
: DataBlockIter ( ) {
Initialize ( ucmp , data , restarts , num_restarts , global_seqno ,
Initialize ( raw_ ucmp, data , restarts , num_restarts , global_seqno ,
read_amp_bitmap , block_contents_pinned , data_block_hash_index ) ;
read_amp_bitmap , block_contents_pinned , data_block_hash_index ) ;
}
}
void Initialize ( const Comparator * ucmp , const char * data , uint32_t restarts ,
void Initialize ( const Comparator * raw_ucmp , const char * data ,
uint32_t num_restarts , SequenceNumber global_seqno ,
uint32_t restarts , uint32_t num_restarts ,
SequenceNumber global_seqno ,
BlockReadAmpBitmap * read_amp_bitmap ,
BlockReadAmpBitmap * read_amp_bitmap ,
bool block_contents_pinned ,
bool block_contents_pinned ,
DataBlockHashIndex * data_block_hash_index ) {
DataBlockHashIndex * data_block_hash_index ) {
InitializeBase ( ucmp , data , restarts , num_restarts , global_seqno ,
InitializeBase ( raw_ ucmp, data , restarts , num_restarts , global_seqno ,
block_contents_pinned ) ;
block_contents_pinned ) ;
raw_key_ . SetIsUserKey ( false ) ;
raw_key_ . SetIsUserKey ( false ) ;
read_amp_bitmap_ = read_amp_bitmap ;
read_amp_bitmap_ = read_amp_bitmap ;
@ -594,12 +598,12 @@ class IndexBlockIter final : public BlockIter<IndexValue> {
// format.
// format.
// value_is_full, default true, means that no delta encoding is
// value_is_full, default true, means that no delta encoding is
// applied to values.
// applied to values.
void Initialize ( const Comparator * ucmp , const char * data , uint32_t restarts ,
void Initialize ( const Comparator * raw_ ucmp, const char * data ,
uint32_t num_ restarts, SequenceNumber global_seqno ,
uint32_t restarts , uint32_t num_restarts ,
BlockPrefixIndex * prefix_index , bool have_first_key ,
SequenceNumber global_seqno , BlockPrefixIndex * prefix_index ,
bool key_includes_seq , bool value_is_full ,
bool have_first_key , bool key_includes_seq ,
bool block_contents_pinned ) {
bool value_is_full , bool block_contents_pinned ) {
InitializeBase ( ucmp , data , restarts , num_restarts ,
InitializeBase ( raw_ ucmp, data , restarts , num_restarts ,
kDisableGlobalSequenceNumber , block_contents_pinned ) ;
kDisableGlobalSequenceNumber , block_contents_pinned ) ;
raw_key_ . SetIsUserKey ( ! key_includes_seq ) ;
raw_key_ . SetIsUserKey ( ! key_includes_seq ) ;
prefix_index_ = prefix_index ;
prefix_index_ = prefix_index ;