Skip to content

Commit 5d5c3f0

Browse files
committed
Fix issue with token creation
1 parent 0253683 commit 5d5c3f0

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

cachelib/allocator/CacheAllocator-inl.h

+33-26
Original file line numberDiff line numberDiff line change
@@ -1243,14 +1243,14 @@ bool CacheAllocator<CacheTrait>::moveChainedItem(ChainedItem& oldItem,
12431243
template <typename CacheTrait>
12441244
void CacheAllocator<CacheTrait>::unlinkItemForEviction(Item& it) {
12451245
XDCHECK(it.isMarkedForEviction());
1246-
XDCHECK(it.getRefCount() == 0);
1246+
XDCHECK_EQ(0, it.getRefCount());
12471247
accessContainer_->remove(it);
12481248
removeFromMMContainer(it);
12491249

12501250
// Since we managed to mark the item for eviction we must be the only
12511251
// owner of the item.
12521252
const auto ref = it.unmarkForEviction();
1253-
XDCHECK(ref == 0u);
1253+
XDCHECK_EQ(0, ref);
12541254
}
12551255

12561256
template <typename CacheTrait>
@@ -1289,43 +1289,50 @@ CacheAllocator<CacheTrait>::findEviction(PoolId pid, ClassId cid) {
12891289
: toRecycle_;
12901290

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

1295-
if (evictToNvmCache && !token.isValid()) {
1296+
if (evictToNvmCache && !token_.isValid()) {
12961297
stats_.evictFailConcurrentFill.inc();
1297-
} else if (candidate_->markForEviction()) {
1298-
XDCHECK(candidate_->isMarkedForEviction());
1299-
// markForEviction to make sure no other thead is evicting the item
1300-
// nor holding a handle to that item
1301-
toRecycle = toRecycle_;
1302-
candidate = candidate_;
1303-
1304-
// Check if parent changed for chained items - if yes, we cannot
1305-
// remove the child from the mmContainer as we will not be evicting
1306-
// it. We could abort right here, but we need to cleanup in case
1307-
// unmarkForEviction() returns 0 - so just go through normal path.
1308-
if (!toRecycle_->isChainedItem() ||
1309-
&toRecycle->asChainedItem().getParentItem(compressor_) ==
1310-
candidate)
1311-
mmContainer.remove(itr);
1312-
return;
1313-
} else {
1298+
++itr;
1299+
continue;
1300+
}
1301+
1302+
auto markedForEviction = candidate_->markForEviction();
1303+
if (!markedForEviction) {
13141304
if (candidate_->hasChainedItem()) {
13151305
stats_.evictFailParentAC.inc();
13161306
} else {
13171307
stats_.evictFailAC.inc();
13181308
}
1309+
++itr;
1310+
continue;
13191311
}
13201312

1321-
++itr;
1322-
XDCHECK(toRecycle == nullptr);
1323-
XDCHECK(candidate == nullptr);
1313+
XDCHECK(candidate_->isMarkedForEviction());
1314+
// markForEviction to make sure no other thead is evicting the item
1315+
// nor holding a handle to that item
1316+
toRecycle = toRecycle_;
1317+
candidate = candidate_;
1318+
token = std::move(token_);
1319+
1320+
// Check if parent changed for chained items - if yes, we cannot
1321+
// remove the child from the mmContainer as we will not be evicting
1322+
// it. We could abort right here, but we need to cleanup in case
1323+
// unmarkForEviction() returns 0 - so just go through normal path.
1324+
if (!toRecycle_->isChainedItem() ||
1325+
&toRecycle->asChainedItem().getParentItem(compressor_) ==
1326+
candidate) {
1327+
mmContainer.remove(itr);
1328+
}
1329+
return;
13241330
}
13251331
});
13261332

1327-
if (!toRecycle)
1333+
if (!toRecycle) {
13281334
continue;
1335+
}
13291336

13301337
XDCHECK(toRecycle);
13311338
XDCHECK(candidate);

0 commit comments

Comments
 (0)