|
|
|
@ -1436,6 +1436,107 @@ TEST_F(DBPropertiesTest, SstFilesSize) { |
|
|
|
|
ASSERT_TRUE(listener->callback_triggered); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(DBPropertiesTest, BlockCacheProperties) { |
|
|
|
|
Options options; |
|
|
|
|
uint64_t value; |
|
|
|
|
|
|
|
|
|
// Block cache properties are not available for tables other than
|
|
|
|
|
// block-based table.
|
|
|
|
|
options.table_factory.reset(NewPlainTableFactory()); |
|
|
|
|
Reopen(options); |
|
|
|
|
ASSERT_FALSE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_FALSE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
ASSERT_FALSE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
|
|
|
|
|
options.table_factory.reset(NewCuckooTableFactory()); |
|
|
|
|
Reopen(options); |
|
|
|
|
ASSERT_FALSE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_FALSE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
ASSERT_FALSE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
|
|
|
|
|
// Block cache properties are not available if block cache is not used.
|
|
|
|
|
BlockBasedTableOptions table_options; |
|
|
|
|
table_options.no_block_cache = true; |
|
|
|
|
options.table_factory.reset(NewBlockBasedTableFactory(table_options)); |
|
|
|
|
Reopen(options); |
|
|
|
|
ASSERT_FALSE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_FALSE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
ASSERT_FALSE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
|
|
|
|
|
// Test with empty block cache.
|
|
|
|
|
constexpr size_t kCapacity = 100; |
|
|
|
|
auto block_cache = NewLRUCache(kCapacity, 0 /*num_shard_bits*/); |
|
|
|
|
table_options.block_cache = block_cache; |
|
|
|
|
table_options.no_block_cache = false; |
|
|
|
|
options.table_factory.reset(NewBlockBasedTableFactory(table_options)); |
|
|
|
|
Reopen(options); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_EQ(kCapacity, value); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
ASSERT_EQ(0, value); |
|
|
|
|
ASSERT_TRUE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
ASSERT_EQ(0, value); |
|
|
|
|
|
|
|
|
|
// Insert unpinned item to the cache and check size.
|
|
|
|
|
constexpr size_t kSize1 = 50; |
|
|
|
|
block_cache->Insert("item1", nullptr /*value*/, kSize1, nullptr /*deleter*/); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_EQ(kCapacity, value); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
ASSERT_EQ(kSize1, value); |
|
|
|
|
ASSERT_TRUE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
ASSERT_EQ(0, value); |
|
|
|
|
|
|
|
|
|
// Insert pinned item to the cache and check size.
|
|
|
|
|
constexpr size_t kSize2 = 30; |
|
|
|
|
Cache::Handle* item2 = nullptr; |
|
|
|
|
block_cache->Insert("item2", nullptr /*value*/, kSize2, nullptr /*deleter*/, |
|
|
|
|
&item2); |
|
|
|
|
ASSERT_NE(nullptr, item2); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_EQ(kCapacity, value); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
ASSERT_EQ(kSize1 + kSize2, value); |
|
|
|
|
ASSERT_TRUE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
ASSERT_EQ(kSize2, value); |
|
|
|
|
|
|
|
|
|
// Insert another pinned item to make the cache over-sized.
|
|
|
|
|
constexpr size_t kSize3 = 80; |
|
|
|
|
Cache::Handle* item3 = nullptr; |
|
|
|
|
block_cache->Insert("item3", nullptr /*value*/, kSize3, nullptr /*deleter*/, |
|
|
|
|
&item3); |
|
|
|
|
ASSERT_NE(nullptr, item2); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_EQ(kCapacity, value); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
// Item 1 is evicted.
|
|
|
|
|
ASSERT_EQ(kSize2 + kSize3, value); |
|
|
|
|
ASSERT_TRUE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
ASSERT_EQ(kSize2 + kSize3, value); |
|
|
|
|
|
|
|
|
|
// Check size after release.
|
|
|
|
|
block_cache->Release(item2); |
|
|
|
|
block_cache->Release(item3); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheCapacity, &value)); |
|
|
|
|
ASSERT_EQ(kCapacity, value); |
|
|
|
|
ASSERT_TRUE(db_->GetIntProperty(DB::Properties::kBlockCacheUsage, &value)); |
|
|
|
|
// item2 will be evicted, while item3 remain in cache after release.
|
|
|
|
|
ASSERT_EQ(kSize3, value); |
|
|
|
|
ASSERT_TRUE( |
|
|
|
|
db_->GetIntProperty(DB::Properties::kBlockCachePinnedUsage, &value)); |
|
|
|
|
ASSERT_EQ(0, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
|
|