diff options
Diffstat (limited to 'cache/tiered_secondary_cache_test.cc')
-rw-r--r-- | cache/tiered_secondary_cache_test.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cache/tiered_secondary_cache_test.cc b/cache/tiered_secondary_cache_test.cc index e4b420226..f38a358ad 100644 --- a/cache/tiered_secondary_cache_test.cc +++ b/cache/tiered_secondary_cache_test.cc @@ -765,6 +765,54 @@ TEST_F(DBTieredSecondaryCacheTest, IterateTest) { Destroy(options); } +TEST_F(DBTieredSecondaryCacheTest, VolatileTierTest) { + if (!LZ4_Supported()) { + ROCKSDB_GTEST_SKIP("This test requires LZ4 support."); + return; + } + + BlockBasedTableOptions table_options; + // We want a block cache of size 5KB, and a compressed secondary cache of + // size 5KB. However, we specify a block cache size of 256KB here in order + // to take into account the cache reservation in the block cache on + // behalf of the compressed cache. The unit of cache reservation is 256KB. + // The effective block cache capacity will be calculated as 256 + 5 = 261KB, + // and 256KB will be reserved for the compressed cache, leaving 5KB for + // the primary block cache. We only have to worry about this here because + // the cache size is so small. + table_options.block_cache = NewCache(256 * 1024, 5 * 1024, 256 * 1024); + table_options.block_size = 4 * 1024; + table_options.cache_index_and_filter_blocks = false; + Options options = GetDefaultOptions(); + options.create_if_missing = true; + options.compression = kLZ4Compression; + options.table_factory.reset(NewBlockBasedTableFactory(table_options)); + + // Disable paranoid_file_checks so that flush will not read back the newly + // written file + options.paranoid_file_checks = false; + options.lowest_used_cache_tier = CacheTier::kVolatileTier; + DestroyAndReopen(options); + Random rnd(301); + const int N = 256; + for (int i = 0; i < N; i++) { + std::string p_v; + test::CompressibleString(&rnd, 0.5, 1007, &p_v); + ASSERT_OK(Put(Key(i), p_v)); + } + + ASSERT_OK(Flush()); + + // Since lowest_used_cache_tier is the volatile tier, nothing should be + // inserted in the secondary cache. + std::string v = Get(Key(0)); + ASSERT_EQ(1007, v.size()); + ASSERT_EQ(nvm_sec_cache()->num_insert_saved(), 0u); + ASSERT_EQ(nvm_sec_cache()->num_misses(), 0u); + + Destroy(options); +} + class DBTieredAdmPolicyTest : public DBTieredSecondaryCacheTest, public testing::WithParamInterface<TieredAdmissionPolicy> {}; |