@@ -2578,18 +2578,27 @@ Status BlockBasedTable::ForceEvict() {
25782578 auto compressed_cache_key_prefix_size =
25792579 rep_->compressed_cache_key_prefix_size ;
25802580
2581- auto do_evict = [=, &cache_key, &compressed_cache_key](uint64_t offset) {
2581+ uint64_t block_cache_erase_count = 0 ;
2582+ uint64_t block_cache_erase_failures_count = 0 ;
2583+
2584+ auto do_evict = [=, &cache_key, &compressed_cache_key,
2585+ &block_cache_erase_count,
2586+ &block_cache_erase_failures_count](uint64_t offset) {
25822587 if (block_cache) {
25832588 char * end = EncodeVarint64 (cache_key + cache_key_prefix_size, offset);
2584- block_cache->Erase (
2589+ bool erased = block_cache->Erase (
25852590 Slice (cache_key, static_cast <size_t >(end - cache_key)));
2591+ ++block_cache_erase_count;
2592+ block_cache_erase_failures_count += !erased;
25862593 }
25872594 if (block_cache_compressed) {
25882595 char * end = EncodeVarint64 (
25892596 compressed_cache_key + compressed_cache_key_prefix_size, offset);
2590- block_cache_compressed->Erase (
2597+ bool erased = block_cache_compressed->Erase (
25912598 Slice (compressed_cache_key,
25922599 static_cast <size_t >(end - compressed_cache_key)));
2600+ ++block_cache_erase_count;
2601+ block_cache_erase_failures_count += !erased;
25932602 }
25942603 };
25952604
@@ -2613,6 +2622,11 @@ Status BlockBasedTable::ForceEvict() {
26132622 // IndexBlock
26142623 do_evict (rep_->dummy_index_reader_offset );
26152624
2625+ RecordTick (rep_->ioptions .statistics , BLOCK_CACHE_ERASE ,
2626+ block_cache_erase_count);
2627+ RecordTick (rep_->ioptions .statistics , BLOCK_CACHE_ERASE_FAILURES ,
2628+ block_cache_erase_failures_count);
2629+
26162630 return Status::OK ();
26172631}
26182632
@@ -3127,15 +3141,21 @@ void BlockBasedTable::Close() {
31273141 // cleanup index and filter blocks to avoid accessing dangling pointer
31283142 if (!rep_->table_options .no_block_cache ) {
31293143 char cache_key[kMaxCacheKeyPrefixSize + kMaxVarint64Length ];
3144+ uint64_t erased_count = 0 ;
3145+
31303146 // Get the filter block key
31313147 auto key = GetCacheKey (rep_->cache_key_prefix , rep_->cache_key_prefix_size ,
31323148 rep_->filter_handle , cache_key);
3133- rep_->table_options .block_cache .get ()->Erase (key);
3149+ erased_count += rep_->table_options .block_cache .get ()->Erase (key);
31343150 // Get the index block key
31353151 key = GetCacheKeyFromOffset (rep_->cache_key_prefix ,
31363152 rep_->cache_key_prefix_size ,
31373153 rep_->dummy_index_reader_offset , cache_key);
3138- rep_->table_options .block_cache .get ()->Erase (key);
3154+ erased_count += rep_->table_options .block_cache .get ()->Erase (key);
3155+
3156+ RecordTick (rep_->ioptions .statistics , BLOCK_CACHE_ERASE , 2 );
3157+ RecordTick (rep_->ioptions .statistics , BLOCK_CACHE_ERASE_FAILURES ,
3158+ 2 - erased_count);
31393159 }
31403160 rep_->closed = true ;
31413161}
0 commit comments