| 306 | } |
| 307 | |
| 308 | bool 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 | |
| 339 | bool BlockCache::couldExist(HashedKey hk) { |
| 340 | const auto lr = index_->peek(hk.keyHash()); |
no test coverage detected