From 947cd86558ca819918c626f247ba76080da0f138 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 12 Mar 2018 07:17:20 -0500 Subject: [PATCH] include/rocksdb/cache.h: expose setHighPriPoolRatio Signed-off-by: Mark Nelson --- cache/lru_cache.cc | 8 +++++++- cache/lru_cache.h | 4 ++-- include/rocksdb/cache.h | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index 44763c317..a7611cac1 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -290,7 +290,7 @@ bool LRUCacheShard::Ref(Cache::Handle* h) { return true; } -void LRUCacheShard::SetHighPriorityPoolRatio(double high_pri_pool_ratio) { +void LRUCacheShard::SetHighPriPoolRatio(double high_pri_pool_ratio) { MutexLock l(&mutex_); high_pri_pool_ratio_ = high_pri_pool_ratio; high_pri_pool_capacity_ = capacity_ * high_pri_pool_ratio_; @@ -549,6 +549,12 @@ double LRUCache::GetHighPriPoolRatio() const { return result; } +void LRUCache::SetHighPriPoolRatio(double high_pri_pool_ratio) { + for (int i = 0; i < num_shards_; i++) { + shards_[i].SetHighPriPoolRatio(high_pri_pool_ratio); + } +} + std::shared_ptr NewLRUCache(const LRUCacheOptions& cache_opts) { return NewLRUCache(cache_opts.capacity, cache_opts.num_shard_bits, cache_opts.strict_capacity_limit, diff --git a/cache/lru_cache.h b/cache/lru_cache.h index 9c41f4907..60538c5f5 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -172,7 +172,7 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard { virtual void SetStrictCapacityLimit(bool strict_capacity_limit) override; // Set percentage of capacity reserved for high-pri cache entries. - void SetHighPriorityPoolRatio(double high_pri_pool_ratio); + void SetHighPriPoolRatio(double high_pri_pool_ratio); // Like Cache methods, but with an extra "hash" parameter. virtual Status Insert(const Slice& key, uint32_t hash, void* value, @@ -293,7 +293,7 @@ class LRUCache : public ShardedCache { virtual size_t GetHighPriPoolCapacity() const; virtual size_t GetHighPriPoolUsage() const; virtual double GetHighPriPoolRatio() const; - + virtual void SetHighPriPoolRatio(double high_pri_pool_ratio); // Retrieves number of elements in LRU, for unit test purpose only size_t TEST_GetLRUSize(); diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index ad82cdbcb..66df9c91f 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -186,6 +186,11 @@ class Cache { // capacity. virtual void SetStrictCapacityLimit(bool strict_capacity_limit) = 0; + // Set the high priority pool ratio + virtual void SetHighPriPoolRatio(double high_pri_pool_ratio) { + // default implementation is noop + } + // Get the flag whether to return error on insertion when cache reaches its // full capacity. virtual bool HasStrictCapacityLimit() const = 0; -- 2.47.3