* Made the EventListener extend the Customizable class.
* EventListeners that have a non-empty Name() and that are registered with the ObjectRegistry can now be serialized to/from the OPTIONS file.
* Insert warm blocks (data blocks, uncompressed dict blocks, index and filter blocks) in Block cache during flush under option BlockBasedTableOptions.prepopulate_block_cache. Previously it was enabled for only data blocks.
+* BlockBasedTableOptions.prepopulate_block_cache can be dynamically configured using DB::SetOptions.
### Performance Improvements
* Try to avoid updating DBOptions if `SetDBOptions()` does not change any option value.
}
}
-// This test cache all types of blocks during flush.
+// This test cache data, index and filter blocks during flush.
TEST_F(DBBlockCacheTest, WarmCacheWithBlocksDuringFlush) {
Options options = CurrentOptions();
options.create_if_missing = true;
DestroyAndReopen(options);
std::string value(kValueSize, 'a');
- for (size_t i = 1; i < 2; i++) {
+ for (size_t i = 1; i <= kNumBlocks; i++) {
ASSERT_OK(Put(ToString(i), value));
ASSERT_OK(Flush());
ASSERT_EQ(i, options.statistics->getTickerCount(BLOCK_CACHE_DATA_ADD));
options.statistics->getTickerCount(BLOCK_CACHE_FILTER_HIT));
}
}
+
+TEST_F(DBBlockCacheTest, DynamicallyWarmCacheDuringFlush) {
+ Options options = CurrentOptions();
+ options.create_if_missing = true;
+ options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();
+
+ BlockBasedTableOptions table_options;
+ table_options.block_cache = NewLRUCache(1 << 25, 0, false);
+ table_options.cache_index_and_filter_blocks = false;
+ table_options.prepopulate_block_cache =
+ BlockBasedTableOptions::PrepopulateBlockCache::kFlushOnly;
+
+ options.table_factory.reset(NewBlockBasedTableFactory(table_options));
+ DestroyAndReopen(options);
+
+ std::string value(kValueSize, 'a');
+
+ for (size_t i = 1; i <= 5; i++) {
+ ASSERT_OK(Put(ToString(i), value));
+ ASSERT_OK(Flush());
+ ASSERT_EQ(1,
+ options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
+
+ ASSERT_EQ(value, Get(ToString(i)));
+ ASSERT_EQ(0,
+ options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
+ ASSERT_EQ(
+ 0, options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_MISS));
+ ASSERT_EQ(1,
+ options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_HIT));
+ }
+
+ ASSERT_OK(dbfull()->SetOptions(
+ {{"block_based_table_factory", "{prepopulate_block_cache=kDisable;}"}}));
+
+ for (size_t i = 6; i <= kNumBlocks; i++) {
+ ASSERT_OK(Put(ToString(i), value));
+ ASSERT_OK(Flush());
+ ASSERT_EQ(0,
+ options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
+
+ ASSERT_EQ(value, Get(ToString(i)));
+ ASSERT_EQ(1,
+ options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_ADD));
+ ASSERT_EQ(
+ 1, options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_MISS));
+ ASSERT_EQ(0,
+ options.statistics->getAndResetTickerCount(BLOCK_CACHE_DATA_HIT));
+ }
+}
#endif
namespace {
// further helps if the workload exhibits high temporal locality, where most
// of the reads go to recently written data. This also helps in case of
// Distributed FileSystem.
+ //
+ // This parameter can be changed dynamically by
+ // DB::SetOptions({{"block_based_table_factory",
+ // "{prepopulate_block_cache=kFlushOnly;}"}}));
enum class PrepopulateBlockCache : char {
// Disable prepopulate block cache.
kDisable,
// @param map The string to enum mapping for this enum
template <typename T>
static OptionTypeInfo Enum(
- int offset, const std::unordered_map<std::string, T>* const map) {
+ int offset, const std::unordered_map<std::string, T>* const map,
+ OptionTypeFlags flags = OptionTypeFlags::kNone) {
return OptionTypeInfo(
- offset, OptionType::kEnum, OptionVerificationType::kNormal,
- OptionTypeFlags::kNone,
+ offset, OptionType::kEnum, OptionVerificationType::kNormal, flags,
// Uses the map argument to convert the input string into
// its corresponding enum value. If value is found in the map,
// addr is updated to the corresponding map entry.