Fix a race in LRUCacheShard::Promote (#8717)
Summary: In ```LRUCacheShard::Promote```, a reference is released outside the LRU mutex. Fix the race condition. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8717 Reviewed By: zhichao-cao Differential Revision: D30649206 Pulled By: anand1976 fbshipit-source-id: 09c0af05b2294a7fe2c02876a61b0bad6e3ada61
This commit is contained in:
parent
3efc6fd641
commit
1fe5ac3468
@ -1,4 +1,8 @@
|
|||||||
# Rocksdb Change Log
|
# Rocksdb Change Log
|
||||||
|
## 6.24.1 (2021-08-31)
|
||||||
|
### Bug Fixes
|
||||||
|
* Fix a race in item ref counting in LRUCache when promoting an item from the SecondaryCache.
|
||||||
|
|
||||||
## 6.24.0 (2021-08-20)
|
## 6.24.0 (2021-08-20)
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
* If the primary's CURRENT file is missing or inaccessible, the secondary instance should not hang repeatedly trying to switch to a new MANIFEST. It should instead return the error code encountered while accessing the file.
|
* If the primary's CURRENT file is missing or inaccessible, the secondary instance should not hang repeatedly trying to switch to a new MANIFEST. It should instead return the error code encountered while accessing the file.
|
||||||
|
9
cache/lru_cache.cc
vendored
9
cache/lru_cache.cc
vendored
@ -360,7 +360,10 @@ Status LRUCacheShard::InsertItem(LRUHandle* e, Cache::Handle** handle,
|
|||||||
if (handle == nullptr) {
|
if (handle == nullptr) {
|
||||||
LRU_Insert(e);
|
LRU_Insert(e);
|
||||||
} else {
|
} else {
|
||||||
|
// If caller already holds a ref, no need to take one here
|
||||||
|
if (!e->HasRefs()) {
|
||||||
e->Ref();
|
e->Ref();
|
||||||
|
}
|
||||||
*handle = reinterpret_cast<Cache::Handle*>(e);
|
*handle = reinterpret_cast<Cache::Handle*>(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,11 +401,7 @@ void LRUCacheShard::Promote(LRUHandle* e) {
|
|||||||
if (e->value) {
|
if (e->value) {
|
||||||
Cache::Handle* handle = reinterpret_cast<Cache::Handle*>(e);
|
Cache::Handle* handle = reinterpret_cast<Cache::Handle*>(e);
|
||||||
Status s = InsertItem(e, &handle, /*free_handle_on_fail=*/false);
|
Status s = InsertItem(e, &handle, /*free_handle_on_fail=*/false);
|
||||||
if (s.ok()) {
|
if (!s.ok()) {
|
||||||
// InsertItem would have taken a reference on the item, so decrement it
|
|
||||||
// here as we expect the caller to already hold a reference
|
|
||||||
e->Unref();
|
|
||||||
} else {
|
|
||||||
// Item is in memory, but not accounted against the cache capacity.
|
// Item is in memory, but not accounted against the cache capacity.
|
||||||
// When the handle is released, the item should get deleted
|
// When the handle is released, the item should get deleted
|
||||||
assert(!e->InCache());
|
assert(!e->InCache());
|
||||||
|
Loading…
Reference in New Issue
Block a user