diff --git a/cache/cache_entry_roles.cc b/cache/cache_entry_roles.cc index 1aebedd24d..b27349554d 100644 --- a/cache/cache_entry_roles.cc +++ b/cache/cache_entry_roles.cc @@ -23,6 +23,7 @@ std::array kCacheEntryRoleToCamelString{{ "FilterConstruction", "BlockBasedTableReader", "FileMetadata", + "BlobValue", "BlobCache", "Misc", }}; @@ -39,6 +40,7 @@ std::array kCacheEntryRoleToHyphenString{{ "filter-construction", "block-based-table-reader", "file-metadata", + "blob-value", "blob-cache", "misc", }}; diff --git a/db/blob/blob_contents.cc b/db/blob/blob_contents.cc index df5e476594..50f6132de8 100644 --- a/db/blob/blob_contents.cc +++ b/db/blob/blob_contents.cc @@ -7,6 +7,7 @@ #include +#include "cache/cache_entry_roles.h" #include "cache/cache_helpers.h" #include "port/malloc.h" @@ -62,13 +63,10 @@ Status BlobContents::SaveToCallback(void* from_obj, size_t from_offset, return Status::OK(); } -void BlobContents::DeleteCallback(const Slice& key, void* value) { - DeleteCacheEntry(key, value); -} - Cache::CacheItemHelper* BlobContents::GetCacheItemHelper() { - static Cache::CacheItemHelper cache_helper(&SizeCallback, &SaveToCallback, - &DeleteCallback); + static Cache::CacheItemHelper cache_helper( + &SizeCallback, &SaveToCallback, + GetCacheEntryDeleterForRole()); return &cache_helper; } diff --git a/db/blob/blob_contents.h b/db/blob/blob_contents.h index 9ea9babf2e..02d0e3f188 100644 --- a/db/blob/blob_contents.h +++ b/db/blob/blob_contents.h @@ -40,8 +40,6 @@ class BlobContents { static Status SaveToCallback(void* from_obj, size_t from_offset, size_t length, void* out); - static void DeleteCallback(const Slice& key, void* value); - static Cache::CacheItemHelper* GetCacheItemHelper(); static Status CreateCallback(const void* buf, size_t size, void** out_obj, diff --git a/db/blob/blob_file_builder.cc b/db/blob/blob_file_builder.cc index 65939d3e39..a8e94b6f43 100644 --- a/db/blob/blob_file_builder.cc +++ b/db/blob/blob_file_builder.cc @@ -416,8 +416,12 @@ Status BlobFileBuilder::PutBlobIntoCacheIfNeeded(const Slice& blob, std::unique_ptr buf = BlobContents::Create(std::move(allocation), blob.size()); + Cache::CacheItemHelper* const cache_item_helper = + BlobContents::GetCacheItemHelper(); + assert(cache_item_helper); + s = blob_cache->Insert(key, buf.get(), buf->ApproximateMemoryUsage(), - &BlobContents::DeleteCallback, + cache_item_helper->del_cb, nullptr /* cache_handle */, priority); if (s.ok()) { RecordTick(statistics, BLOB_DB_CACHE_ADD); diff --git a/db/blob/blob_source.cc b/db/blob/blob_source.cc index f2571be90e..11a91d9e45 100644 --- a/db/blob/blob_source.cc +++ b/db/blob/blob_source.cc @@ -128,11 +128,15 @@ Status BlobSource::InsertEntryIntoCache(const Slice& key, BlobContents* value, Cache::Priority priority) const { Status s; + Cache::CacheItemHelper* const cache_item_helper = + BlobContents::GetCacheItemHelper(); + assert(cache_item_helper); + if (lowest_used_cache_tier_ == CacheTier::kNonVolatileBlockTier) { - s = blob_cache_->Insert(key, value, BlobContents::GetCacheItemHelper(), - charge, cache_handle, priority); + s = blob_cache_->Insert(key, value, cache_item_helper, charge, cache_handle, + priority); } else { - s = blob_cache_->Insert(key, value, charge, &BlobContents::DeleteCallback, + s = blob_cache_->Insert(key, value, charge, cache_item_helper->del_cb, cache_handle, priority); } diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index d38fc37c47..8bad61b523 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -600,7 +600,10 @@ enum class CacheEntryRole { kBlockBasedTableReader, // FileMetadata's charge to account for its memory usage kFileMetadata, - // Blob cache's charge to account for its memory usage + // Blob value (when using the same cache as block cache and blob cache) + kBlobValue, + // Blob cache's charge to account for its memory usage (when using a + // separate block cache and blob cache) kBlobCache, // Default bucket, for miscellaneous cache entries. Do not use for // entries that could potentially add up to large usage.