Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add HighPriCache and LowPriCache interface to implement PrioritizedCache #144

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cache/lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions include/rocksdb/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down