diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index 7c04cb909d5..43c2d52857f 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -190,7 +190,8 @@ void LRUCacheShard::LRU_Remove(LRUHandle* e) { void LRUCacheShard::LRU_Insert(LRUHandle* e) { assert(e->next == nullptr); assert(e->prev == nullptr); - if (high_pri_pool_ratio_ > 0 && (e->IsHighPri() || e->HasHit())) { + if ((high_pri_pool_ratio_ > 0 && (e->IsHighPri() || e->HasHit())) + || high_pri_pool_ratio_ == 1.0) { // Inset "e" to head of LRU list. e->next = &lru_; e->prev = lru_.prev; @@ -522,6 +523,18 @@ double LRUCache::GetHighPriPoolRatio() { return result; } +std::shared_ptr<Cache> NewHighPriCache(LRUCacheOptions& cache_opts) { + // set high_pri_pool_ratio always 1 + cache_opts.high_pri_pool_ratio = 1.0; + return NewLRUCache(cache_opts); +} + +std::shared_ptr<Cache> NewLowPriCache(LRUCacheOptions& cache_opts) { + // set high_pri_pool_ratio always 0 + cache_opts.high_pri_pool_ratio = 0.0; + return NewLRUCache(cache_opts); +} + std::shared_ptr<Cache> NewLRUCache(const LRUCacheOptions& cache_opts) { return NewLRUCache(cache_opts.capacity, cache_opts.num_shard_bits, cache_opts.strict_capacity_limit, diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index 6bde575e0fc..2eafc3408a9 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -105,6 +105,14 @@ extern std::shared_ptr<Cache> NewLRUCache( extern std::shared_ptr<Cache> NewLRUCache(const LRUCacheOptions& cache_opts); +// Create a new cache which is always high priority cache, is always insert +// into the cache with high-priority, regardless of user provided option. +extern std::shared_ptr<Cache> NewHighPriCache(LRUCacheOptions& cache_opts); + +// Create a new cache which is always low priority cache, is always insert +// into the cache with low-priority, regardless of user provided option. +extern std::shared_ptr<Cache> NewLowPriCache(LRUCacheOptions& cache_opts); + // Similar to NewLRUCache, but create a cache based on CLOCK algorithm with // better concurrent performance in some cases. See util/clock_cache.cc for // more detail.