@ -100,10 +100,10 @@ class CompressedSecondaryCacheTest : public testing::Test,
void BasicTestHelper ( std : : shared_ptr < SecondaryCache > sec_cache ,
void BasicTestHelper ( std : : shared_ptr < SecondaryCache > sec_cache ,
bool sec_cache_is_compressed ) {
bool sec_cache_is_compressed ) {
get_perf_context ( ) - > Reset ( ) ;
get_perf_context ( ) - > Reset ( ) ;
bool is _in_sec_cache{ true } ;
bool kept _in_sec_cache{ true } ;
// Lookup an non-existent key.
// Lookup an non-existent key.
std : : unique_ptr < SecondaryCacheResultHandle > handle0 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle0 = sec_cache - > Lookup (
" k0 " , & kHelper , this , true , /*advise_erase=*/ true , is _in_sec_cache) ;
" k0 " , & kHelper , this , true , /*advise_erase=*/ true , kept _in_sec_cache) ;
ASSERT_EQ ( handle0 , nullptr ) ;
ASSERT_EQ ( handle0 , nullptr ) ;
Random rnd ( 301 ) ;
Random rnd ( 301 ) ;
@ -117,7 +117,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_compressed_bytes , 0 ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_compressed_bytes , 0 ) ;
std : : unique_ptr < SecondaryCacheResultHandle > handle1_1 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle1_1 = sec_cache - > Lookup (
" k1 " , & kHelper , this , true , /*advise_erase=*/ false , is _in_sec_cache) ;
" k1 " , & kHelper , this , true , /*advise_erase=*/ false , kept _in_sec_cache) ;
ASSERT_EQ ( handle1_1 , nullptr ) ;
ASSERT_EQ ( handle1_1 , nullptr ) ;
// Insert and Lookup the item k1 for the second time and advise erasing it.
// Insert and Lookup the item k1 for the second time and advise erasing it.
@ -125,9 +125,9 @@ class CompressedSecondaryCacheTest : public testing::Test,
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_insert_real_count , 1 ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_insert_real_count , 1 ) ;
std : : unique_ptr < SecondaryCacheResultHandle > handle1_2 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle1_2 = sec_cache - > Lookup (
" k1 " , & kHelper , this , true , /*advise_erase=*/ true , is _in_sec_cache) ;
" k1 " , & kHelper , this , true , /*advise_erase=*/ true , kept _in_sec_cache) ;
ASSERT_NE ( handle1_2 , nullptr ) ;
ASSERT_NE ( handle1_2 , nullptr ) ;
ASSERT_FALSE ( is _in_sec_cache) ;
ASSERT_FALSE ( kept _in_sec_cache) ;
if ( sec_cache_is_compressed ) {
if ( sec_cache_is_compressed ) {
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_uncompressed_bytes ,
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_uncompressed_bytes ,
1000 ) ;
1000 ) ;
@ -145,7 +145,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
// Lookup the item k1 again.
// Lookup the item k1 again.
std : : unique_ptr < SecondaryCacheResultHandle > handle1_3 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle1_3 = sec_cache - > Lookup (
" k1 " , & kHelper , this , true , /*advise_erase=*/ true , is _in_sec_cache) ;
" k1 " , & kHelper , this , true , /*advise_erase=*/ true , kept _in_sec_cache) ;
ASSERT_EQ ( handle1_3 , nullptr ) ;
ASSERT_EQ ( handle1_3 , nullptr ) ;
// Insert and Lookup the item k2.
// Insert and Lookup the item k2.
@ -154,7 +154,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_insert_dummy_count , 2 ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_insert_dummy_count , 2 ) ;
std : : unique_ptr < SecondaryCacheResultHandle > handle2_1 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle2_1 = sec_cache - > Lookup (
" k2 " , & kHelper , this , true , /*advise_erase=*/ false , is _in_sec_cache) ;
" k2 " , & kHelper , this , true , /*advise_erase=*/ false , kept _in_sec_cache) ;
ASSERT_EQ ( handle2_1 , nullptr ) ;
ASSERT_EQ ( handle2_1 , nullptr ) ;
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
@ -169,7 +169,7 @@ class CompressedSecondaryCacheTest : public testing::Test,
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_compressed_bytes , 0 ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_compressed_bytes , 0 ) ;
}
}
std : : unique_ptr < SecondaryCacheResultHandle > handle2_2 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle2_2 = sec_cache - > Lookup (
" k2 " , & kHelper , this , true , /*advise_erase=*/ false , is _in_sec_cache) ;
" k2 " , & kHelper , this , true , /*advise_erase=*/ false , kept _in_sec_cache) ;
ASSERT_NE ( handle2_2 , nullptr ) ;
ASSERT_NE ( handle2_2 , nullptr ) ;
std : : unique_ptr < TestItem > val2 =
std : : unique_ptr < TestItem > val2 =
std : : unique_ptr < TestItem > ( static_cast < TestItem * > ( handle2_2 - > Value ( ) ) ) ;
std : : unique_ptr < TestItem > ( static_cast < TestItem * > ( handle2_2 - > Value ( ) ) ) ;
@ -247,15 +247,15 @@ class CompressedSecondaryCacheTest : public testing::Test,
TestItem item2 ( str2 . data ( ) , str2 . length ( ) ) ;
TestItem item2 ( str2 . data ( ) , str2 . length ( ) ) ;
// Insert a dummy handle, k1 is not evicted.
// Insert a dummy handle, k1 is not evicted.
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
bool is _in_sec_cache{ false } ;
bool kept _in_sec_cache{ false } ;
std : : unique_ptr < SecondaryCacheResultHandle > handle1 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle1 = sec_cache - > Lookup (
" k1 " , & kHelper , this , true , /*advise_erase=*/ false , is _in_sec_cache) ;
" k1 " , & kHelper , this , true , /*advise_erase=*/ false , kept _in_sec_cache) ;
ASSERT_EQ ( handle1 , nullptr ) ;
ASSERT_EQ ( handle1 , nullptr ) ;
// Insert k2 and k1 is evicted.
// Insert k2 and k1 is evicted.
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
ASSERT_OK ( sec_cache - > Insert ( " k2 " , & item2 , & kHelper ) ) ;
std : : unique_ptr < SecondaryCacheResultHandle > handle2 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle2 = sec_cache - > Lookup (
" k2 " , & kHelper , this , true , /*advise_erase=*/ false , is _in_sec_cache) ;
" k2 " , & kHelper , this , true , /*advise_erase=*/ false , kept _in_sec_cache) ;
ASSERT_NE ( handle2 , nullptr ) ;
ASSERT_NE ( handle2 , nullptr ) ;
std : : unique_ptr < TestItem > val2 =
std : : unique_ptr < TestItem > val2 =
std : : unique_ptr < TestItem > ( static_cast < TestItem * > ( handle2 - > Value ( ) ) ) ;
std : : unique_ptr < TestItem > ( static_cast < TestItem * > ( handle2 - > Value ( ) ) ) ;
@ -266,13 +266,13 @@ class CompressedSecondaryCacheTest : public testing::Test,
ASSERT_OK ( sec_cache - > Insert ( " k1 " , & item1 , & kHelper ) ) ;
ASSERT_OK ( sec_cache - > Insert ( " k1 " , & item1 , & kHelper ) ) ;
std : : unique_ptr < SecondaryCacheResultHandle > handle1_1 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle1_1 = sec_cache - > Lookup (
" k1 " , & kHelper , this , true , /*advise_erase=*/ false , is _in_sec_cache) ;
" k1 " , & kHelper , this , true , /*advise_erase=*/ false , kept _in_sec_cache) ;
ASSERT_EQ ( handle1_1 , nullptr ) ;
ASSERT_EQ ( handle1_1 , nullptr ) ;
// Create Fails.
// Create Fails.
SetFailCreate ( true ) ;
SetFailCreate ( true ) ;
std : : unique_ptr < SecondaryCacheResultHandle > handle2_1 = sec_cache - > Lookup (
std : : unique_ptr < SecondaryCacheResultHandle > handle2_1 = sec_cache - > Lookup (
" k2 " , & kHelper , this , true , /*advise_erase=*/ true , is _in_sec_cache) ;
" k2 " , & kHelper , this , true , /*advise_erase=*/ true , kept _in_sec_cache) ;
ASSERT_EQ ( handle2_1 , nullptr ) ;
ASSERT_EQ ( handle2_1 , nullptr ) ;
// Save Fails.
// Save Fails.
@ -970,10 +970,10 @@ TEST_P(CompressedSecondaryCacheTestWithCompressionParam, EntryRoles) {
ASSERT_OK ( sec_cache - > Insert ( ith_key , & item , & kHelperByRole [ i ] ) ) ;
ASSERT_OK ( sec_cache - > Insert ( ith_key , & item , & kHelperByRole [ i ] ) ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_insert_real_count , 1U ) ;
ASSERT_EQ ( get_perf_context ( ) - > compressed_sec_cache_insert_real_count , 1U ) ;
bool is _in_sec_cache{ true } ;
bool kept _in_sec_cache{ true } ;
std : : unique_ptr < SecondaryCacheResultHandle > handle =
std : : unique_ptr < SecondaryCacheResultHandle > handle =
sec_cache - > Lookup ( ith_key , & kHelperByRole [ i ] , this , true ,
sec_cache - > Lookup ( ith_key , & kHelperByRole [ i ] , this , true ,
/*advise_erase=*/ true , is _in_sec_cache) ;
/*advise_erase=*/ true , kept _in_sec_cache) ;
ASSERT_NE ( handle , nullptr ) ;
ASSERT_NE ( handle , nullptr ) ;
// Lookup returns the right data
// Lookup returns the right data