@@ -497,7 +497,6 @@ uint32_t BlockCache::onRegionReclaim(RegionId rid, BufferView buffer) {
497497 makeHK (entryEnd - sizeof (EntryDesc) - desc.keySize , desc.keySize );
498498 BufferView value{desc.valueSize , entryEnd - entrySize};
499499
500- BlockCache::ReinsertionRes reinsertionRes = ReinsertionRes::kRemoved ;
501500 if (checksumData_ && desc.cs != checksum (value)) {
502501 // We do not need to abort here since the EntryDesc checksum was good, so
503502 // we can safely proceed to read the next entry.
@@ -515,30 +514,30 @@ uint32_t BlockCache::onRegionReclaim(RegionId rid, BufferView buffer) {
515514 desc.valueSize ,
516515 folly::hexlify (folly::ByteRange (value.data (), value.dataEnd ())));
517516 reclaimValueChecksumErrorCount_.inc ();
518- if (removeItem (hk, RelAddress{rid, offset})) {
519- reinsertionRes = ReinsertionRes::kEvicted ;
520- }
517+ removeItem (hk, RelAddress{rid, offset});
521518 // Reset the value to nullptr to avoid the destructor doing wrong thing
522519 value = BufferView ();
523520 } else {
524- reinsertionRes =
521+ AllocatorApiResult reinsertionRes =
525522 reinsertOrRemoveItem (hk, value, entrySize, RelAddress{rid, offset});
526523 switch (reinsertionRes) {
527- case ReinsertionRes:: kEvicted :
524+ case AllocatorApiResult:: EVICTED :
528525 evictionCount++;
529526 usedSizeBytes_.sub (decodeSizeHint (encodeSizeHint (entrySize)));
530527 break ;
531- case ReinsertionRes:: kRemoved :
528+ case AllocatorApiResult:: REMOVED :
532529 holeCount_.sub (1 );
533530 holeSizeTotal_.sub (decodeSizeHint (encodeSizeHint (entrySize)));
534531 break ;
535- case ReinsertionRes:: kReinserted :
532+ default :
536533 break ;
537534 }
538- }
539-
540- if (destructorCb_ && reinsertionRes == ReinsertionRes::kEvicted ) {
541- destructorCb_ (hk, value, DestructorEvent::Recycled);
535+ if (destructorCb_ && reinsertionRes == AllocatorApiResult::EVICTED ) {
536+ destructorCb_ (hk, value, DestructorEvent::Recycled);
537+ } else {
538+ updateEventTracker (hk.key (), AllocatorApiEvent::NVM_EVICT ,
539+ reinsertionRes, entrySize);
540+ }
542541 }
543542 XDCHECK_GE (offset, entrySize);
544543 offset -= entrySize;
@@ -611,22 +610,34 @@ bool BlockCache::removeItem(HashedKey hk, RelAddress currAddr) {
611610 return false ;
612611}
613612
614- BlockCache::ReinsertionRes BlockCache::reinsertOrRemoveItem (
615- HashedKey hk, BufferView value, uint32_t entrySize, RelAddress currAddr) {
613+ void BlockCache::updateEventTracker (folly::StringPiece key,
614+ AllocatorApiEvent event,
615+ AllocatorApiResult result,
616+ uint32_t size) {
617+ if (eventTracker_.has_value ()) {
618+ eventTracker_->get ().record (event, key, result, size);
619+ }
620+ }
621+
622+ AllocatorApiResult BlockCache::reinsertOrRemoveItem (HashedKey hk,
623+ BufferView value,
624+ uint32_t entrySize,
625+ RelAddress currAddr) {
616626 auto removeItem = [this , hk, currAddr](bool expired) {
617627 if (index_->removeIfMatch (hk.keyHash (), encodeRelAddress (currAddr))) {
618628 if (expired) {
619629 evictionExpiredCount_.inc ();
630+ return AllocatorApiResult::EXPIRED ;
620631 }
621- return ReinsertionRes:: kEvicted ;
632+ return AllocatorApiResult:: EVICTED ;
622633 }
623- return ReinsertionRes:: kRemoved ;
634+ return AllocatorApiResult:: REMOVED ;
624635 };
625636
626637 const auto lr = index_->peek (hk.keyHash ());
627638 if (!lr.found () || decodeRelAddress (lr.address ()) != currAddr) {
628639 evictionLookupMissCounter_.inc ();
629- return ReinsertionRes:: kRemoved ;
640+ return AllocatorApiResult:: REMOVED ;
630641 }
631642
632643 if (checkExpired_ && checkExpired_ (value)) {
@@ -657,10 +668,12 @@ BlockCache::ReinsertionRes BlockCache::reinsertOrRemoveItem(
657668 case OpenStatus::Error:
658669 allocErrorCount_.inc ();
659670 reinsertionErrorCount_.inc ();
660- break ;
671+ removeItem (false );
672+ return AllocatorApiResult::FAILED ;
661673 case OpenStatus::Retry:
662674 reinsertionErrorCount_.inc ();
663- return removeItem (false );
675+ removeItem (false );
676+ return AllocatorApiResult::FAILED ;
664677 }
665678 auto closeRegionGuard =
666679 folly::makeGuard ([this , desc_2 = std::move (desc)]() mutable {
@@ -680,12 +693,14 @@ BlockCache::ReinsertionRes BlockCache::reinsertOrRemoveItem(
680693 encodeRelAddress (addr.add (slotSize)),
681694 encodeRelAddress (currAddr));
682695 if (!replaced) {
696+ // happens if you can't find the key in the map
683697 reinsertionErrorCount_.inc ();
684- return removeItem (false );
698+ removeItem (false );
699+ return AllocatorApiResult::FAILED ;
685700 }
686701 reinsertionCount_.inc ();
687702 reinsertionBytes_.add (entrySize);
688- return ReinsertionRes:: kReinserted ;
703+ return AllocatorApiResult:: REINSERTED ;
689704}
690705
691706Status BlockCache::writeEntry (RelAddress addr,
0 commit comments