Skip to content

Commit a1df6cf

Browse files
committed
Add tickers BLOCK_CACHE_ERASE & BLOCK_CACHE_ERASE_FAILURES
1 parent 19e67a7 commit a1df6cf

6 files changed

Lines changed: 53 additions & 10 deletions

File tree

include/rocksdb/statistics.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ enum Tickers : uint32_t {
254254
GC_TOUCH_FILES,
255255
GC_SKIP_GET_BY_SEQ,
256256
GC_SKIP_GET_BY_FILE,
257+
258+
// # of blocks erased from block cache.
259+
BLOCK_CACHE_ERASE,
260+
// # of failures when erasing blocks from block cache.
261+
BLOCK_CACHE_ERASE_FAILURES,
262+
257263
TICKER_ENUM_MAX
258264
};
259265

java/rocksjni/portal.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3476,8 +3476,12 @@ class TickerTypeJni {
34763476
return 0x63;
34773477
case TERARKDB_NAMESPACE::Tickers::GC_SKIP_GET_BY_FILE:
34783478
return 0x64;
3479-
case TERARKDB_NAMESPACE::Tickers::TICKER_ENUM_MAX:
3479+
case TERARKDB_NAMESPACE::Tickers::BLOCK_CACHE_ERASE:
34803480
return 0x65;
3481+
case TERARKDB_NAMESPACE::Tickers::BLOCK_CACHE_ERASE_FAILURES:
3482+
return 0x66;
3483+
case TERARKDB_NAMESPACE::Tickers::TICKER_ENUM_MAX:
3484+
return 0x67;
34813485

34823486
default:
34833487
// undefined/default
@@ -3692,6 +3696,10 @@ class TickerTypeJni {
36923696
case 0x64:
36933697
return TERARKDB_NAMESPACE::Tickers::GC_SKIP_GET_BY_FILE;
36943698
case 0x65:
3699+
return TERARKDB_NAMESPACE::Tickers::BLOCK_CACHE_ERASE;
3700+
case 0x66:
3701+
return TERARKDB_NAMESPACE::Tickers::BLOCK_CACHE_ERASE_FAILURES;
3702+
case 0x67:
36953703
return TERARKDB_NAMESPACE::Tickers::TICKER_ENUM_MAX;
36963704

36973705
default:

monitoring/statistics.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const std::vector<std::pair<Tickers, std::string>> TickersNameMap = {
2727
{BLOCK_CACHE_HIT, "rocksdb.block.cache.hit"},
2828
{BLOCK_CACHE_ADD, "rocksdb.block.cache.add"},
2929
{BLOCK_CACHE_ADD_FAILURES, "rocksdb.block.cache.add.failures"},
30+
{BLOCK_CACHE_ERASE, "rocksdb.block.cache.erase"},
31+
{BLOCK_CACHE_ERASE_FAILURES, "rocksdb.block.cache.erase.failures"},
3032
{BLOCK_CACHE_INDEX_MISS, "rocksdb.block.cache.index.miss"},
3133
{BLOCK_CACHE_INDEX_HIT, "rocksdb.block.cache.index.hit"},
3234
{BLOCK_CACHE_INDEX_ADD, "rocksdb.block.cache.index.add"},

table/block_based_table_reader.cc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

table/partitioned_filter_block.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ PartitionedFilterBlockReader::~PartitionedFilterBlockReader() {
148148
IndexBlockIter biter;
149149
BlockHandle handle;
150150
Statistics* kNullStats = nullptr;
151+
152+
uint64_t block_cache_erase_count = 0;
153+
uint64_t block_cache_erase_failures_count = 0;
154+
151155
idx_on_fltr_blk_->NewIterator<IndexBlockIter>(
152156
&comparator_, comparator_.user_comparator(), &biter, kNullStats, true,
153157
index_key_includes_seq_, index_value_is_full_);
@@ -157,8 +161,13 @@ PartitionedFilterBlockReader::~PartitionedFilterBlockReader() {
157161
auto key = BlockBasedTable::GetCacheKey(table_->rep_->cache_key_prefix,
158162
table_->rep_->cache_key_prefix_size,
159163
handle, cache_key);
160-
block_cache->Erase(key);
164+
bool erased = block_cache->Erase(key);
165+
++block_cache_erase_count;
166+
block_cache_erase_failures_count += !erased;
161167
}
168+
RecordTick(statistics(), BLOCK_CACHE_ERASE, block_cache_erase_count);
169+
RecordTick(statistics(), BLOCK_CACHE_ERASE_FAILURES,
170+
block_cache_erase_failures_count);
162171
}
163172

164173
bool PartitionedFilterBlockReader::KeyMayMatch(

table/table_reader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ class TableReader {
9999
bool (*callback_func)(void* arg, const Slice& key,
100100
LazyBuffer&& value));
101101

102-
virtual Status ForceEvict() {
103-
return Status::NotSupported();
104-
}
102+
virtual Status ForceEvict() { return Status::NotSupported(); }
105103

106104
// Prefetch data corresponding to a give range of keys
107105
// Typically this functionality is required for table implementations that

0 commit comments

Comments
 (0)