Feedback: use map for internal rep & miscs
This commit is contained in:
parent
e214d4ee1e
commit
eeff4a8ffd
@ -951,10 +951,9 @@ class ChargeFilterConstructionTestWithParam
|
||||
// calculation.
|
||||
constexpr std::size_t kCacheCapacity = 100 * 1024 * 1024;
|
||||
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged = charge_filter_construction_;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kFilterConstruction,
|
||||
{/*.charged = */ charge_filter_construction_}});
|
||||
table_options.filter_policy = Create(10, policy_);
|
||||
table_options.partition_filters = partition_filters_;
|
||||
if (table_options.partition_filters) {
|
||||
|
@ -1490,10 +1490,9 @@ TEST_F(DBSSTTest, OpenDBWithInfiniteMaxOpenFilesSubjectToMemoryLimit) {
|
||||
}
|
||||
Close();
|
||||
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]
|
||||
.charged = charge_table_reader;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kBlockBasedTableReader,
|
||||
{/*.charged = */ charge_table_reader}});
|
||||
table_options.block_cache =
|
||||
NewLRUCache(1024 /* capacity */, 0 /* num_shard_bits */,
|
||||
true /* strict_capacity_limit */);
|
||||
@ -1502,11 +1501,13 @@ TEST_F(DBSSTTest, OpenDBWithInfiniteMaxOpenFilesSubjectToMemoryLimit) {
|
||||
// Reopening the DB will try to load all existing files, conditionally
|
||||
// subject to memory limit
|
||||
Status s = TryReopen(options);
|
||||
if (table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]
|
||||
.charged == CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
|
||||
if (charge_table_reader == CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
EXPECT_TRUE(s.IsMemoryLimit());
|
||||
EXPECT_TRUE(s.ToString().find(
|
||||
kCacheEntryRoleToCamelString[static_cast<std::uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]) !=
|
||||
std::string::npos);
|
||||
EXPECT_TRUE(s.ToString().find("memory limit based on cache capacity") !=
|
||||
std::string::npos);
|
||||
|
||||
|
@ -2339,24 +2339,21 @@ void StressTest::Open(SharedState* shared) {
|
||||
block_based_options.block_cache_compressed = compressed_cache_;
|
||||
block_based_options.checksum = checksum_type_e;
|
||||
block_based_options.block_size = FLAGS_block_size;
|
||||
block_based_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer)]
|
||||
.charged = FLAGS_charge_compression_dictionary_building_buffer
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled;
|
||||
block_based_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged = FLAGS_charge_filter_construction
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled;
|
||||
block_based_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]
|
||||
.charged = FLAGS_charge_table_reader
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled;
|
||||
block_based_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kCompressionDictionaryBuildingBuffer,
|
||||
{/*.charged = */ FLAGS_charge_compression_dictionary_building_buffer
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
block_based_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kFilterConstruction,
|
||||
{/*.charged = */ FLAGS_charge_filter_construction
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
block_based_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kBlockBasedTableReader,
|
||||
{/*.charged = */ FLAGS_charge_table_reader
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
block_based_options.format_version =
|
||||
static_cast<uint32_t>(FLAGS_format_version);
|
||||
block_based_options.index_block_restart_interval =
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "rocksdb/cache.h"
|
||||
#include "rocksdb/customizable.h"
|
||||
@ -113,13 +112,14 @@ struct CacheEntryRoleOptions {
|
||||
kFallback,
|
||||
};
|
||||
Decision charged = Decision::kFallback;
|
||||
bool operator==(const CacheEntryRoleOptions& other) const {
|
||||
return charged == other.charged;
|
||||
}
|
||||
};
|
||||
|
||||
struct CacheUsageOptions {
|
||||
CacheEntryRoleOptions default_options;
|
||||
std::vector<CacheEntryRoleOptions> options_overrides =
|
||||
std::vector<CacheEntryRoleOptions>(kNumCacheEntryRoles,
|
||||
CacheEntryRoleOptions());
|
||||
CacheEntryRoleOptions options;
|
||||
std::map<CacheEntryRole, CacheEntryRoleOptions> options_overrides;
|
||||
};
|
||||
|
||||
// For advanced user only
|
||||
@ -306,53 +306,30 @@ struct BlockBasedTableOptions {
|
||||
uint64_t metadata_block_size = 4096;
|
||||
|
||||
// `cache_usage_options` allows users to specify the default
|
||||
// options (`cache_usage_options.default_options`) and the overrides
|
||||
// options (`cache_usage_options.options`) and the overriding
|
||||
// options (`cache_usage_options.options_overrides`)
|
||||
// for different `CacheEntryRole` under various features related to cache
|
||||
// usage.
|
||||
//
|
||||
// For a certain `CacheEntryRole r` and a certain feature `f` of
|
||||
// For a certain `CacheEntryRole role` and a certain feature `f` of
|
||||
// `CacheEntryRoleOptions`:
|
||||
// (a) If `options_overrides[static_cast<uint32_t>(role)].f !=
|
||||
// Decision::kFallback`, then it will be used to override the `Decision` value
|
||||
// of `cache_usage_options.default_options.f`.
|
||||
//
|
||||
// Example:
|
||||
// (a.1)
|
||||
// `options_overrides[static_cast<uint32_t>(CacheEntryRole::kBlockBasedTableReader)]
|
||||
// = {.charged = Decision::kEnabled}`
|
||||
// (a.2) `cache_usage_options.default_options.charged = Decision::kFallback`
|
||||
// (a.1) + (a.2) => the `CacheEntryRoleOptions::charged`
|
||||
// feature will be enabled for `CacheEntryRole::kBlockBasedTableReader`
|
||||
//
|
||||
// (b) If `options_overrides[static_cast<uint32_t>(role)].f ==
|
||||
// Decision::kFallback`, then the `Decision` value of
|
||||
// `cache_usage_options.default_options.f` will be used. If this default value
|
||||
// is set to `Decision::kFallback`, then the existing behavior will be in
|
||||
// effect. See "Features" below for the existing behaviors.
|
||||
//
|
||||
// Example:
|
||||
// (b.1)
|
||||
// `options_overrides[static_cast<uint32_t>(CacheEntryRole::kBlockBasedTableReader)]
|
||||
// = {.charged = Decision::kFallback}`
|
||||
// (b.2) `cache_usage_options.default_options.charged = Decision::kFallback`
|
||||
// (b.1) + (b.2) => the `CacheEntryRoleOptions::charged` feature will fallback
|
||||
// to the existing behavior for `CacheEntryRole::kBlockBasedTableReader`
|
||||
//
|
||||
// Features:
|
||||
// 1. If `options_overrides` has an entry for `role` and
|
||||
// `options_overrides[role].f != kFallback`, we use
|
||||
// `options_overrides[role].f`
|
||||
// 2. Otherwise, if `options[role].f != kFallback`, we use `options[role].f`
|
||||
// 3. Otherwise, we follow the compatible existing behavior for `f` (see below
|
||||
// for more)
|
||||
//
|
||||
// `cache_usage_options` currently supports specifying options for the
|
||||
// following features:
|
||||
//
|
||||
// 1. Memory charging to block cache (`CacheEntryRoleOptions::charged`)
|
||||
//
|
||||
// Memory charging is a feature of accounting memory usage of specific area
|
||||
// (represented by `CacheEntryRole`) toward usage in block cache (if
|
||||
// available), by updating a dynamical charge to the block cache loosely based
|
||||
// on the actual memory usage of that area.
|
||||
//
|
||||
// Existing behavior:
|
||||
//
|
||||
// (1) CacheEntryRole::kCompressionDictionaryBuildingBuffer : kEnabled
|
||||
// Charge memory usage of the buffered data used as training samples for
|
||||
// dictionary compression.
|
||||
@ -362,18 +339,20 @@ struct BlockBasedTableOptions {
|
||||
// unbuffered.
|
||||
//
|
||||
// (2) CacheEntryRole::kFilterConstruction : kDisabled
|
||||
// If enabled, charge memory usage of Bloom Filter (format_version >= 5) and
|
||||
// Ribbon Filter construction. If additional temporary memory of Ribbon Filter
|
||||
// exceeds the avaible space left in the block cache at some point (i.e,
|
||||
// causing a cache full under `LRUCacheOptions::strict_capacity_limit` =
|
||||
// true), construction will fall back to Bloom Filter.
|
||||
// Same as kDisabled - does not charge memory usage of Bloom Filter
|
||||
// (format_version >= 5) and Ribbon Filter construction. If enabled and if
|
||||
// additional temporary memory of Ribbon Filter exceeds the avaible space left
|
||||
// in the block cache at some point (i.e, causing a cache full under
|
||||
// `LRUCacheOptions::strict_capacity_limit` = true), construction will fall
|
||||
// back to Bloom Filter.
|
||||
//
|
||||
// (3) CacheEntryRole::kBlockBasedTableReader : kDisabled
|
||||
// If enabled, charge memory usage of table properties + index block/filter
|
||||
// block/uncompression dictionary if stored in table reader (i.e,
|
||||
// BlockBasedTableOptions::cache_index_and_filter_blocks == false)
|
||||
// along with some internal data structures during table reader creation.
|
||||
// If such a table reader exceeds
|
||||
// Same as kDisabled - does not charge memory usage of table properties +
|
||||
// index block/filter block/uncompression dictionary when stored in table
|
||||
// reader (i.e, BlockBasedTableOptions::cache_index_and_filter_blocks ==
|
||||
// false)
|
||||
// + some internal data structures during table reader creation.
|
||||
// If enabled and if such a table reader exceeds
|
||||
// the avaible space left in the block cache at some point (i.e, causing
|
||||
// a cache full under `LRUCacheOptions::strict_capacity_limit` = true),
|
||||
// creation will fail with Status::MemoryLimit().
|
||||
|
@ -462,11 +462,14 @@ struct BlockBasedTableBuilder::Rep {
|
||||
compression_opts.max_dict_buffer_bytes);
|
||||
}
|
||||
|
||||
const auto& compress_dict_build_buffer_charged =
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer)]
|
||||
.charged;
|
||||
const auto options_overrides_iter =
|
||||
table_options.cache_usage_options.options_overrides.find(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer);
|
||||
const auto compress_dict_build_buffer_charged =
|
||||
options_overrides_iter !=
|
||||
table_options.cache_usage_options.options_overrides.end()
|
||||
? options_overrides_iter->second.charged
|
||||
: table_options.cache_usage_options.options.charged;
|
||||
if (table_options.block_cache &&
|
||||
(compress_dict_build_buffer_charged ==
|
||||
CacheEntryRoleOptions::Decision::kEnabled ||
|
||||
@ -479,6 +482,7 @@ struct BlockBasedTableBuilder::Rep {
|
||||
} else {
|
||||
compression_dict_buffer_cache_res_mgr = nullptr;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < compression_opts.parallel_threads; i++) {
|
||||
compression_ctxs[i].reset(new CompressionContext(compression_type));
|
||||
}
|
||||
|
@ -422,11 +422,16 @@ BlockBasedTableFactory::BlockBasedTableFactory(
|
||||
InitializeOptions();
|
||||
RegisterOptions(&table_options_, &block_based_table_type_info);
|
||||
|
||||
const auto options_overrides_iter =
|
||||
table_options_.cache_usage_options.options_overrides.find(
|
||||
CacheEntryRole::kBlockBasedTableReader);
|
||||
const auto table_reader_charged =
|
||||
options_overrides_iter !=
|
||||
table_options_.cache_usage_options.options_overrides.end()
|
||||
? options_overrides_iter->second.charged
|
||||
: table_options_.cache_usage_options.options.charged;
|
||||
if (table_options_.block_cache &&
|
||||
table_options_.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]
|
||||
.charged == CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
table_reader_charged == CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
table_reader_cache_res_mgr_.reset(new ConcurrentCacheReservationManager(
|
||||
std::make_shared<CacheReservationManagerImpl<
|
||||
CacheEntryRole::kBlockBasedTableReader>>(
|
||||
@ -470,15 +475,17 @@ void BlockBasedTableFactory::InitializeOptions() {
|
||||
// We do not support partitioned filters without partitioning indexes
|
||||
table_options_.partition_filters = false;
|
||||
}
|
||||
auto& cache_usage_overrides_options =
|
||||
auto& options_overrides =
|
||||
table_options_.cache_usage_options.options_overrides;
|
||||
const auto& cache_usage_default_options =
|
||||
table_options_.cache_usage_options.default_options;
|
||||
for (std::size_t i = 0; i < cache_usage_overrides_options.size(); ++i) {
|
||||
CacheEntryRoleOptions& override_options = cache_usage_overrides_options[i];
|
||||
if (override_options.charged ==
|
||||
CacheEntryRoleOptions::Decision::kFallback) {
|
||||
override_options.charged = cache_usage_default_options.charged;
|
||||
const auto options = table_options_.cache_usage_options.options;
|
||||
for (std::uint32_t i = 0; i < kNumCacheEntryRoles; ++i) {
|
||||
CacheEntryRole role = static_cast<CacheEntryRole>(i);
|
||||
auto options_overrides_iter = options_overrides.find(role);
|
||||
if (options_overrides_iter == options_overrides.end()) {
|
||||
options_overrides.insert({role, options});
|
||||
} else if (options_overrides_iter->second.charged ==
|
||||
CacheEntryRoleOptions::Decision::kFallback) {
|
||||
options_overrides_iter->second.charged = options.charged;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -678,27 +685,30 @@ Status BlockBasedTableFactory::ValidateOptions(
|
||||
}
|
||||
const auto& options_overrides =
|
||||
table_options_.cache_usage_options.options_overrides;
|
||||
for (std::size_t i = 0; i < options_overrides.size(); ++i) {
|
||||
const CacheEntryRoleOptions& cache_entry_role_option = options_overrides[i];
|
||||
for (auto options_overrides_iter = options_overrides.cbegin();
|
||||
options_overrides_iter != options_overrides.cend();
|
||||
++options_overrides_iter) {
|
||||
const CacheEntryRole role = options_overrides_iter->first;
|
||||
const CacheEntryRoleOptions options = options_overrides_iter->second;
|
||||
static const std::set<CacheEntryRole> kMemoryChargingSupported = {
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer,
|
||||
CacheEntryRole::kFilterConstruction,
|
||||
CacheEntryRole::kBlockBasedTableReader};
|
||||
if (cache_entry_role_option.charged !=
|
||||
CacheEntryRoleOptions::Decision::kFallback &&
|
||||
kMemoryChargingSupported.count(static_cast<CacheEntryRole>(i)) == 0) {
|
||||
if (options.charged != CacheEntryRoleOptions::Decision::kFallback &&
|
||||
kMemoryChargingSupported.count(role) == 0) {
|
||||
return Status::NotSupported(
|
||||
"Enable/Disable CacheEntryRoleOptions::charged"
|
||||
"for CacheEntryRole " +
|
||||
kCacheEntryRoleToCamelString[i] + " is not supported");
|
||||
kCacheEntryRoleToCamelString[static_cast<uint32_t>(role)] +
|
||||
" is not supported");
|
||||
}
|
||||
if (table_options_.no_block_cache &&
|
||||
cache_entry_role_option.charged ==
|
||||
CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
options.charged == CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
return Status::InvalidArgument(
|
||||
"Enable CacheEntryRoleOptions::charged"
|
||||
"for CacheEntryRole " +
|
||||
kCacheEntryRoleToCamelString[i] + " but block cache is disabled");
|
||||
kCacheEntryRoleToCamelString[static_cast<uint32_t>(role)] +
|
||||
" but block cache is disabled");
|
||||
}
|
||||
}
|
||||
{
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -717,7 +718,10 @@ Status BlockBasedTable::Open(
|
||||
mem_usage, &(rep->table_reader_cache_res_handle));
|
||||
if (s.IsIncomplete()) {
|
||||
s = Status::MemoryLimit(
|
||||
"Can't allocate BlockBasedTableReader due to memory limit based on "
|
||||
"Can't allocate " +
|
||||
kCacheEntryRoleToCamelString[static_cast<std::uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)] +
|
||||
" due to memory limit based on "
|
||||
"cache capacity for memory allocation");
|
||||
}
|
||||
}
|
||||
|
@ -345,10 +345,9 @@ class ChargeTableReaderTest
|
||||
|
||||
void ConfigureTableFactory() override {
|
||||
BlockBasedTableOptions table_options;
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]
|
||||
.charged = charge_table_reader_;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kBlockBasedTableReader,
|
||||
{/*.charged = */ charge_table_reader_}});
|
||||
table_options.block_cache = table_reader_charge_tracking_cache_;
|
||||
|
||||
table_options.cache_index_and_filter_blocks = false;
|
||||
@ -441,6 +440,10 @@ TEST_P(ChargeTableReaderTest, Basic) {
|
||||
|
||||
if (charge_table_reader_ == CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
EXPECT_TRUE(s.IsMemoryLimit()) << "s: " << s.ToString();
|
||||
EXPECT_TRUE(s.ToString().find(
|
||||
kCacheEntryRoleToCamelString[static_cast<std::uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]) !=
|
||||
std::string::npos);
|
||||
EXPECT_TRUE(s.ToString().find("memory limit based on cache capacity") !=
|
||||
std::string::npos);
|
||||
|
||||
|
@ -1483,14 +1483,19 @@ std::string BloomFilterPolicy::GetId() const {
|
||||
FilterBitsBuilder* BloomLikeFilterPolicy::GetFastLocalBloomBuilderWithContext(
|
||||
const FilterBuildingContext& context) const {
|
||||
bool offm = context.table_options.optimize_filters_for_memory;
|
||||
bool reserve_filter_construction_mem =
|
||||
(context.table_options.block_cache &&
|
||||
context.table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged == CacheEntryRoleOptions::Decision::kEnabled);
|
||||
const auto options_overrides_iter =
|
||||
context.table_options.cache_usage_options.options_overrides.find(
|
||||
CacheEntryRole::kFilterConstruction);
|
||||
const auto filter_construction_charged =
|
||||
options_overrides_iter !=
|
||||
context.table_options.cache_usage_options.options_overrides.end()
|
||||
? options_overrides_iter->second.charged
|
||||
: context.table_options.cache_usage_options.options.charged;
|
||||
|
||||
std::shared_ptr<CacheReservationManager> cache_res_mgr;
|
||||
if (reserve_filter_construction_mem) {
|
||||
if (context.table_options.block_cache &&
|
||||
filter_construction_charged ==
|
||||
CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
cache_res_mgr = std::make_shared<
|
||||
CacheReservationManagerImpl<CacheEntryRole::kFilterConstruction>>(
|
||||
context.table_options.block_cache);
|
||||
@ -1528,14 +1533,19 @@ BloomLikeFilterPolicy::GetStandard128RibbonBuilderWithContext(
|
||||
const FilterBuildingContext& context) const {
|
||||
// FIXME: code duplication with GetFastLocalBloomBuilderWithContext
|
||||
bool offm = context.table_options.optimize_filters_for_memory;
|
||||
bool reserve_filter_construction_mem =
|
||||
(context.table_options.block_cache &&
|
||||
context.table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged == CacheEntryRoleOptions::Decision::kEnabled);
|
||||
const auto options_overrides_iter =
|
||||
context.table_options.cache_usage_options.options_overrides.find(
|
||||
CacheEntryRole::kFilterConstruction);
|
||||
const auto filter_construction_charged =
|
||||
options_overrides_iter !=
|
||||
context.table_options.cache_usage_options.options_overrides.end()
|
||||
? options_overrides_iter->second.charged
|
||||
: context.table_options.cache_usage_options.options.charged;
|
||||
|
||||
std::shared_ptr<CacheReservationManager> cache_res_mgr;
|
||||
if (reserve_filter_construction_mem) {
|
||||
if (context.table_options.block_cache &&
|
||||
filter_construction_charged ==
|
||||
CacheEntryRoleOptions::Decision::kEnabled) {
|
||||
cache_res_mgr = std::make_shared<
|
||||
CacheReservationManagerImpl<CacheEntryRole::kFilterConstruction>>(
|
||||
context.table_options.block_cache);
|
||||
|
@ -5214,10 +5214,9 @@ TEST_F(ChargeCompressionDictionaryBuildingBufferTest, Basic) {
|
||||
table_options.block_cache = cache;
|
||||
table_options.flush_block_policy_factory =
|
||||
std::make_shared<FlushBlockEveryKeyPolicyFactory>();
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer)]
|
||||
.charged = charge_compression_dictionary_building_buffer;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kCompressionDictionaryBuildingBuffer,
|
||||
{/*.charged = */ charge_compression_dictionary_building_buffer}});
|
||||
Options options;
|
||||
options.compression = kSnappyCompression;
|
||||
options.compression_opts.max_dict_bytes = kMaxDictBytes;
|
||||
@ -5282,6 +5281,8 @@ TEST_F(ChargeCompressionDictionaryBuildingBufferTest,
|
||||
constexpr std::size_t kMaxDictBytes = 1024;
|
||||
constexpr std::size_t kMaxDictBufferBytes = 2 * kSizeDummyEntry;
|
||||
|
||||
// `CacheEntryRoleOptions::charged` is enabled by default for
|
||||
// CacheEntryRole::kCompressionDictionaryBuildingBuffer
|
||||
BlockBasedTableOptions table_options;
|
||||
LRUCacheOptions lo;
|
||||
lo.capacity = kCacheCapacity;
|
||||
@ -5291,10 +5292,6 @@ TEST_F(ChargeCompressionDictionaryBuildingBufferTest,
|
||||
table_options.block_cache = cache;
|
||||
table_options.flush_block_policy_factory =
|
||||
std::make_shared<FlushBlockEveryKeyPolicyFactory>();
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer)]
|
||||
.charged = CacheEntryRoleOptions::Decision::kEnabled;
|
||||
|
||||
Options options;
|
||||
options.compression = kSnappyCompression;
|
||||
@ -5369,6 +5366,8 @@ TEST_F(ChargeCompressionDictionaryBuildingBufferTest, BasicWithCacheFull) {
|
||||
// (key2, value2) won't exceed the buffer limit
|
||||
constexpr std::size_t kMaxDictBufferBytes = 1024 * 1024 * 1024;
|
||||
|
||||
// `CacheEntryRoleOptions::charged` is enabled by default for
|
||||
// CacheEntryRole::kCompressionDictionaryBuildingBuffer
|
||||
BlockBasedTableOptions table_options;
|
||||
LRUCacheOptions lo;
|
||||
lo.capacity = kCacheCapacity;
|
||||
@ -5378,10 +5377,6 @@ TEST_F(ChargeCompressionDictionaryBuildingBufferTest, BasicWithCacheFull) {
|
||||
table_options.block_cache = cache;
|
||||
table_options.flush_block_policy_factory =
|
||||
std::make_shared<FlushBlockEveryKeyPolicyFactory>();
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer)]
|
||||
.charged = CacheEntryRoleOptions::Decision::kEnabled;
|
||||
|
||||
Options options;
|
||||
options.compression = kSnappyCompression;
|
||||
@ -5452,26 +5447,36 @@ class CacheUsageOptionsOverridesTest : public DBTestBase {
|
||||
};
|
||||
|
||||
TEST_F(CacheUsageOptionsOverridesTest, SanitizeAndValidateOptions) {
|
||||
// To test `default_options` is used when no `options_overrides` is specified
|
||||
// To test `cache_usage_options.options_overrides` is sanitized
|
||||
// where `cache_usage_options.options` is used when there is no entry in
|
||||
// `cache_usage_options.options_overrides`
|
||||
Options options;
|
||||
options.create_if_missing = true;
|
||||
BlockBasedTableOptions table_options = BlockBasedTableOptions();
|
||||
table_options.cache_usage_options.default_options.charged =
|
||||
CacheEntryRoleOptions::Decision::kEnabled;
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
Destroy(options);
|
||||
Status s = TryReopen(options);
|
||||
EXPECT_TRUE(s.IsNotSupported());
|
||||
EXPECT_TRUE(
|
||||
s.ToString().find("Enable/Disable CacheEntryRoleOptions::charged") !=
|
||||
std::string::npos);
|
||||
EXPECT_TRUE(s.ok());
|
||||
const auto* sanitized_table_options =
|
||||
options.table_factory->GetOptions<BlockBasedTableOptions>();
|
||||
const auto sanitized_options_overrides =
|
||||
sanitized_table_options->cache_usage_options.options_overrides;
|
||||
EXPECT_EQ(sanitized_options_overrides.size(), kNumCacheEntryRoles);
|
||||
for (auto options_overrides_iter = sanitized_options_overrides.cbegin();
|
||||
options_overrides_iter != sanitized_options_overrides.cend();
|
||||
++options_overrides_iter) {
|
||||
CacheEntryRoleOptions role_options = options_overrides_iter->second;
|
||||
CacheEntryRoleOptions default_options =
|
||||
sanitized_table_options->cache_usage_options.options;
|
||||
EXPECT_TRUE(role_options == default_options);
|
||||
}
|
||||
Destroy(options);
|
||||
|
||||
// To test option validation on unsupported CacheEntryRole
|
||||
table_options = BlockBasedTableOptions();
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(CacheEntryRole::kDataBlock)]
|
||||
.charged = CacheEntryRoleOptions::Decision::kDisabled;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kDataBlock,
|
||||
{/*.charged = */ CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
Destroy(options);
|
||||
s = TryReopen(options);
|
||||
@ -5487,10 +5492,9 @@ TEST_F(CacheUsageOptionsOverridesTest, SanitizeAndValidateOptions) {
|
||||
// To test option validation on existence of block cache
|
||||
table_options = BlockBasedTableOptions();
|
||||
table_options.no_block_cache = true;
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged = CacheEntryRoleOptions::Decision::kEnabled;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kFilterConstruction,
|
||||
{/*.charged = */ CacheEntryRoleOptions::Decision::kEnabled}});
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
Destroy(options);
|
||||
s = TryReopen(options);
|
||||
|
@ -4172,24 +4172,21 @@ class Benchmark {
|
||||
true;
|
||||
}
|
||||
block_based_options.block_cache = cache_;
|
||||
block_based_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kCompressionDictionaryBuildingBuffer)]
|
||||
.charged = FLAGS_charge_compression_dictionary_building_buffer
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled;
|
||||
block_based_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged = FLAGS_charge_filter_construction
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled;
|
||||
block_based_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kBlockBasedTableReader)]
|
||||
.charged = FLAGS_charge_table_reader
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled;
|
||||
block_based_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kCompressionDictionaryBuildingBuffer,
|
||||
{/*.charged = */ FLAGS_charge_compression_dictionary_building_buffer
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
block_based_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kFilterConstruction,
|
||||
{/*.charged = */ FLAGS_charge_filter_construction
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
block_based_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kBlockBasedTableReader,
|
||||
{/*.charged = */ FLAGS_charge_table_reader
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
block_based_options.block_cache_compressed = compressed_cache_;
|
||||
block_based_options.block_size = FLAGS_block_size;
|
||||
block_based_options.block_restart_interval = FLAGS_block_restart_interval;
|
||||
|
@ -632,10 +632,9 @@ TEST_F(ChargeFilterConstructionTest, RibbonFilterFallBackOnLargeBanding) {
|
||||
CacheEntryRoleOptions::Decision::kEnabled;
|
||||
|
||||
BlockBasedTableOptions table_options;
|
||||
table_options.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged = charge_filter_construction_mem;
|
||||
table_options.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kFilterConstruction,
|
||||
{/*.charged = */ charge_filter_construction_mem}});
|
||||
LRUCacheOptions lo;
|
||||
lo.capacity = kCacheCapacity;
|
||||
lo.num_shard_bits = 0; // 2^0 shard
|
||||
|
@ -325,11 +325,12 @@ struct FilterBench : public MockBlockBasedTableTester {
|
||||
FLAGS_optimize_filters_for_memory;
|
||||
table_options_.detect_filter_construct_corruption =
|
||||
FLAGS_detect_filter_construct_corruption;
|
||||
table_options_.cache_usage_options.options_overrides.insert(
|
||||
{CacheEntryRole::kFilterConstruction,
|
||||
{/*.charged = */ FLAGS_charge_filter_construction
|
||||
? CacheEntryRoleOptions::Decision::kEnabled
|
||||
: CacheEntryRoleOptions::Decision::kDisabled}});
|
||||
if (FLAGS_charge_filter_construction) {
|
||||
table_options_.cache_usage_options
|
||||
.options_overrides[static_cast<uint32_t>(
|
||||
CacheEntryRole::kFilterConstruction)]
|
||||
.charged = CacheEntryRoleOptions::Decision::kEnabled;
|
||||
table_options_.no_block_cache = false;
|
||||
LRUCacheOptions lo;
|
||||
lo.capacity = FLAGS_block_cache_capacity_MB * 1024 * 1024;
|
||||
|
Loading…
x
Reference in New Issue
Block a user