From f46a2a03759a11731d62f01a0707a44ccab4cfbc Mon Sep 17 00:00:00 2001 From: Vaibhav Gogte Date: Tue, 18 Jun 2019 17:32:44 -0700 Subject: [PATCH] Export Cache::GetCharge (#5476) Summary: Exporting GetCharge to cache.hh Pull Request resolved: https://github.com/facebook/rocksdb/pull/5476 Differential Revision: D15881882 Pulled By: riversand963 fbshipit-source-id: 3d99084d10059b4fcaaaba240606ed50bc23351c --- cache/cache_test.cc | 8 ++++++++ cache/sharded_cache.h | 3 ++- include/rocksdb/cache.h | 3 +++ utilities/simulator_cache/sim_cache.cc | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cache/cache_test.cc b/cache/cache_test.cc index 0cc3d5595..d7b191bb3 100644 --- a/cache/cache_test.cc +++ b/cache/cache_test.cc @@ -686,6 +686,14 @@ TEST_P(CacheTest, DefaultShardBits) { ASSERT_EQ(6, sc->GetNumShardBits()); } +TEST_P(CacheTest, GetCharge) { + Insert(1, 2); + Cache::Handle* h1 = cache_->Lookup(EncodeKey(1)); + ASSERT_EQ(2, DecodeValue(cache_->Value(h1))); + ASSERT_EQ(1, cache_->GetCharge(h1)); + cache_->Release(h1); +} + #ifdef SUPPORT_CLOCK_CACHE std::shared_ptr (*new_clock_cache_func)(size_t, int, bool) = NewClockCache; diff --git a/cache/sharded_cache.h b/cache/sharded_cache.h index 920898b87..0c1499f22 100644 --- a/cache/sharded_cache.h +++ b/cache/sharded_cache.h @@ -54,7 +54,8 @@ class ShardedCache : public Cache { virtual CacheShard* GetShard(int shard) = 0; virtual const CacheShard* GetShard(int shard) const = 0; virtual void* Value(Handle* handle) override = 0; - virtual size_t GetCharge(Handle* handle) const = 0; + virtual size_t GetCharge(Handle* handle) const override = 0; + virtual uint32_t GetHash(Handle* handle) const = 0; virtual void DisownData() override = 0; diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index ed7790aeb..8fb691559 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -226,6 +226,9 @@ class Cache { // returns the memory size for the entries in use by the system virtual size_t GetPinnedUsage() const = 0; + // returns the charge for the specific entry in the cache. + virtual size_t GetCharge(Handle* handle) const = 0; + // Call this on shutdown if you want to speed it up. Cache will disown // any underlying data and will not free it on delete. This call will leak // memory - call this only if you're shutting down the process. diff --git a/utilities/simulator_cache/sim_cache.cc b/utilities/simulator_cache/sim_cache.cc index f6f1e6714..d84a593b9 100644 --- a/utilities/simulator_cache/sim_cache.cc +++ b/utilities/simulator_cache/sim_cache.cc @@ -235,6 +235,8 @@ class SimCacheImpl : public SimCache { return cache_->GetUsage(handle); } + size_t GetCharge(Handle* handle) const override { return cache_->GetCharge(handle); } + size_t GetPinnedUsage() const override { return cache_->GetPinnedUsage(); } void DisownData() override {