@ -6,6 +6,7 @@
# include "rocksdb/utilities/sim_cache.h"
# include <atomic>
# include "port/port.h"
# include "util/statistics.h"
namespace rocksdb {
@ -16,12 +17,11 @@ class SimCacheImpl : public SimCache {
// capacity for real cache (ShardedLRUCache)
// test_capacity for key only cache
SimCacheImpl ( std : : shared_ptr < Cache > cache , size_t sim_capacity ,
int num_shard_bits , Statistics * stats )
int num_shard_bits )
: cache_ ( cache ) ,
key_only_cache_ ( NewLRUCache ( sim_capacity , num_shard_bits ) ) ,
miss_times_ ( 0 ) ,
hit_times_ ( 0 ) ,
stats_ ( stats ) { }
hit_times_ ( 0 ) { }
virtual ~ SimCacheImpl ( ) { }
virtual void SetCapacity ( size_t capacity ) override {
@ -51,17 +51,17 @@ class SimCacheImpl : public SimCache {
return cache_ - > Insert ( key , value , charge , deleter , handle , priority ) ;
}
virtual Handle * Lookup ( const Slice & key ) override {
virtual Handle * Lookup ( const Slice & key , Statistics * stats ) override {
Handle * h = key_only_cache_ - > Lookup ( key ) ;
if ( h ! = nullptr ) {
key_only_cache_ - > Release ( h ) ;
inc_hit_counter ( ) ;
RecordTick ( stats_ , SIM_BLOCK_CACHE_HIT ) ;
RecordTick ( stats , SIM_BLOCK_CACHE_HIT ) ;
} else {
inc_miss_counter ( ) ;
RecordTick ( stats_ , SIM_BLOCK_CACHE_MISS ) ;
RecordTick ( stats , SIM_BLOCK_CACHE_MISS ) ;
}
return cache_ - > Lookup ( key ) ;
return cache_ - > Lookup ( key , stats ) ;
}
virtual void Release ( Handle * handle ) override { cache_ - > Release ( handle ) ; }
@ -160,13 +160,11 @@ class SimCacheImpl : public SimCache {
// For instrumentation purpose, use NewSimCache instead
std : : shared_ptr < SimCache > NewSimCache ( std : : shared_ptr < Cache > cache ,
size_t sim_capacity , int num_shard_bits ,
std : : shared_ptr < Statistics > stats ) {
size_t sim_capacity , int num_shard_bits ) {
if ( num_shard_bits > = 20 ) {
return nullptr ; // the cache cannot be sharded into too many fine pieces
}
return std : : make_shared < SimCacheImpl > ( cache , sim_capacity , num_shard_bits ,
stats . get ( ) ) ;
return std : : make_shared < SimCacheImpl > ( cache , sim_capacity , num_shard_bits ) ;
}
} // end namespace rocksdb