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
main
Vaibhav Gogte 6 years ago committed by Facebook Github Bot
parent 92f631da33
commit f46a2a0375
  1. 8
      cache/cache_test.cc
  2. 3
      cache/sharded_cache.h
  3. 3
      include/rocksdb/cache.h
  4. 2
      utilities/simulator_cache/sim_cache.cc

@ -686,6 +686,14 @@ TEST_P(CacheTest, DefaultShardBits) {
ASSERT_EQ(6, sc->GetNumShardBits()); 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 #ifdef SUPPORT_CLOCK_CACHE
std::shared_ptr<Cache> (*new_clock_cache_func)(size_t, int, std::shared_ptr<Cache> (*new_clock_cache_func)(size_t, int,
bool) = NewClockCache; bool) = NewClockCache;

@ -54,7 +54,8 @@ class ShardedCache : public Cache {
virtual CacheShard* GetShard(int shard) = 0; virtual CacheShard* GetShard(int shard) = 0;
virtual const CacheShard* GetShard(int shard) const = 0; virtual const CacheShard* GetShard(int shard) const = 0;
virtual void* Value(Handle* handle) override = 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 uint32_t GetHash(Handle* handle) const = 0;
virtual void DisownData() override = 0; virtual void DisownData() override = 0;

@ -226,6 +226,9 @@ class Cache {
// returns the memory size for the entries in use by the system // returns the memory size for the entries in use by the system
virtual size_t GetPinnedUsage() const = 0; 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 // 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 // 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. // memory - call this only if you're shutting down the process.

@ -235,6 +235,8 @@ class SimCacheImpl : public SimCache {
return cache_->GetUsage(handle); return cache_->GetUsage(handle);
} }
size_t GetCharge(Handle* handle) const override { return cache_->GetCharge(handle); }
size_t GetPinnedUsage() const override { return cache_->GetPinnedUsage(); } size_t GetPinnedUsage() const override { return cache_->GetPinnedUsage(); }
void DisownData() override { void DisownData() override {

Loading…
Cancel
Save