Skip to content

Commit

Permalink
Fix ebuckets stop indication during ebExpire() (#13287)
Browse files Browse the repository at this point in the history
on active-expire of buckets, at function `ebExpire()` ->
`ebSegExpire()`, if callback `onExpireItem()` indicated to stop, Yet
iterator (iter) was wrongly already got updated to point to next item.
In turn the segment will be updated without current item.
  • Loading branch information
moticless committed May 23, 2024
1 parent a25b153 commit ae6df30
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ebuckets.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,11 @@ static int ebSegExpire(FirstSegHdr *firstSegHdr,

for (i = 0; (i < numItemsInSeg) && (info->itemsExpired < info->maxToExpire) ; ++i) {
mIter = type->getExpireMeta(iter);
eItem toDelete = iter;
iter = mIter->next;

/* keep aside `next` before removing `iter` by onExpireItem */
eItem next = mIter->next;
mIter->trash = 1;
ExpireAction act = info->onExpireItem(toDelete, info->ctx);
ExpireAction act = info->onExpireItem(iter, info->ctx);

/* if (act == ACT_REMOVE_EXP_ITEM)
* then don't touch the item. Assume it got deleted */
Expand All @@ -452,9 +453,11 @@ static int ebSegExpire(FirstSegHdr *firstSegHdr,

if (act == ACT_UPDATE_EXP_ITEM) {
mIter->next = *updateList;
*updateList = toDelete;
*updateList = iter;
}

/* Item was REMOVED/UPDATED. Advance to `next` item */
iter = next;
++info->itemsExpired;
firstSegHdr->totalItems -= 1;
}
Expand Down Expand Up @@ -672,6 +675,7 @@ static int ebListExpire(ebuckets *eb,
if (info->itemsExpired == info->maxToExpire)
break;

/* keep aside `next` before removing `iter` by onExpireItem */
eItem *next = metaItem->next;
metaItem->trash = 1;
ExpireAction act = info->onExpireItem(item, info->ctx);
Expand Down

0 comments on commit ae6df30

Please sign in to comment.