Fix LRU Ref() for handles with external references only

Summary:
For case !handle->InCache() && handle->refs >= 1 (the third case mentioned in lru_cache.h), the key was overwritten by Insert(). In this case, the refcount can still be incremented, and the cache handle will never enter LRU list. Fix Ref() logic for this case.
Closes https://github.com/facebook/rocksdb/pull/1808

Differential Revision: D4467656

Pulled By: ajkr

fbshipit-source-id: c0784d8
main
Andrew Kryczka 8 years ago committed by Facebook Github Bot
parent 17c1180603
commit 94a0c32e73
  1. 11
      util/lru_cache.cc

@ -259,14 +259,11 @@ Cache::Handle* LRUCacheShard::Lookup(const Slice& key, uint32_t hash) {
bool LRUCacheShard::Ref(Cache::Handle* h) {
LRUHandle* handle = reinterpret_cast<LRUHandle*>(h);
MutexLock l(&mutex_);
if (handle->InCache()) {
if (handle->refs == 1) {
LRU_Remove(handle);
}
handle->refs++;
return true;
if (handle->InCache() && handle->refs == 1) {
LRU_Remove(handle);
}
return false;
handle->refs++;
return true;
}
void LRUCacheShard::SetHighPriorityPoolRatio(double high_pri_pool_ratio) {

Loading…
Cancel
Save