diff --git a/cache/cache_entry_roles.cc b/cache/cache_entry_roles.cc index 1aebedd24d814b6bdd5d1b2dee90e8e5b3ce26f7..b27349554d32a4b04ee28f5d3afe7c5853d3a604 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 df5e47659469eca43c7544d6b0051aa11e3d3f31..50f6132de8f112f0dfaa4efee1f246e033363507 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 9ea9babf2eb5215a271334f0272af32990a1c22a..02d0e3f18841537d72545d95aa1abd25eb0ed32e 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 65939d3e39e77119ba994ff35035ef4f183a18fa..a8e94b6f43e5f3334db925c28ef200e7313b68de 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 f2571be90e7341b9f441ed45db5246caf9d1948d..11a91d9e4542064a6bd4f948e63b60fb085ebd20 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 d38fc37c475d55d380d3b8485238b131b7fec22d..8bad61b523fc36252a77b6822f73c3d474109edb 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.