Skip to content

Commit

Permalink
Fix issue with token creation
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed Apr 25, 2023
1 parent 0253683 commit 7a033e6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cachelib/allocator/CacheAllocator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1289,26 +1289,29 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
: toRecycle_;

const bool evictToNvmCache = shouldWriteToNvmCache(*candidate_);
if (evictToNvmCache)
token = nvmCache_->createPutToken(candidate_->getKey());
auto token_ = evictToNvmCache
? nvmCache_->createPutToken(candidate_->getKey())
: typename NvmCacheT::PutToken{};

if (evictToNvmCache && !token.isValid()) {
if (evictToNvmCache && !token_.isValid()) {
stats_.evictFailConcurrentFill.inc();
} else if (candidate_->markForEviction()) {
XDCHECK(candidate_->isMarkedForEviction());
// markForEviction to make sure no other thead is evicting the item
// nor holding a handle to that item
toRecycle = toRecycle_;
candidate = candidate_;
token = std::move(token_);

// Check if parent changed for chained items - if yes, we cannot
// remove the child from the mmContainer as we will not be evicting
// it. We could abort right here, but we need to cleanup in case
// unmarkForEviction() returns 0 - so just go through normal path.
if (!toRecycle_->isChainedItem() ||
&toRecycle->asChainedItem().getParentItem(compressor_) ==
candidate)
candidate) {
mmContainer.remove(itr);
}
return;
} else {
if (candidate_->hasChainedItem()) {
Expand All @@ -1324,8 +1327,9 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
}
});

if (!toRecycle)
if (!toRecycle) {
continue;
}

XDCHECK(toRecycle);
XDCHECK(candidate);
Expand Down

0 comments on commit 7a033e6

Please sign in to comment.