@ -80,11 +80,12 @@ Status ReadBlockFromFile(
std : : unique_ptr < Block > * result , const ImmutableCFOptions & ioptions ,
std : : unique_ptr < Block > * result , const ImmutableCFOptions & ioptions ,
bool do_uncompress , const Slice & compression_dict ,
bool do_uncompress , const Slice & compression_dict ,
const PersistentCacheOptions & cache_options , SequenceNumber global_seqno ,
const PersistentCacheOptions & cache_options , SequenceNumber global_seqno ,
size_t read_amp_bytes_per_bit , const bool immortal_file = false ) {
size_t read_amp_bytes_per_bit , CacheAllocator * allocator = nullptr ,
const bool immortal_file = false ) {
BlockContents contents ;
BlockContents contents ;
BlockFetcher block_fetcher ( file , prefetch_buffer , footer , options , handle ,
BlockFetcher block_fetcher (
& contents , ioptions , do_uncompres s ,
file , prefetch_buffer , footer , options , handle , & contents , ioption s,
compression_dict , cache_options , immortal_file ) ;
do_uncompress , compression_dict , cache_options , allocator , immortal_file ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
result - > reset ( new Block ( std : : move ( contents ) , global_seqno ,
result - > reset ( new Block ( std : : move ( contents ) , global_seqno ,
@ -94,6 +95,13 @@ Status ReadBlockFromFile(
return s ;
return s ;
}
}
inline CacheAllocator * GetCacheAllocator (
const BlockBasedTableOptions & table_options ) {
return table_options . block_cache . get ( )
? table_options . block_cache - > cache_allocator ( )
: nullptr ;
}
// Delete the resource that is held by the iterator.
// Delete the resource that is held by the iterator.
template < class ResourceType >
template < class ResourceType >
void DeleteHeldResource ( void * arg , void * /*ignored*/ ) {
void DeleteHeldResource ( void * arg , void * /*ignored*/ ) {
@ -1150,7 +1158,8 @@ Status BlockBasedTable::ReadMetaBlock(Rep* rep,
rep - > footer . metaindex_handle ( ) , & meta , rep - > ioptions ,
rep - > footer . metaindex_handle ( ) , & meta , rep - > ioptions ,
true /* decompress */ , Slice ( ) /*compression dict*/ ,
true /* decompress */ , Slice ( ) /*compression dict*/ ,
rep - > persistent_cache_options , kDisableGlobalSequenceNumber ,
rep - > persistent_cache_options , kDisableGlobalSequenceNumber ,
0 /* read_amp_bytes_per_bit */ ) ;
0 /* read_amp_bytes_per_bit */ ,
GetCacheAllocator ( rep - > table_options ) ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
ROCKS_LOG_ERROR ( rep - > ioptions . info_log ,
ROCKS_LOG_ERROR ( rep - > ioptions . info_log ,
@ -1173,7 +1182,7 @@ Status BlockBasedTable::GetDataBlockFromCache(
const ImmutableCFOptions & ioptions , const ReadOptions & read_options ,
const ImmutableCFOptions & ioptions , const ReadOptions & read_options ,
BlockBasedTable : : CachableEntry < Block > * block , uint32_t format_version ,
BlockBasedTable : : CachableEntry < Block > * block , uint32_t format_version ,
const Slice & compression_dict , size_t read_amp_bytes_per_bit , bool is_index ,
const Slice & compression_dict , size_t read_amp_bytes_per_bit , bool is_index ,
GetContext * get_context ) {
GetContext * get_context , CacheAllocator * allocator ) {
Status s ;
Status s ;
Block * compressed_block = nullptr ;
Block * compressed_block = nullptr ;
Cache : : Handle * block_cache_compressed_handle = nullptr ;
Cache : : Handle * block_cache_compressed_handle = nullptr ;
@ -1230,7 +1239,7 @@ Status BlockBasedTable::GetDataBlockFromCache(
compression_dict ) ;
compression_dict ) ;
s = UncompressBlockContents ( uncompresssion_ctx , compressed_block - > data ( ) ,
s = UncompressBlockContents ( uncompresssion_ctx , compressed_block - > data ( ) ,
compressed_block - > size ( ) , & contents ,
compressed_block - > size ( ) , & contents ,
format_version , ioptions ) ;
format_version , ioptions , allocator ) ;
// Insert uncompressed block into block cache
// Insert uncompressed block into block cache
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
@ -1292,7 +1301,8 @@ Status BlockBasedTable::PutDataBlockToCache(
const ReadOptions & /*read_options*/ , const ImmutableCFOptions & ioptions ,
const ReadOptions & /*read_options*/ , const ImmutableCFOptions & ioptions ,
CachableEntry < Block > * block , Block * raw_block , uint32_t format_version ,
CachableEntry < Block > * block , Block * raw_block , uint32_t format_version ,
const Slice & compression_dict , size_t read_amp_bytes_per_bit , bool is_index ,
const Slice & compression_dict , size_t read_amp_bytes_per_bit , bool is_index ,
Cache : : Priority priority , GetContext * get_context ) {
Cache : : Priority priority , GetContext * get_context ,
CacheAllocator * allocator ) {
assert ( raw_block - > compression_type ( ) = = kNoCompression | |
assert ( raw_block - > compression_type ( ) = = kNoCompression | |
block_cache_compressed ! = nullptr ) ;
block_cache_compressed ! = nullptr ) ;
@ -1305,7 +1315,7 @@ Status BlockBasedTable::PutDataBlockToCache(
compression_dict ) ;
compression_dict ) ;
s = UncompressBlockContents ( uncompression_ctx , raw_block - > data ( ) ,
s = UncompressBlockContents ( uncompression_ctx , raw_block - > data ( ) ,
raw_block - > size ( ) , & contents , format_version ,
raw_block - > size ( ) , & contents , format_version ,
ioptions ) ;
ioptions , allocator ) ;
}
}
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
delete raw_block ;
delete raw_block ;
@ -1402,7 +1412,8 @@ FilterBlockReader* BlockBasedTable::ReadFilter(
BlockFetcher block_fetcher ( rep - > file . get ( ) , prefetch_buffer , rep - > footer ,
BlockFetcher block_fetcher ( rep - > file . get ( ) , prefetch_buffer , rep - > footer ,
ReadOptions ( ) , filter_handle , & block ,
ReadOptions ( ) , filter_handle , & block ,
rep - > ioptions , false /* decompress */ ,
rep - > ioptions , false /* decompress */ ,
dummy_comp_dict , rep - > persistent_cache_options ) ;
dummy_comp_dict , rep - > persistent_cache_options ,
GetCacheAllocator ( rep - > table_options ) ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -1700,7 +1711,9 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
& block_value , rep - > ioptions , rep - > blocks_maybe_compressed ,
& block_value , rep - > ioptions , rep - > blocks_maybe_compressed ,
compression_dict , rep - > persistent_cache_options ,
compression_dict , rep - > persistent_cache_options ,
is_index ? kDisableGlobalSequenceNumber : rep - > global_seqno ,
is_index ? kDisableGlobalSequenceNumber : rep - > global_seqno ,
rep - > table_options . read_amp_bytes_per_bit , rep - > immortal_table ) ;
rep - > table_options . read_amp_bytes_per_bit ,
GetCacheAllocator ( rep - > table_options ) ,
rep - > immortal_table ) ;
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
block . value = block_value . release ( ) ;
block . value = block_value . release ( ) ;
@ -1792,7 +1805,8 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache(
s = GetDataBlockFromCache (
s = GetDataBlockFromCache (
key , ckey , block_cache , block_cache_compressed , rep - > ioptions , ro ,
key , ckey , block_cache , block_cache_compressed , rep - > ioptions , ro ,
block_entry , rep - > table_options . format_version , compression_dict ,
block_entry , rep - > table_options . format_version , compression_dict ,
rep - > table_options . read_amp_bytes_per_bit , is_index , get_context ) ;
rep - > table_options . read_amp_bytes_per_bit , is_index , get_context ,
GetCacheAllocator ( rep - > table_options ) ) ;
if ( block_entry - > value = = nullptr & & ! no_io & & ro . fill_cache ) {
if ( block_entry - > value = = nullptr & & ! no_io & & ro . fill_cache ) {
std : : unique_ptr < Block > raw_block ;
std : : unique_ptr < Block > raw_block ;
@ -1804,7 +1818,9 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache(
block_cache_compressed = = nullptr & & rep - > blocks_maybe_compressed ,
block_cache_compressed = = nullptr & & rep - > blocks_maybe_compressed ,
compression_dict , rep - > persistent_cache_options ,
compression_dict , rep - > persistent_cache_options ,
is_index ? kDisableGlobalSequenceNumber : rep - > global_seqno ,
is_index ? kDisableGlobalSequenceNumber : rep - > global_seqno ,
rep - > table_options . read_amp_bytes_per_bit , rep - > immortal_table ) ;
rep - > table_options . read_amp_bytes_per_bit ,
GetCacheAllocator ( rep - > table_options ) ,
rep - > immortal_table ) ;
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
@ -1817,7 +1833,7 @@ Status BlockBasedTable::MaybeLoadDataBlockToCache(
. cache_index_and_filter_blocks_with_high_priority
. cache_index_and_filter_blocks_with_high_priority
? Cache : : Priority : : HIGH
? Cache : : Priority : : HIGH
: Cache : : Priority : : LOW ,
: Cache : : Priority : : LOW ,
get_context ) ;
get_context , GetCacheAllocator ( rep - > table_options ) ) ;
}
}
}
}
}
}
@ -2524,11 +2540,12 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
BlockHandle handle = index_iter - > value ( ) ;
BlockHandle handle = index_iter - > value ( ) ;
BlockContents contents ;
BlockContents contents ;
Slice dummy_comp_dict ;
Slice dummy_comp_dict ;
BlockFetcher block_fetcher ( rep_ - > file . get ( ) , nullptr /* prefetch buffer */ ,
BlockFetcher block_fetcher (
rep_ - > footer , ReadOptions ( ) , handle , & contents ,
rep_ - > file . get ( ) , nullptr /* prefetch buffer */ , rep_ - > footer ,
rep_ - > ioptions , false /* decompress */ ,
ReadOptions ( ) , handle , & contents , rep_ - > ioptions ,
dummy_comp_dict /*compression dict*/ ,
false /* decompress */ , dummy_comp_dict /*compression dict*/ ,
rep_ - > persistent_cache_options ) ;
rep_ - > persistent_cache_options ,
GetCacheAllocator ( rep_ - > table_options ) ) ;
s = block_fetcher . ReadBlockContents ( ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
break ;
break ;
@ -2550,11 +2567,12 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
s = handle . DecodeFrom ( & input ) ;
s = handle . DecodeFrom ( & input ) ;
BlockContents contents ;
BlockContents contents ;
Slice dummy_comp_dict ;
Slice dummy_comp_dict ;
BlockFetcher block_fetcher ( rep_ - > file . get ( ) , nullptr /* prefetch buffer */ ,
BlockFetcher block_fetcher (
rep_ - > footer , ReadOptions ( ) , handle , & contents ,
rep_ - > file . get ( ) , nullptr /* prefetch buffer */ , rep_ - > footer ,
rep_ - > ioptions , false /* decompress */ ,
ReadOptions ( ) , handle , & contents , rep_ - > ioptions ,
dummy_comp_dict /*compression dict*/ ,
false /* decompress */ , dummy_comp_dict /*compression dict*/ ,
rep_ - > persistent_cache_options ) ;
rep_ - > persistent_cache_options ,
GetCacheAllocator ( rep_ - > table_options ) ) ;
s = block_fetcher . ReadBlockContents ( ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
break ;
break ;
@ -2858,7 +2876,8 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file,
rep_ - > file . get ( ) , nullptr /* prefetch_buffer */ , rep_ - > footer ,
rep_ - > file . get ( ) , nullptr /* prefetch_buffer */ , rep_ - > footer ,
ReadOptions ( ) , handle , & block , rep_ - > ioptions ,
ReadOptions ( ) , handle , & block , rep_ - > ioptions ,
false /*decompress*/ , dummy_comp_dict /*compression dict*/ ,
false /*decompress*/ , dummy_comp_dict /*compression dict*/ ,
rep_ - > persistent_cache_options ) ;
rep_ - > persistent_cache_options ,
GetCacheAllocator ( rep_ - > table_options ) ) ;
s = block_fetcher . ReadBlockContents ( ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
rep_ - > filter . reset ( new BlockBasedFilterBlockReader (
rep_ - > filter . reset ( new BlockBasedFilterBlockReader (