@ -137,6 +137,8 @@ Slice GetCacheKeyFromOffset(const char* cache_key_prefix,
Cache : : Handle * GetEntryFromCache ( Cache * block_cache , const Slice & key ,
Tickers block_cache_miss_ticker ,
Tickers block_cache_hit_ticker ,
uint64_t * block_cache_miss_stats ,
uint64_t * block_cache_hit_stats ,
Statistics * statistics ,
GetContext * get_context ) {
auto cache_handle = block_cache - > Lookup ( key , statistics ) ;
@ -144,12 +146,12 @@ Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key,
PERF_COUNTER_ADD ( block_cache_hit_count , 1 ) ;
if ( get_context ! = nullptr ) {
// overall cache hit
get_context - > RecordCounters ( BLOCK_CACHE_HIT , 1 ) ;
get_context - > get_context_stats_ . num_cache_hit + + ;
// total bytes read from cache
get_context - > RecordCounters ( BLOCK_CACHE_BYTES_READ ,
block_cache - > GetUsage ( cache_handle ) ) ;
get_context - > get_context_stats_ . num_cache_bytes_read + =
block_cache - > GetUsage ( cache_handle ) ;
// block-type specific cache hit
get_context - > RecordCounters ( block_cache_hit_ticker , 1 ) ;
( * block_cache_hit_stats ) + + ;
} else {
// overall cache hit
RecordTick ( statistics , BLOCK_CACHE_HIT ) ;
@ -161,9 +163,9 @@ Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key,
} else {
if ( get_context ! = nullptr ) {
// overall cache miss
get_context - > RecordCounters ( BLOCK_CACHE_MISS , 1 ) ;
get_context - > get_context_stats_ . num_cache_miss + + ;
// block-type specific cache miss
get_context - > RecordCounters ( block_cache_miss_ticker , 1 ) ;
( * block_cache_miss_stats ) + + ;
} else {
RecordTick ( statistics , BLOCK_CACHE_MISS ) ;
RecordTick ( statistics , block_cache_miss_ticker ) ;
@ -1166,8 +1168,16 @@ Status BlockBasedTable::GetDataBlockFromCache(
block - > cache_handle = GetEntryFromCache (
block_cache , block_cache_key ,
is_index ? BLOCK_CACHE_INDEX_MISS : BLOCK_CACHE_DATA_MISS ,
is_index ? BLOCK_CACHE_INDEX_HIT : BLOCK_CACHE_DATA_HIT , statistics ,
get_context ) ;
is_index ? BLOCK_CACHE_INDEX_HIT : BLOCK_CACHE_DATA_HIT ,
get_context
? ( is_index ? & get_context - > get_context_stats_ . num_cache_index_miss
: & get_context - > get_context_stats_ . num_cache_data_miss )
: nullptr ,
get_context
? ( is_index ? & get_context - > get_context_stats_ . num_cache_index_hit
: & get_context - > get_context_stats_ . num_cache_data_hit )
: nullptr ,
statistics , get_context ) ;
if ( block - > cache_handle ! = nullptr ) {
block - > value =
reinterpret_cast < Block * > ( block_cache - > Value ( block - > cache_handle ) ) ;
@ -1222,24 +1232,26 @@ Status BlockBasedTable::GetDataBlockFromCache(
block_cache - > TEST_mark_as_data_block ( block_cache_key , charge ) ;
if ( s . ok ( ) ) {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_BYTES_WRITE , charge ) ;
get_context - > get_context_stats_ . num_cache_add + + ;
get_context - > get_context_stats_ . num_cache_bytes_write + = charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_BYTES_WRITE , charge ) ;
}
if ( is_index ) {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_INDEX_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_INDEX_BYTES_INSERT , charge ) ;
get_context - > get_context_stats_ . num_cache_index_add + + ;
get_context - > get_context_stats_ . num_cache_index_bytes_insert + =
charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_INDEX_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_INDEX_BYTES_INSERT , charge ) ;
}
} else {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_DATA_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_DATA_BYTES_INSERT , charge ) ;
get_context - > get_context_stats_ . num_cache_data_add + + ;
get_context - > get_context_stats_ . num_cache_data_bytes_insert + =
charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_DATA_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_DATA_BYTES_INSERT , charge ) ;
@ -1321,24 +1333,25 @@ Status BlockBasedTable::PutDataBlockToCache(
if ( s . ok ( ) ) {
assert ( block - > cache_handle ! = nullptr ) ;
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_BYTES_WRITE , charge ) ;
get_context - > get_context_stats_ . num_cache_add + + ;
get_context - > get_context_stats_ . num_cache_bytes_write + = charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_BYTES_WRITE , charge ) ;
}
if ( is_index ) {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_INDEX_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_INDEX_BYTES_INSERT , charge ) ;
get_context - > get_context_stats_ . num_cache_index_add + + ;
get_context - > get_context_stats_ . num_cache_index_bytes_insert + =
charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_INDEX_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_INDEX_BYTES_INSERT , charge ) ;
}
} else {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_DATA_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_DATA_BYTES_INSERT , charge ) ;
get_context - > get_context_stats_ . num_cache_data_add + + ;
get_context - > get_context_stats_ . num_cache_data_bytes_insert + = charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_DATA_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_DATA_BYTES_INSERT , charge ) ;
@ -1463,9 +1476,13 @@ BlockBasedTable::CachableEntry<FilterBlockReader> BlockBasedTable::GetFilter(
filter_blk_handle , cache_key ) ;
Statistics * statistics = rep_ - > ioptions . statistics ;
auto cache_handle =
GetEntryFromCache ( block_cache , key , BLOCK_CACHE_FILTER_MISS ,
BLOCK_CACHE_FILTER_HIT , statistics , get_context ) ;
auto cache_handle = GetEntryFromCache (
block_cache , key , BLOCK_CACHE_FILTER_MISS , BLOCK_CACHE_FILTER_HIT ,
get_context ? & get_context - > get_context_stats_ . num_cache_filter_miss
: nullptr ,
get_context ? & get_context - > get_context_stats_ . num_cache_filter_hit
: nullptr ,
statistics , get_context ) ;
FilterBlockReader * filter = nullptr ;
if ( cache_handle ! = nullptr ) {
@ -1486,10 +1503,11 @@ BlockBasedTable::CachableEntry<FilterBlockReader> BlockBasedTable::GetFilter(
: Cache : : Priority : : LOW ) ;
if ( s . ok ( ) ) {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_BYTES_WRITE , usage ) ;
get_context - > RecordCounters ( BLOCK_CACHE_FILTER_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_FILTER_BYTES_INSERT , usage ) ;
get_context - > get_context_stats_ . num_cache_add + + ;
get_context - > get_context_stats_ . num_cache_bytes_write + = usage ;
get_context - > get_context_stats_ . num_cache_filter_add + + ;
get_context - > get_context_stats_ . num_cache_filter_bytes_insert + =
usage ;
} else {
RecordTick ( statistics , BLOCK_CACHE_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_BYTES_WRITE , usage ) ;
@ -1535,9 +1553,13 @@ InternalIterator* BlockBasedTable::NewIndexIterator(
GetCacheKeyFromOffset ( rep_ - > cache_key_prefix , rep_ - > cache_key_prefix_size ,
rep_ - > dummy_index_reader_offset , cache_key ) ;
Statistics * statistics = rep_ - > ioptions . statistics ;
auto cache_handle =
GetEntryFromCache ( block_cache , key , BLOCK_CACHE_INDEX_MISS ,
BLOCK_CACHE_INDEX_HIT , statistics , get_context ) ;
auto cache_handle = GetEntryFromCache (
block_cache , key , BLOCK_CACHE_INDEX_MISS , BLOCK_CACHE_INDEX_HIT ,
get_context ? & get_context - > get_context_stats_ . num_cache_index_miss
: nullptr ,
get_context ? & get_context - > get_context_stats_ . num_cache_index_hit
: nullptr ,
statistics , get_context ) ;
if ( cache_handle = = nullptr & & no_io ) {
if ( input_iter ! = nullptr ) {
@ -1573,8 +1595,8 @@ InternalIterator* BlockBasedTable::NewIndexIterator(
if ( s . ok ( ) ) {
if ( get_context ! = nullptr ) {
get_context - > RecordCounters ( BLOCK_CACHE_ADD , 1 ) ;
get_context - > RecordCounters ( BLOCK_CACHE_BYTES_WRITE , charge ) ;
get_context - > get_context_stats_ . num_cache_add + + ;
get_context - > get_context_stats_ . num_cache_bytes_write + = charge ;
} else {
RecordTick ( statistics , BLOCK_CACHE_ADD ) ;
RecordTick ( statistics , BLOCK_CACHE_BYTES_WRITE , charge ) ;