MCPcopy Create free account
hub / github.com/facebook/CacheLib / updateIndex

Method updateIndex

cachelib/navy/block_cache/BlockCache.cpp:308–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308bool BlockCache::updateIndex(uint64_t keyHash,
309 uint32_t size,
310 const RelAddress& addr,
311 bool allowReplace) const {
312 auto newObjSizeHint = encodeSizeHint(size);
313 auto encodedAddr = encodeRelAddress(addr.add(size));
314 const auto lr =
315 allowReplace
316 ? index_->insert(keyHash, encodedAddr, newObjSizeHint)
317 : index_->insertIfNotExists(keyHash, encodedAddr, newObjSizeHint);
318 // We replaced an existing key in the index
319 uint64_t newObjSize = decodeSizeHint(newObjSizeHint);
320 uint64_t oldObjSize = 0;
321 if (lr.found()) {
322 insertHashCollisionCount_.inc();
323 if (allowReplace) {
324 oldObjSize = decodeSizeHint(lr.sizeHint());
325 addHole(oldObjSize);
326 } else {
327 return false;
328 }
329 }
330 succInsertCount_.inc();
331 if (newObjSize < oldObjSize) {
332 usedSizeBytes_.sub(oldObjSize - newObjSize);
333 } else {
334 usedSizeBytes_.add(newObjSize - oldObjSize);
335 }
336 return true;
337}
338
339bool BlockCache::couldExist(HashedKey hk) {
340 const auto lr = index_->peek(hk.keyHash());

Callers 1

writeBackImplMethod · 0.80

Calls 7

foundMethod · 0.80
sizeHintMethod · 0.80
addMethod · 0.45
insertMethod · 0.45
insertIfNotExistsMethod · 0.45
incMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected