mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-28 15:33:54 +00:00
7818560194
Summary: The patch adds a dedicated cache entry role for blob values and switches to a registered deleter so that blobs show up as a separate bucket (as opposed to "Misc") in the cache occupancy statistics, e.g. ``` Block cache entry stats(count,size,portion): DataBlock(133515,531.73 MB,13.6866%) BlobValue(1824855,3.10 GB,81.7071%) Misc(1,0.00 KB,0%) ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/10601 Test Plan: Ran `make check` and tested the cache occupancy statistics using `db_bench`. Reviewed By: riversand963 Differential Revision: D39107915 Pulled By: ltamasi fbshipit-source-id: 8446c3b190a41a144030df73f318eeda4398c125
135 lines
3.7 KiB
C++
135 lines
3.7 KiB
C++
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#include "cache/cache_entry_roles.h"
|
|
|
|
#include <mutex>
|
|
|
|
#include "port/lang.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
std::array<std::string, kNumCacheEntryRoles> kCacheEntryRoleToCamelString{{
|
|
"DataBlock",
|
|
"FilterBlock",
|
|
"FilterMetaBlock",
|
|
"DeprecatedFilterBlock",
|
|
"IndexBlock",
|
|
"OtherBlock",
|
|
"WriteBuffer",
|
|
"CompressionDictionaryBuildingBuffer",
|
|
"FilterConstruction",
|
|
"BlockBasedTableReader",
|
|
"FileMetadata",
|
|
"BlobValue",
|
|
"BlobCache",
|
|
"Misc",
|
|
}};
|
|
|
|
std::array<std::string, kNumCacheEntryRoles> kCacheEntryRoleToHyphenString{{
|
|
"data-block",
|
|
"filter-block",
|
|
"filter-meta-block",
|
|
"deprecated-filter-block",
|
|
"index-block",
|
|
"other-block",
|
|
"write-buffer",
|
|
"compression-dictionary-building-buffer",
|
|
"filter-construction",
|
|
"block-based-table-reader",
|
|
"file-metadata",
|
|
"blob-value",
|
|
"blob-cache",
|
|
"misc",
|
|
}};
|
|
|
|
const std::string& GetCacheEntryRoleName(CacheEntryRole role) {
|
|
return kCacheEntryRoleToHyphenString[static_cast<size_t>(role)];
|
|
}
|
|
|
|
const std::string& BlockCacheEntryStatsMapKeys::CacheId() {
|
|
static const std::string kCacheId = "id";
|
|
return kCacheId;
|
|
}
|
|
|
|
const std::string& BlockCacheEntryStatsMapKeys::CacheCapacityBytes() {
|
|
static const std::string kCacheCapacityBytes = "capacity";
|
|
return kCacheCapacityBytes;
|
|
}
|
|
|
|
const std::string&
|
|
BlockCacheEntryStatsMapKeys::LastCollectionDurationSeconds() {
|
|
static const std::string kLastCollectionDurationSeconds =
|
|
"secs_for_last_collection";
|
|
return kLastCollectionDurationSeconds;
|
|
}
|
|
|
|
const std::string& BlockCacheEntryStatsMapKeys::LastCollectionAgeSeconds() {
|
|
static const std::string kLastCollectionAgeSeconds =
|
|
"secs_since_last_collection";
|
|
return kLastCollectionAgeSeconds;
|
|
}
|
|
|
|
namespace {
|
|
|
|
std::string GetPrefixedCacheEntryRoleName(const std::string& prefix,
|
|
CacheEntryRole role) {
|
|
const std::string& role_name = GetCacheEntryRoleName(role);
|
|
std::string prefixed_role_name;
|
|
prefixed_role_name.reserve(prefix.size() + role_name.size());
|
|
prefixed_role_name.append(prefix);
|
|
prefixed_role_name.append(role_name);
|
|
return prefixed_role_name;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
std::string BlockCacheEntryStatsMapKeys::EntryCount(CacheEntryRole role) {
|
|
const static std::string kPrefix = "count.";
|
|
return GetPrefixedCacheEntryRoleName(kPrefix, role);
|
|
}
|
|
|
|
std::string BlockCacheEntryStatsMapKeys::UsedBytes(CacheEntryRole role) {
|
|
const static std::string kPrefix = "bytes.";
|
|
return GetPrefixedCacheEntryRoleName(kPrefix, role);
|
|
}
|
|
|
|
std::string BlockCacheEntryStatsMapKeys::UsedPercent(CacheEntryRole role) {
|
|
const static std::string kPrefix = "percent.";
|
|
return GetPrefixedCacheEntryRoleName(kPrefix, role);
|
|
}
|
|
|
|
namespace {
|
|
|
|
struct Registry {
|
|
std::mutex mutex;
|
|
UnorderedMap<Cache::DeleterFn, CacheEntryRole> role_map;
|
|
void Register(Cache::DeleterFn fn, CacheEntryRole role) {
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
role_map[fn] = role;
|
|
}
|
|
UnorderedMap<Cache::DeleterFn, CacheEntryRole> Copy() {
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
return role_map;
|
|
}
|
|
};
|
|
|
|
Registry& GetRegistry() {
|
|
STATIC_AVOID_DESTRUCTION(Registry, registry);
|
|
return registry;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void RegisterCacheDeleterRole(Cache::DeleterFn fn, CacheEntryRole role) {
|
|
GetRegistry().Register(fn, role);
|
|
}
|
|
|
|
UnorderedMap<Cache::DeleterFn, CacheEntryRole> CopyCacheDeleterRoleMap() {
|
|
return GetRegistry().Copy();
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|