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
This commit is contained in:
Vaibhav Gogte 2019-06-18 17:32:44 -07:00 committed by Fosco Marotto
parent d9aecd909f
commit b4f8173984
4 changed files with 15 additions and 1 deletions

8
cache/cache_test.cc vendored
View File

@ -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<Cache> (*new_clock_cache_func)(size_t, int,
bool) = NewClockCache;

View File

@ -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;

View File

@ -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.

View File

@ -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 {