@ -78,13 +78,14 @@ Status ReadBlockFromFile(
RandomAccessFileReader * file , FilePrefetchBuffer * prefetch_buffer ,
const Footer & footer , const ReadOptions & options , const BlockHandle & handle ,
std : : unique_ptr < Block > * result , const ImmutableCFOptions & ioptions ,
bool do_uncompress , const Slice & compression_dict ,
bool do_uncompress , bool maybe_compressed , const Slice & compression_dict ,
const PersistentCacheOptions & cache_options , SequenceNumber global_seqno ,
size_t read_amp_bytes_per_bit , MemoryAllocator * allocator = nullpt r ) {
size_t read_amp_bytes_per_bit , MemoryAllocator * memory_ allocator) {
BlockContents contents ;
BlockFetcher block_fetcher ( file , prefetch_buffer , footer , options , handle ,
& contents , ioptions , do_uncompress ,
compression_dict , cache_options , allocator ) ;
maybe_compressed , compression_dict , cache_options ,
memory_allocator ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
if ( s . ok ( ) ) {
result - > reset ( new Block ( std : : move ( contents ) , global_seqno ,
@ -101,6 +102,13 @@ inline MemoryAllocator* GetMemoryAllocator(
: nullptr ;
}
inline MemoryAllocator * GetMemoryAllocatorForCompressedBlock (
const BlockBasedTableOptions & table_options ) {
return table_options . block_cache_compressed . get ( )
? table_options . block_cache_compressed - > memory_allocator ( )
: nullptr ;
}
// Delete the resource that is held by the iterator.
template < class ResourceType >
void DeleteHeldResource ( void * arg , void * /*ignored*/ ) {
@ -222,13 +230,15 @@ class PartitionIndexReader : public IndexReader, public Cleanable {
IndexReader * * index_reader ,
const PersistentCacheOptions & cache_options ,
const int level , const bool index_key_includes_seq ,
const bool index_value_is_full ) {
const bool index_value_is_full ,
MemoryAllocator * memory_allocator ) {
std : : unique_ptr < Block > index_block ;
auto s = ReadBlockFromFile (
file , prefetch_buffer , footer , ReadOptions ( ) , index_handle ,
& index_block , ioptions , true /* decompress */ ,
Slice ( ) /*compression dict*/ , cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ) ;
true /*maybe_compressed*/ , Slice ( ) /*compression dict*/ , cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ,
memory_allocator ) ;
if ( s . ok ( ) ) {
* index_reader = new PartitionIndexReader (
@ -401,13 +411,15 @@ class BinarySearchIndexReader : public IndexReader {
IndexReader * * index_reader ,
const PersistentCacheOptions & cache_options ,
const bool index_key_includes_seq ,
const bool index_value_is_full ) {
const bool index_value_is_full ,
MemoryAllocator * memory_allocator ) {
std : : unique_ptr < Block > index_block ;
auto s = ReadBlockFromFile (
file , prefetch_buffer , footer , ReadOptions ( ) , index_handle ,
& index_block , ioptions , true /* decompress */ ,
Slice ( ) /*compression dict*/ , cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ) ;
true /*maybe_compressed*/ , Slice ( ) /*compression dict*/ , cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ,
memory_allocator ) ;
if ( s . ok ( ) ) {
* index_reader = new BinarySearchIndexReader (
@ -473,13 +485,15 @@ class HashIndexReader : public IndexReader {
InternalIterator * meta_index_iter , IndexReader * * index_reader ,
bool /*hash_index_allow_collision*/ ,
const PersistentCacheOptions & cache_options ,
const bool index_key_includes_seq , const bool index_value_is_full ) {
const bool index_key_includes_seq , const bool index_value_is_full ,
MemoryAllocator * memory_allocator ) {
std : : unique_ptr < Block > index_block ;
auto s = ReadBlockFromFile (
file , prefetch_buffer , footer , ReadOptions ( ) , index_handle ,
& index_block , ioptions , true /* decompress */ ,
Slice ( ) /*compression dict*/ , cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ) ;
true /*maybe_compressed*/ , Slice ( ) /*compression dict*/ , cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ,
memory_allocator ) ;
if ( ! s . ok ( ) ) {
return s ;
@ -518,7 +532,8 @@ class HashIndexReader : public IndexReader {
BlockFetcher prefixes_block_fetcher (
file , prefetch_buffer , footer , ReadOptions ( ) , prefixes_handle ,
& prefixes_contents , ioptions , true /*decompress*/ ,
dummy_comp_dict /*compression dict*/ , cache_options ) ;
true /*maybe_compressed*/ , dummy_comp_dict /*compression dict*/ ,
cache_options , memory_allocator ) ;
s = prefixes_block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
return s ;
@ -527,7 +542,8 @@ class HashIndexReader : public IndexReader {
BlockFetcher prefixes_meta_block_fetcher (
file , prefetch_buffer , footer , ReadOptions ( ) , prefixes_meta_handle ,
& prefixes_meta_contents , ioptions , true /*decompress*/ ,
dummy_comp_dict /*compression dict*/ , cache_options ) ;
true /*maybe_compressed*/ , dummy_comp_dict /*compression dict*/ ,
cache_options , memory_allocator ) ;
s = prefixes_meta_block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
// TODO: log error
@ -894,7 +910,9 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
if ( s . ok ( ) ) {
s = ReadProperties ( meta_iter - > value ( ) , rep - > file . get ( ) ,
prefetch_buffer . get ( ) , rep - > footer , rep - > ioptions ,
& table_properties , false /* compression_type_missing */ ) ;
& table_properties ,
false /* compression_type_missing */ ,
nullptr /* memory_allocator */ ) ;
}
if ( ! s . ok ( ) ) {
@ -938,7 +956,8 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
read_options . verify_checksums = false ;
BlockFetcher compression_block_fetcher (
rep - > file . get ( ) , prefetch_buffer . get ( ) , rep - > footer , read_options ,
compression_dict_handle , compression_dict_cont . get ( ) , rep - > ioptions , false /* decompress */ ,
compression_dict_handle , compression_dict_cont . get ( ) , rep - > ioptions ,
false /* decompress */ , false /*maybe_compressed*/ ,
Slice ( ) /*compression dict*/ , cache_options ) ;
s = compression_block_fetcher . ReadBlockContents ( ) ;
@ -1166,9 +1185,10 @@ Status BlockBasedTable::ReadMetaBlock(Rep* rep,
Status s = ReadBlockFromFile (
rep - > file . get ( ) , prefetch_buffer , rep - > footer , ReadOptions ( ) ,
rep - > footer . metaindex_handle ( ) , & meta , rep - > ioptions ,
true /* decompress */ , Slice ( ) /*compression dict*/ ,
rep - > persistent_cache_options , kDisableGlobalSequenceNumber ,
0 /* read_amp_bytes_per_bit */ , GetMemoryAllocator ( rep - > table_options ) ) ;
true /* decompress */ , true /*maybe_compressed*/ ,
Slice ( ) /*compression dict*/ , rep - > persistent_cache_options ,
kDisableGlobalSequenceNumber , 0 /* read_amp_bytes_per_bit */ ,
GetMemoryAllocator ( rep - > table_options ) ) ;
if ( ! s . ok ( ) ) {
ROCKS_LOG_ERROR ( rep - > ioptions . info_log ,
@ -1312,8 +1332,8 @@ Status BlockBasedTable::PutDataBlockToCache(
CachableEntry < Block > * cached_block , BlockContents * raw_block_contents ,
CompressionType raw_block_comp_type , uint32_t format_version ,
const Slice & compression_dict , SequenceNumber seq_no ,
size_t read_amp_bytes_per_bit , bool is_index , Cache : : Priority priority ,
GetContext * get_context , MemoryAllocator * allocator ) {
size_t read_amp_bytes_per_bit , MemoryAllocator * memory_allocator ,
bool is_index , Cache : : Priority priority , GetContext * get_context ) {
assert ( raw_block_comp_type = = kNoCompression | |
block_cache_compressed ! = nullptr ) ;
@ -1327,7 +1347,7 @@ Status BlockBasedTable::PutDataBlockToCache(
s = UncompressBlockContents (
uncompression_ctx , raw_block_contents - > data . data ( ) ,
raw_block_contents - > data . size ( ) , & uncompressed_block_contents ,
format_version , ioptions , allocator ) ;
format_version , ioptions , memory_ allocator) ;
}
if ( ! s . ok ( ) ) {
return s ;
@ -1431,11 +1451,11 @@ FilterBlockReader* BlockBasedTable::ReadFilter(
Slice dummy_comp_dict ;
BlockFetcher block_fetcher ( rep - > file . get ( ) , prefetch_buffer , rep - > footer ,
ReadOptions ( ) , filter_handle , & block ,
rep - > ioptions , false /* decompress */ ,
dummy_comp_dict , rep - > persistent_cache_options ,
GetMemoryAllocator ( rep - > table_options ) ) ;
BlockFetcher block_fetcher (
rep - > file . get ( ) , prefetch_buffer , rep - > footer , ReadOptions ( ) ,
filter_handle , & block , rep - > ioptions , false /* decompress */ ,
false /*maybe_compressed*/ , dummy_comp_dict ,
rep - > persistent_cache_options , GetMemoryAllocator ( rep - > table_options ) ) ;
Status s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
@ -1736,8 +1756,10 @@ TBlockIter* BlockBasedTable::NewDataBlockIterator(
READ_BLOCK_GET_MICROS ) ;
s = ReadBlockFromFile (
rep - > file . get ( ) , prefetch_buffer , rep - > footer , ro , handle ,
& block_value , rep - > ioptions , rep - > blocks_maybe_compressed ,
compression_dict , rep - > persistent_cache_options ,
& block_value , rep - > ioptions ,
rep - > blocks_maybe_compressed /*do_decompress*/ ,
rep - > blocks_maybe_compressed , compression_dict ,
rep - > persistent_cache_options ,
is_index ? kDisableGlobalSequenceNumber : rep - > global_seqno ,
rep - > table_options . read_amp_bytes_per_bit ,
GetMemoryAllocator ( rep - > table_options ) ) ;
@ -1857,13 +1879,13 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache(
BlockContents raw_block_contents ;
{
StopWatch sw ( rep - > ioptions . env , statistics , READ_BLOCK_GET_MICROS ) ;
BlockFetcher block_fetcher (
rep - > file . get ( ) , prefetch_buffer , rep - > footer , ro , handle ,
& raw_block_contents , rep - > ioptions ,
do_decompress /* do uncompress */ , compression_dict ,
rep - > persistent_cache_options ,
GetMemoryAllocator ( rep - > table_options ) ) ;
do_decompress /* do uncompress */ , rep - > blocks_maybe_compressed ,
compression_dict , rep - > persistent_cache_options ,
GetMemoryAllocator ( rep - > table_options ) ,
GetMemoryAllocatorForCompressedBlock ( rep - > table_options ) ) ;
s = block_fetcher . ReadBlockContents ( ) ;
raw_block_comp_type = block_fetcher . get_compression_type ( ) ;
}
@ -1876,12 +1898,13 @@ Status BlockBasedTable::MaybeReadBlockAndLoadToCache(
key , ckey , block_cache , block_cache_compressed , ro , rep - > ioptions ,
block_entry , & raw_block_contents , raw_block_comp_type ,
rep - > table_options . format_version , compression_dict , seq_no ,
rep - > table_options . read_amp_bytes_per_bit , is_index ,
rep - > table_options . read_amp_bytes_per_bit ,
GetMemoryAllocator ( rep - > table_options ) , is_index ,
is_index & & rep - > table_options
. cache_index_and_filter_blocks_with_high_priority
? Cache : : Priority : : HIGH
: Cache : : Priority : : LOW ,
get_context , GetMemoryAllocator ( rep - > table_options ) ) ;
get_context ) ;
}
}
}
@ -2608,12 +2631,11 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
BlockHandle handle = index_iter - > value ( ) ;
BlockContents contents ;
Slice dummy_comp_dict ;
BlockFetcher block_fetcher ( rep_ - > file . get ( ) , nullptr /* prefetch buffer */ ,
rep_ - > footer , ReadOptions ( ) , handle , & contents ,
rep_ - > ioptions , false /* decompress */ ,
dummy_comp_dict /*compression dict*/ ,
rep_ - > persistent_cache_options ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
BlockFetcher block_fetcher (
rep_ - > file . get ( ) , nullptr /* prefetch buffer */ , rep_ - > footer ,
ReadOptions ( ) , handle , & contents , rep_ - > ioptions ,
false /* decompress */ , false /*maybe_compressed*/ ,
dummy_comp_dict /*compression dict*/ , rep_ - > persistent_cache_options ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
break ;
@ -2635,12 +2657,11 @@ Status BlockBasedTable::VerifyChecksumInBlocks(
s = handle . DecodeFrom ( & input ) ;
BlockContents contents ;
Slice dummy_comp_dict ;
BlockFetcher block_fetcher ( rep_ - > file . get ( ) , nullptr /* prefetch buffer */ ,
rep_ - > footer , ReadOptions ( ) , handle , & contents ,
rep_ - > ioptions , false /* decompress */ ,
dummy_comp_dict /*compression dict*/ ,
rep_ - > persistent_cache_options ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
BlockFetcher block_fetcher (
rep_ - > file . get ( ) , nullptr /* prefetch buffer */ , rep_ - > footer ,
ReadOptions ( ) , handle , & contents , rep_ - > ioptions ,
false /* decompress */ , false /*maybe_compressed*/ ,
dummy_comp_dict /*compression dict*/ , rep_ - > persistent_cache_options ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
break ;
@ -2729,7 +2750,8 @@ Status BlockBasedTable::CreateIndexReader(
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_key_is_user_key = = 0 ,
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ) ;
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
}
case BlockBasedTableOptions : : kBinarySearch : {
return BinarySearchIndexReader : : Create (
@ -2738,7 +2760,8 @@ Status BlockBasedTable::CreateIndexReader(
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_key_is_user_key = = 0 ,
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ) ;
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
}
case BlockBasedTableOptions : : kHashSearch : {
std : : unique_ptr < Block > meta_guard ;
@ -2760,7 +2783,8 @@ Status BlockBasedTable::CreateIndexReader(
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_key_is_user_key = = 0 ,
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ) ;
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
}
meta_index_iter = meta_iter_guard . get ( ) ;
}
@ -2773,7 +2797,8 @@ Status BlockBasedTable::CreateIndexReader(
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_key_is_user_key = = 0 ,
rep_ - > table_properties = = nullptr | |
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ) ;
rep_ - > table_properties - > index_value_is_delta_encoded = = 0 ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
}
default : {
std : : string error_message =
@ -2942,9 +2967,9 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file,
BlockFetcher block_fetcher (
rep_ - > file . get ( ) , nullptr /* prefetch_buffer */ , rep_ - > footer ,
ReadOptions ( ) , handle , & block , rep_ - > ioptions ,
false /*decompress*/ , dummy_comp_dict /*compression dict */,
rep_ - > persistent_cache_options ,
GetMemoryAllocator ( rep_ - > table_options ) ) ;
false /*decompress*/ , false /*maybe_compressed */,
dummy_comp_dict /*compression dict*/ ,
rep_ - > persistent_cache_options ) ;
s = block_fetcher . ReadBlockContents ( ) ;
if ( ! s . ok ( ) ) {
rep_ - > filter . reset ( new BlockBasedFilterBlockReader (