valkey icon indicating copy to clipboard operation
valkey copied to clipboard

Fast path in SET if the expiration time is expired

Open enjoy-binbin opened this issue 1 year ago • 2 comments

If the expiration time passed in SET is expired, for example, it has expired due to the machine time (DTS) or the expiration time passed in (wrong arg). In this case, we don't need to set the key and wait for the active expire scan before deleting the key.

Compared with previous changes:

  1. If the key does not exist, previously we would set the key and wait for the active expire to delete it, so it is a set + del from the perspective of propaganda. Now we will no set the key and return, so it a NOP.

  2. If the key exists, previously we woule set the key and wait for the active expire to delete it, so it is a set + del From the perspective of propaganda. Now we will delete it and return, so it is a del.

Adding a new deleteExpiredKeyFromOverwriteAndPropagate function to reduce the duplicate code.

A simple benchmark test:

./src/valkey-benchmark -P 32 -c 100 -n 10000000 -r 1000000000 set __rand_int__ value exat 100

old: 252474.23, new: 829256.12

enjoy-binbin avatar Aug 02 '24 09:08 enjoy-binbin

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.66%. Comparing base (b12668a) to head (58c086c). Report is 32 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #865      +/-   ##
============================================
+ Coverage     70.61%   70.66%   +0.05%     
============================================
  Files           112      112              
  Lines         61515    61514       -1     
============================================
+ Hits          43436    43468      +32     
+ Misses        18079    18046      -33     
Files with missing lines Coverage Δ
src/cluster.c 88.35% <ø> (+0.29%) :arrow_up:
src/db.c 88.50% <100.00%> (+0.07%) :arrow_up:
src/expire.c 96.42% <100.00%> (-0.09%) :arrow_down:
src/server.h 100.00% <ø> (ø)
src/t_string.c 96.49% <100.00%> (-0.02%) :arrow_down:

... and 8 files with indirect coverage changes

codecov[bot] avatar Aug 02 '24 09:08 codecov[bot]

ok, the test failed because the old restore use lazyfree_lazy_server_del to delete the expired key (not the lazy expire)

i am going to leave store alone.

enjoy-binbin avatar Aug 08 '24 05:08 enjoy-binbin