From e408e98c8c250238073ac6ccc0846319a025f132 Mon Sep 17 00:00:00 2001 From: Aaron Gao Date: Fri, 12 Aug 2016 14:16:57 -0700 Subject: [PATCH] add Name() to Cache Summary: preparation for detecting Cache type. If SimCache, we then may trigger some command like "setSimCapacity()" with setOptions() Test Plan: make all check Reviewers: yiwu, sdong Reviewed By: sdong Subscribers: andrewkr, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D61953 --- include/rocksdb/cache.h | 3 +++ include/rocksdb/utilities/sim_cache.h | 2 ++ util/lru_cache.cc | 1 + util/sharded_cache.h | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index 53cb6c60f..c74de986d 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -51,6 +51,9 @@ class Cache { // Opaque handle to an entry stored in the cache. struct Handle {}; + // The type of the Cache + virtual const char* Name() const = 0; + // Insert a mapping from key->value into the cache and assign it // the specified charge against the total cache capacity. // If strict_capacity_limit is true and cache reaches its full capacity, diff --git a/include/rocksdb/utilities/sim_cache.h b/include/rocksdb/utilities/sim_cache.h index d6f31cd8e..8ccef0560 100644 --- a/include/rocksdb/utilities/sim_cache.h +++ b/include/rocksdb/utilities/sim_cache.h @@ -33,6 +33,8 @@ class SimCache : public Cache { virtual ~SimCache() {} + virtual const char* Name() const override { return "SimCache"; } + // returns the maximum configured capacity of the simcache for simulation virtual size_t GetSimCapacity() const = 0; diff --git a/util/lru_cache.cc b/util/lru_cache.cc index cdc1c3f27..de51174ed 100644 --- a/util/lru_cache.cc +++ b/util/lru_cache.cc @@ -528,6 +528,7 @@ class LRUCache : public ShardedCache { virtual ~LRUCache() { delete[] shards_; } + virtual const char* Name() const override { return "LRUCache"; } virtual CacheShard* GetShard(int shard) override { return reinterpret_cast(&shards_[shard]); } diff --git a/util/sharded_cache.h b/util/sharded_cache.h index 58658bdc3..4abccde4b 100644 --- a/util/sharded_cache.h +++ b/util/sharded_cache.h @@ -46,7 +46,7 @@ class ShardedCache : public Cache { public: ShardedCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit); virtual ~ShardedCache() = default; - + virtual const char* Name() const override = 0; virtual CacheShard* GetShard(int shard) = 0; virtual const CacheShard* GetShard(int shard) const = 0; virtual void* Value(Handle* handle) override = 0;