mirror of
https://github.com/facebook/rocksdb.git
synced 2024-12-03 05:54:17 +00:00
91b95cadee
Summary: Context: Some data blocks are temporarily buffered in memory in BlockBasedTableBuilder for building compression dictionary used in data block compression. Currently this memory usage is not counted toward our global memory usage utilizing block cache capacity. To improve that, this PR charges that memory usage into the block cache to achieve better memory tracking and limiting. - Reserve memory in block cache for buffered data blocks that are used to build a compression dictionary - Release all the memory associated with buffering the data blocks mentioned above in EnterUnbuffered(), which is called when (a) buffer limit is exceeded after buffering OR (b) the block cache becomes full after reservation OR (c) BlockBasedTableBuilder calls Finish() Pull Request resolved: https://github.com/facebook/rocksdb/pull/8428 Test Plan: - Passing existing unit tests - Passing new unit tests Reviewed By: ajkr Differential Revision: D30755305 Pulled By: hx235 fbshipit-source-id: 6e66665020b775154a94c4c5e0f2adaeaff13981
69 lines
1.7 KiB
C++
69 lines
1.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<const char*, kNumCacheEntryRoles> kCacheEntryRoleToCamelString{{
|
|
"DataBlock",
|
|
"FilterBlock",
|
|
"FilterMetaBlock",
|
|
"DeprecatedFilterBlock",
|
|
"IndexBlock",
|
|
"OtherBlock",
|
|
"WriteBuffer",
|
|
"CompressionDictionaryBuildingBuffer",
|
|
"Misc",
|
|
}};
|
|
|
|
std::array<const char*, kNumCacheEntryRoles> kCacheEntryRoleToHyphenString{{
|
|
"data-block",
|
|
"filter-block",
|
|
"filter-meta-block",
|
|
"deprecated-filter-block",
|
|
"index-block",
|
|
"other-block",
|
|
"write-buffer",
|
|
"compression-dictionary-building-buffer",
|
|
"misc",
|
|
}};
|
|
|
|
namespace {
|
|
|
|
struct Registry {
|
|
std::mutex mutex;
|
|
std::unordered_map<Cache::DeleterFn, CacheEntryRole> role_map;
|
|
void Register(Cache::DeleterFn fn, CacheEntryRole role) {
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
role_map[fn] = role;
|
|
}
|
|
std::unordered_map<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);
|
|
}
|
|
|
|
std::unordered_map<Cache::DeleterFn, CacheEntryRole> CopyCacheDeleterRoleMap() {
|
|
return GetRegistry().Copy();
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|