Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update evictionpool if needed #5368

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from

Conversation

soloestoy
Copy link
Collaborator

Update evictionPool every time we call freeMemoryIfNeeded,
in case the old candidates is not the best, imagine that:

Time1: we need free memory and populate some keys to evictionPool
like that: A:10,B:9,C:8
Time2: we delete the bestkey A and free enough memory, then keys
in evictionPool are: B:9,C:8
Time3: we need free memory again, and the idle time of B is 3,
but B is already in evctionPool and idle time is 9, so
we take it as the bestkey to delete, but it is not the
correct bestkey.

Also we should update evictionPool in case maxmemory-policy changed,
because LRU, LFU and TTL has different meanings.

BTW, compare to the whole eviction cycle, update evictionPool before the cycle is not a big deal.

Update the cache of possible candidates in the evictionPool,
in case the old candidates is not the best, imagine that:

Time1: we need free memory and populate some keys to evictionPool
       like that: A:10,B:9,C:8
Time2: we delete the bestkey A and free enough memory, then keys
       in evictionPool are: B:9,C:8
Time3: we need free memory again, and the idle time of B is 3,
       but B is already in evctionPool and idle time is 9, so
       we take it as the bestkey to delete, but it is not the
       correct bestkey.

Also we should update evictionPool in case maxmemory-policy changed,
because LRU, LFU and TTL has different meanings.
Firstly update every entries idle time, or remove it
if the the key is not we want.
After that using qsort to update entries order in
evictionPool, if key is NULL we take is as maximum.
Thus we can avoid unnecessary sdsdup & sdsfree.
@oranagra
Copy link
Member

before evicting a key based on the pool, we populate it again.
so possibly something else got pushed in front.
anyway, what is your suggestion (i'm too lazy to read the code)? to update and re-sort the existing items in the pull before population?

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants