| 280 | } |
| 281 | |
| 282 | Status BlockCache::insert(HashedKey hk, |
| 283 | BufferView value, |
| 284 | uint8_t /* poolId */, |
| 285 | uint32_t /* expiryTime */, |
| 286 | uint32_t lastAccessTimeSecs) { |
| 287 | auto start = getSteadyClock(); |
| 288 | SCOPE_EXIT { |
| 289 | insertLatency_.trackValue(toMicros(getSteadyClock() - start).count()); |
| 290 | }; |
| 291 | INJECT_PAUSE(pause_blockcache_insert_entry); |
| 292 | |
| 293 | auto allocateRes = allocateForInsert(hk, value.size()); |
| 294 | if (allocateRes.hasError()) { |
| 295 | return allocateRes.error(); |
| 296 | } |
| 297 | auto& [desc, slotSize, addr, bufferView] = allocateRes.value(); |
| 298 | |
| 299 | // After allocation a region is opened for writing. Until we close it, the |
| 300 | // region would not be reclaimed and index never gets an invalid entry. |
| 301 | writeEntry(bufferView, hk, value, false, lastAccessTimeSecs); |
| 302 | updateIndex(hk.keyHash(), slotSize, addr, /* allowReplace */ true); |
| 303 | allocator_.close(std::move(desc)); |
| 304 | INJECT_PAUSE(pause_blockcache_insert_done); |
| 305 | return Status::Ok; |
| 306 | } |
| 307 | |
| 308 | bool BlockCache::updateIndex(uint64_t keyHash, |
| 309 | uint32_t size, |