diff --git a/include/leveldb/cache.h b/include/leveldb/cache.h index a7bd2afa7..f0aa4b130 100644 --- a/include/leveldb/cache.h +++ b/include/leveldb/cache.h @@ -82,6 +82,9 @@ class Cache { // its cache keys. virtual uint64_t NewId() = 0; + // returns the maximum configured capacity of the cache + virtual size_t GetCapacity() = 0; + private: void LRU_Remove(Handle* e); void LRU_Append(Handle* e); diff --git a/util/cache.cc b/util/cache.cc index dedb370b3..6dfa4d121 100644 --- a/util/cache.cc +++ b/util/cache.cc @@ -276,6 +276,7 @@ class ShardedLRUCache : public Cache { port::Mutex id_mutex_; uint64_t last_id_; int numShardBits; + size_t capacity_; static inline uint32_t HashSlice(const Slice& s) { return Hash(s.data(), s.size(), 0); @@ -287,6 +288,7 @@ class ShardedLRUCache : public Cache { void init(size_t capacity, int numbits) { numShardBits = numbits; + capacity_ = capacity; int numShards = 1 << numShardBits; shard_ = new LRUCache[numShards]; const size_t per_shard = (capacity + (numShards - 1)) / numShards; @@ -329,6 +331,9 @@ class ShardedLRUCache : public Cache { MutexLock l(&id_mutex_); return ++(last_id_); } + virtual uint64_t GetCapacity() { + return capacity_; + } }; } // end anonymous namespace diff --git a/util/options.cc b/util/options.cc index bd9027be9..f8c02df09 100644 --- a/util/options.cc +++ b/util/options.cc @@ -7,6 +7,7 @@ #include "leveldb/comparator.h" #include "leveldb/env.h" #include "leveldb/filter_policy.h" +#include "leveldb/cache.h" namespace leveldb { @@ -56,6 +57,7 @@ Options::Dump( Log(log," Options.write_buffer_size: %zd", write_buffer_size); Log(log," Options.max_open_files: %d", max_open_files); Log(log," Options.block_cache: %p", block_cache); + Log(log," Options.block_cache_size: %zd", block_cache->GetCapacity()); Log(log," Options.block_size: %zd", block_size); Log(log,"Options.block_restart_interval: %d", block_restart_interval); Log(log," Options.compression: %d", compression);