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

Unshare object to avoid LRU/LFU being messed up. #250

Merged

Conversation

CharlesChen888
Copy link
Member

@CharlesChen888 CharlesChen888 commented Apr 7, 2024

When LRU/LFU enabled, Valkey does not allow using shared objects, as value objects may be shared among many different keys and they can't share LRU/LFU information.

However maxmemory-policy is modifiable at runtime. If LRU/LFU is not enabled at start, but then enabled when some shared objects are already used, there could be some confusion in LRU/LFU information.

For set command it is OK since it is going to create a new object when LRU/LFU enabled, but get command will not unshare the object and just update LRU/LFU information.

So we may duplicate the object in this case. It is a one-time task for each key using shared objects, unless this is the case for so many keys, there should be no serious performance degradation.

Still, LRU will be updated anyway, no matter LRU/LFU is enabled or not, because OBJECT IDLETIME needs it, unless maxmemory-policy is set to LFU. So idle time of a key may still be messed up.

@CharlesChen888 CharlesChen888 force-pushed the unshare-obj-when-lrulfu branch from 29c44ec to 73395f3 Compare April 7, 2024 09:39
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix.

How did you spot this problem?

Do you want to add a test case for it?

src/object.c Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.17%. Comparing base (1c55f3c) to head (43584f9).
Report is 14 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #250      +/-   ##
============================================
- Coverage     70.19%   70.17%   -0.03%     
============================================
  Files           109      110       +1     
  Lines         59905    59889      -16     
============================================
- Hits          42050    42026      -24     
- Misses        17855    17863       +8     
Files Coverage Δ
src/db.c 88.30% <100.00%> (+0.03%) ⬆️
src/object.c 78.60% <100.00%> (+0.02%) ⬆️
src/server.h 100.00% <100.00%> (ø)

... and 13 files with indirect coverage changes

CharlesChen888 and others added 3 commits May 27, 2024 09:08
Signed-off-by: chentianjie.ctj <chentianjie.ctj@alibaba-inc.com>
Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
@zuiderkwast zuiderkwast added bug Something isn't working release-notes This issue should get a line item in the release notes labels Jun 1, 2024
@zuiderkwast zuiderkwast merged commit d16b4ec into valkey-io:unstable Jun 1, 2024
17 checks passed
naglera pushed a commit to naglera/placeholderkv that referenced this pull request Jun 10, 2024
When LRU/LFU enabled, Valkey does not allow using shared objects, as
value objects may be shared among many different keys and they can't
share LRU/LFU information.

However `maxmemory-policy` is modifiable at runtime. If LRU/LFU is not
enabled at start, but then enabled when some shared objects are already
used, there could be some confusion in LRU/LFU information.

For `set` command it is OK since it is going to create a new object when
LRU/LFU enabled, but `get` command will not unshare the object and just
update LRU/LFU information.

So we may duplicate the object in this case. It is a one-time task for
each key using shared objects, unless this is the case for so many keys,
there should be no serious performance degradation.

Still, LRU will be updated anyway, no matter LRU/LFU is enabled or not,
because `OBJECT IDLETIME` needs it, unless `maxmemory-policy` is set to
LFU. So idle time of a key may still be messed up.

---------

Signed-off-by: chentianjie.ctj <chentianjie.ctj@alibaba-inc.com>
Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release-notes This issue should get a line item in the release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants