@ -15,7 +15,6 @@
# include "cache/cache_entry_roles.h"
# include "cache/cache_entry_roles.h"
# include "rocksdb/cache.h"
# include "rocksdb/cache.h"
# include "rocksdb/slice.h"
# include "rocksdb/slice.h"
# include "table/block_based/block_based_table_reader.h"
# include "test_util/testharness.h"
# include "test_util/testharness.h"
# include "util/coding.h"
# include "util/coding.h"
@ -23,25 +22,24 @@ namespace ROCKSDB_NAMESPACE {
class CacheReservationManagerTest : public : : testing : : Test {
class CacheReservationManagerTest : public : : testing : : Test {
protected :
protected :
static constexpr std : : size_t kSizeDummyEntry =
static constexpr std : : size_t kSizeDummyEntry =
CacheReservationManager : : GetDummyEntrySize ( ) ;
CacheReservationManagerImpl < CacheEntryRole : : kMisc > : : GetDummyEntrySize ( ) ;
static constexpr std : : size_t kCacheCapacity = 4096 * kSizeDummyEntry ;
static constexpr std : : size_t kCacheCapacity = 4096 * kSizeDummyEntry ;
static constexpr int kNumShardBits = 0 ; // 2^0 shard
static constexpr int kNumShardBits = 0 ; // 2^0 shard
static constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
static constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
std : : shared_ptr < Cache > cache = NewLRUCache ( kCacheCapacity , kNumShardBits ) ;
std : : shared_ptr < Cache > cache = NewLRUCache ( kCacheCapacity , kNumShardBits ) ;
std : : unique _ptr< CacheReservationManager > test_cache_rev_mng ;
std : : shared _ptr< CacheReservationManager > test_cache_rev_mng ;
CacheReservationManagerTest ( ) {
CacheReservationManagerTest ( ) {
test_cache_rev_mng . reset ( new CacheReservationManager ( cache ) ) ;
test_cache_rev_mng =
std : : make_shared < CacheReservationManagerImpl < CacheEntryRole : : kMisc > > (
cache ) ;
}
}
} ;
} ;
TEST_F ( CacheReservationManagerTest , GenerateCacheKey ) {
TEST_F ( CacheReservationManagerTest , GenerateCacheKey ) {
std : : size_t new_mem_used = 1 * kSizeDummyEntry ;
std : : size_t new_mem_used = 1 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_GE ( cache - > GetPinnedUsage ( ) , 1 * kSizeDummyEntry ) ;
ASSERT_GE ( cache - > GetPinnedUsage ( ) , 1 * kSizeDummyEntry ) ;
ASSERT_LT ( cache - > GetPinnedUsage ( ) ,
ASSERT_LT ( cache - > GetPinnedUsage ( ) ,
@ -66,10 +64,7 @@ TEST_F(CacheReservationManagerTest, GenerateCacheKey) {
TEST_F ( CacheReservationManagerTest , KeepCacheReservationTheSame ) {
TEST_F ( CacheReservationManagerTest , KeepCacheReservationTheSame ) {
std : : size_t new_mem_used = 1 * kSizeDummyEntry ;
std : : size_t new_mem_used = 1 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
1 * kSizeDummyEntry ) ;
1 * kSizeDummyEntry ) ;
@ -79,9 +74,7 @@ TEST_F(CacheReservationManagerTest, KeepCacheReservationTheSame) {
ASSERT_LT ( initial_pinned_usage ,
ASSERT_LT ( initial_pinned_usage ,
1 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
1 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to keep cache reservation the same when new_mem_used equals "
< < " Failed to keep cache reservation the same when new_mem_used equals "
" to current cache reservation " ;
" to current cache reservation " ;
@ -100,10 +93,7 @@ TEST_F(CacheReservationManagerTest, KeepCacheReservationTheSame) {
TEST_F ( CacheReservationManagerTest ,
TEST_F ( CacheReservationManagerTest ,
IncreaseCacheReservationByMultiplesOfDummyEntrySize ) {
IncreaseCacheReservationByMultiplesOfDummyEntrySize ) {
std : : size_t new_mem_used = 2 * kSizeDummyEntry ;
std : : size_t new_mem_used = 2 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to increase cache reservation correctly " ;
< < " Failed to increase cache reservation correctly " ;
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
@ -121,10 +111,7 @@ TEST_F(CacheReservationManagerTest,
TEST_F ( CacheReservationManagerTest ,
TEST_F ( CacheReservationManagerTest ,
IncreaseCacheReservationNotByMultiplesOfDummyEntrySize ) {
IncreaseCacheReservationNotByMultiplesOfDummyEntrySize ) {
std : : size_t new_mem_used = 2 * kSizeDummyEntry + kSizeDummyEntry / 2 ;
std : : size_t new_mem_used = 2 * kSizeDummyEntry + kSizeDummyEntry / 2 ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to increase cache reservation correctly " ;
< < " Failed to increase cache reservation correctly " ;
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
@ -143,7 +130,7 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest,
IncreaseCacheReservationOnFullCache ) {
IncreaseCacheReservationOnFullCache ) {
;
;
constexpr std : : size_t kSizeDummyEntry =
constexpr std : : size_t kSizeDummyEntry =
CacheReservationManager : : GetDummyEntrySize ( ) ;
CacheReservationManagerImpl < CacheEntryRole : : kMisc > : : GetDummyEntrySize ( ) ;
constexpr std : : size_t kSmallCacheCapacity = 4 * kSizeDummyEntry ;
constexpr std : : size_t kSmallCacheCapacity = 4 * kSizeDummyEntry ;
constexpr std : : size_t kBigCacheCapacity = 4096 * kSizeDummyEntry ;
constexpr std : : size_t kBigCacheCapacity = 4096 * kSizeDummyEntry ;
constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
@ -153,14 +140,12 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest,
lo . num_shard_bits = 0 ; // 2^0 shard
lo . num_shard_bits = 0 ; // 2^0 shard
lo . strict_capacity_limit = true ;
lo . strict_capacity_limit = true ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : unique_ptr < CacheReservationManager > test_cache_rev_mng (
std : : shared_ptr < CacheReservationManager > test_cache_rev_mng =
new CacheReservationManager ( cache ) ) ;
std : : make_shared < CacheReservationManagerImpl < CacheEntryRole : : kMisc > > (
cache ) ;
std : : size_t new_mem_used = kSmallCacheCapacity + 1 ;
std : : size_t new_mem_used = kSmallCacheCapacity + 1 ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : Incomplete ( ) )
EXPECT_EQ ( s , Status : : Incomplete ( ) )
< < " Failed to return status to indicate failure of dummy entry insertion "
< < " Failed to return status to indicate failure of dummy entry insertion "
" during cache reservation on full cache " ;
" during cache reservation on full cache " ;
@ -183,9 +168,7 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest,
" encountering cache resevation failure due to full cache " ;
" encountering cache resevation failure due to full cache " ;
new_mem_used = kSmallCacheCapacity / 2 ; // 2 dummy entries
new_mem_used = kSmallCacheCapacity / 2 ; // 2 dummy entries
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to decrease cache reservation after encountering cache "
< < " Failed to decrease cache reservation after encountering cache "
" reservation failure due to full cache " ;
" reservation failure due to full cache " ;
@ -207,9 +190,7 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest,
// Create cache full again for subsequent tests
// Create cache full again for subsequent tests
new_mem_used = kSmallCacheCapacity + 1 ;
new_mem_used = kSmallCacheCapacity + 1 ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : Incomplete ( ) )
EXPECT_EQ ( s , Status : : Incomplete ( ) )
< < " Failed to return status to indicate failure of dummy entry insertion "
< < " Failed to return status to indicate failure of dummy entry insertion "
" during cache reservation on full cache " ;
" during cache reservation on full cache " ;
@ -235,9 +216,7 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest,
// succeed
// succeed
cache - > SetCapacity ( kBigCacheCapacity ) ;
cache - > SetCapacity ( kBigCacheCapacity ) ;
new_mem_used = kSmallCacheCapacity + 1 ;
new_mem_used = kSmallCacheCapacity + 1 ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to increase cache reservation after increasing cache capacity "
< < " Failed to increase cache reservation after increasing cache capacity "
" and mitigating cache full error " ;
" and mitigating cache full error " ;
@ -259,10 +238,7 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest,
TEST_F ( CacheReservationManagerTest ,
TEST_F ( CacheReservationManagerTest ,
DecreaseCacheReservationByMultiplesOfDummyEntrySize ) {
DecreaseCacheReservationByMultiplesOfDummyEntrySize ) {
std : : size_t new_mem_used = 2 * kSizeDummyEntry ;
std : : size_t new_mem_used = 2 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
2 * kSizeDummyEntry ) ;
2 * kSizeDummyEntry ) ;
@ -272,9 +248,7 @@ TEST_F(CacheReservationManagerTest,
2 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
2 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
new_mem_used = 1 * kSizeDummyEntry ;
new_mem_used = 1 * kSizeDummyEntry ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to decrease cache reservation correctly " ;
< < " Failed to decrease cache reservation correctly " ;
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
@ -292,10 +266,7 @@ TEST_F(CacheReservationManagerTest,
TEST_F ( CacheReservationManagerTest ,
TEST_F ( CacheReservationManagerTest ,
DecreaseCacheReservationNotByMultiplesOfDummyEntrySize ) {
DecreaseCacheReservationNotByMultiplesOfDummyEntrySize ) {
std : : size_t new_mem_used = 2 * kSizeDummyEntry ;
std : : size_t new_mem_used = 2 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
2 * kSizeDummyEntry ) ;
2 * kSizeDummyEntry ) ;
@ -305,9 +276,7 @@ TEST_F(CacheReservationManagerTest,
2 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
2 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
new_mem_used = kSizeDummyEntry / 2 ;
new_mem_used = kSizeDummyEntry / 2 ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to decrease cache reservation correctly " ;
< < " Failed to decrease cache reservation correctly " ;
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
@ -325,7 +294,7 @@ TEST_F(CacheReservationManagerTest,
TEST ( CacheReservationManagerWithDelayedDecreaseTest ,
TEST ( CacheReservationManagerWithDelayedDecreaseTest ,
DecreaseCacheReservationWithDelayedDecrease ) {
DecreaseCacheReservationWithDelayedDecrease ) {
constexpr std : : size_t kSizeDummyEntry =
constexpr std : : size_t kSizeDummyEntry =
CacheReservationManager : : GetDummyEntrySize ( ) ;
CacheReservationManagerImpl < CacheEntryRole : : kMisc > : : GetDummyEntrySize ( ) ;
constexpr std : : size_t kCacheCapacity = 4096 * kSizeDummyEntry ;
constexpr std : : size_t kCacheCapacity = 4096 * kSizeDummyEntry ;
constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
@ -333,14 +302,12 @@ TEST(CacheReservationManagerWithDelayedDecreaseTest,
lo . capacity = kCacheCapacity ;
lo . capacity = kCacheCapacity ;
lo . num_shard_bits = 0 ;
lo . num_shard_bits = 0 ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : unique_ptr < CacheReservationManager > test_cache_rev_mng (
std : : shared_ptr < CacheReservationManager > test_cache_rev_mng =
new CacheReservationManager ( cache , true /* delayed_decrease */ ) ) ;
std : : make_shared < CacheReservationManagerImpl < CacheEntryRole : : kMisc > > (
cache , true /* delayed_decrease */ ) ;
std : : size_t new_mem_used = 8 * kSizeDummyEntry ;
std : : size_t new_mem_used = 8 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
ASSERT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
8 * kSizeDummyEntry ) ;
8 * kSizeDummyEntry ) ;
@ -351,9 +318,7 @@ TEST(CacheReservationManagerWithDelayedDecreaseTest,
8 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
8 * kSizeDummyEntry + kMetaDataChargeOverhead ) ;
new_mem_used = 6 * kSizeDummyEntry ;
new_mem_used = 6 * kSizeDummyEntry ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) ) < < " Failed to delay decreasing cache reservation " ;
EXPECT_EQ ( s , Status : : OK ( ) ) < < " Failed to delay decreasing cache reservation " ;
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
8 * kSizeDummyEntry )
8 * kSizeDummyEntry )
@ -365,9 +330,7 @@ TEST(CacheReservationManagerWithDelayedDecreaseTest,
< < " Failed to delay decreasing underlying dummy entries in cache " ;
< < " Failed to delay decreasing underlying dummy entries in cache " ;
new_mem_used = 7 * kSizeDummyEntry ;
new_mem_used = 7 * kSizeDummyEntry ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) ) < < " Failed to delay decreasing cache reservation " ;
EXPECT_EQ ( s , Status : : OK ( ) ) < < " Failed to delay decreasing cache reservation " ;
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
EXPECT_EQ ( test_cache_rev_mng - > GetTotalReservedCacheSize ( ) ,
8 * kSizeDummyEntry )
8 * kSizeDummyEntry )
@ -379,9 +342,7 @@ TEST(CacheReservationManagerWithDelayedDecreaseTest,
< < " Failed to delay decreasing underlying dummy entries in cache " ;
< < " Failed to delay decreasing underlying dummy entries in cache " ;
new_mem_used = 6 * kSizeDummyEntry - 1 ;
new_mem_used = 6 * kSizeDummyEntry - 1 ;
s = test_cache_rev_mng
s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
EXPECT_EQ ( s , Status : : OK ( ) )
EXPECT_EQ ( s , Status : : OK ( ) )
< < " Failed to decrease cache reservation correctly when new_mem_used < "
< < " Failed to decrease cache reservation correctly when new_mem_used < "
" GetTotalReservedCacheSize() * 3 / 4 on delayed decrease mode " ;
" GetTotalReservedCacheSize() * 3 / 4 on delayed decrease mode " ;
@ -405,7 +366,7 @@ TEST(CacheReservationManagerWithDelayedDecreaseTest,
TEST ( CacheReservationManagerDestructorTest ,
TEST ( CacheReservationManagerDestructorTest ,
ReleaseRemainingDummyEntriesOnDestruction ) {
ReleaseRemainingDummyEntriesOnDestruction ) {
constexpr std : : size_t kSizeDummyEntry =
constexpr std : : size_t kSizeDummyEntry =
CacheReservationManager : : GetDummyEntrySize ( ) ;
CacheReservationManagerImpl < CacheEntryRole : : kMisc > : : GetDummyEntrySize ( ) ;
constexpr std : : size_t kCacheCapacity = 4096 * kSizeDummyEntry ;
constexpr std : : size_t kCacheCapacity = 4096 * kSizeDummyEntry ;
constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
constexpr std : : size_t kMetaDataChargeOverhead = 10000 ;
@ -414,13 +375,11 @@ TEST(CacheReservationManagerDestructorTest,
lo . num_shard_bits = 0 ;
lo . num_shard_bits = 0 ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
{
{
std : : unique_ptr < CacheReservationManager > test_cache_rev_mng (
std : : shared_ptr < CacheReservationManager > test_cache_rev_mng =
new CacheReservationManager ( cache ) ) ;
std : : make_shared < CacheReservationManagerImpl < CacheEntryRole : : kMisc > > (
cache ) ;
std : : size_t new_mem_used = 1 * kSizeDummyEntry ;
std : : size_t new_mem_used = 1 * kSizeDummyEntry ;
Status s =
Status s = test_cache_rev_mng - > UpdateCacheReservation ( new_mem_used ) ;
test_cache_rev_mng
- > UpdateCacheReservation < ROCKSDB_NAMESPACE : : CacheEntryRole : : kMisc > (
new_mem_used ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_GE ( cache - > GetPinnedUsage ( ) , 1 * kSizeDummyEntry ) ;
ASSERT_GE ( cache - > GetPinnedUsage ( ) , 1 * kSizeDummyEntry ) ;
ASSERT_LT ( cache - > GetPinnedUsage ( ) ,
ASSERT_LT ( cache - > GetPinnedUsage ( ) ,
@ -442,18 +401,19 @@ TEST(CacheReservationHandleTest, HandleTest) {
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : shared_ptr < Cache > cache = NewLRUCache ( lo ) ;
std : : shared_ptr < CacheReservationManager > test_cache_rev_mng (
std : : shared_ptr < CacheReservationManager > test_cache_rev_mng (
std : : make_shared < CacheReservationManager > ( cache ) ) ;
std : : make_shared < CacheReservationManagerImpl < CacheEntryRole : : kMisc > > (
cache ) ) ;
std : : size_t mem_used = 0 ;
std : : size_t mem_used = 0 ;
const std : : size_t incremental_mem_used_handle_1 = 1 * kSizeDummyEntry ;
const std : : size_t incremental_mem_used_handle_1 = 1 * kSizeDummyEntry ;
const std : : size_t incremental_mem_used_handle_2 = 2 * kSizeDummyEntry ;
const std : : size_t incremental_mem_used_handle_2 = 2 * kSizeDummyEntry ;
std : : unique_ptr < CacheReservationHandle < CacheEntryRole : : kMisc > > handle_1 ,
std : : unique_ptr < CacheReservationManager : : CacheReservationHandle > handle_1 ,
handle_2 ;
handle_2 ;
// To test consecutive CacheReservationManager::MakeCacheReservation works
// To test consecutive CacheReservationManager::MakeCacheReservation works
// correctly in terms of returning the handle as well as updating cache
// correctly in terms of returning the handle as well as updating cache
// reservation and the latest total memory used
// reservation and the latest total memory used
Status s = test_cache_rev_mng - > MakeCacheReservation < CacheEntryRole : : kMisc > (
Status s = test_cache_rev_mng - > MakeCacheReservation (
incremental_mem_used_handle_1 , & handle_1 ) ;
incremental_mem_used_handle_1 , & handle_1 ) ;
mem_used = mem_used + incremental_mem_used_handle_1 ;
mem_used = mem_used + incremental_mem_used_handle_1 ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
@ -463,8 +423,8 @@ TEST(CacheReservationHandleTest, HandleTest) {
EXPECT_GE ( cache - > GetPinnedUsage ( ) , mem_used ) ;
EXPECT_GE ( cache - > GetPinnedUsage ( ) , mem_used ) ;
EXPECT_LT ( cache - > GetPinnedUsage ( ) , mem_used + kMetaDataChargeOverhead ) ;
EXPECT_LT ( cache - > GetPinnedUsage ( ) , mem_used + kMetaDataChargeOverhead ) ;
s = test_cache_rev_mng - > MakeCacheReservation < CacheEntryRole : : kMisc > (
s = test_cache_rev_mng - > MakeCacheReservation ( incremental_mem_used_handle_2 ,
incremental_mem_used_handle_2 , & handle_2 ) ;
& handle_2 ) ;
mem_used = mem_used + incremental_mem_used_handle_2 ;
mem_used = mem_used + incremental_mem_used_handle_2 ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
ASSERT_EQ ( s , Status : : OK ( ) ) ;
EXPECT_TRUE ( handle_2 ! = nullptr ) ;
EXPECT_TRUE ( handle_2 ! = nullptr ) ;
@ -473,8 +433,9 @@ TEST(CacheReservationHandleTest, HandleTest) {
EXPECT_GE ( cache - > GetPinnedUsage ( ) , mem_used ) ;
EXPECT_GE ( cache - > GetPinnedUsage ( ) , mem_used ) ;
EXPECT_LT ( cache - > GetPinnedUsage ( ) , mem_used + kMetaDataChargeOverhead ) ;
EXPECT_LT ( cache - > GetPinnedUsage ( ) , mem_used + kMetaDataChargeOverhead ) ;
// To test CacheReservationHandle::~CacheReservationHandle() works correctly
// To test
// in releasing the cache reserved for the handle
// CacheReservationManager::CacheReservationHandle::~CacheReservationHandle()
// works correctly in releasing the cache reserved for the handle
handle_1 . reset ( ) ;
handle_1 . reset ( ) ;
EXPECT_TRUE ( handle_1 = = nullptr ) ;
EXPECT_TRUE ( handle_1 = = nullptr ) ;
mem_used = mem_used - incremental_mem_used_handle_1 ;
mem_used = mem_used - incremental_mem_used_handle_1 ;