Refactor of LFU/LRU code for modularity#2857
Conversation
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
ranshid
left a comment
There was a problem hiding this comment.
This is a great refactor @JimB123 !
I could not locate any special issues with the proposed change so gave some small comments. My only concern is that I am not sure how much our test coverage is great when it comes to eviction logic. I guess most of the tests are in maxmemory.tcl which are validated. I think that introducing it now (in early development stage) is probably fine.
| } else { | ||
| val->lru = LRU_CLOCK(); | ||
| } | ||
| val->lru = lrulfu_touch(val->lru); |
There was a problem hiding this comment.
why not wrap the touch as an Object API as well?
There was a problem hiding this comment.
There's already pretty tight coupling between db.c and object.c. My intent was to clean up the LRU/LFU API (which I did). I wasn't intending to clean up the db/object coupling - that's a bigger task. Given that this was the only place that needed this, and the files are already coupled, I didn't see a reason to create an API for this.
db.c is already directly accessing the lru field when updating in dbSetValue. So there's no point in trying to completely hide it... without further refactor between db/object.
Co-authored-by: Ran Shidlansik <ranshid@amazon.com> Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #2857 +/- ##
============================================
+ Coverage 72.42% 72.43% +0.01%
============================================
Files 128 129 +1
Lines 70300 70502 +202
============================================
+ Hits 50917 51071 +154
- Misses 19383 19431 +48
🚀 New features to boost your workflow:
|
General cleanup on LRU/LFU code. Improve modularity and maintainability. Specifically: * Consolidates the mathematical logic for LRU/LFU into `lrulfu.c`, with an API in `lrulfu.h`. Knowledge of the LRU/LFU implementation was previously spread out across `db.c`, `evict.c`, `object.c`, `server.c`, and `server.h`. * Separates knowledge of the LRU from knowledge of the object containing the LRU value. `lrulfu.c` knows about the LRU/LFU algorithms, without knowing about the `robj`. `object.c` knows about the `robj` without knowing about the details of the LRU/LFU algorithms. * Eliminated `server.lruclock`, instead using `server.unixtime`. This also eliminates the periodic need to call `mstime()` to maintain the lru clock. * Fixed a minor computation bug in the old `LFUTimeElapsed` function (off by 1 after rollover). * Eliminate specific IF checks for rollover, using defined behavior for unsigned rollover instead. * Fixed a bug in `debug.c` which would perform LFU modification on an LRU value. --------- Signed-off-by: Jim Brunner <brunnerj@amazon.com> Co-authored-by: Ran Shidlansik <ranshid@amazon.com>
General cleanup on LRU/LFU code. Improve modularity and maintainability. Specifically: * Consolidates the mathematical logic for LRU/LFU into `lrulfu.c`, with an API in `lrulfu.h`. Knowledge of the LRU/LFU implementation was previously spread out across `db.c`, `evict.c`, `object.c`, `server.c`, and `server.h`. * Separates knowledge of the LRU from knowledge of the object containing the LRU value. `lrulfu.c` knows about the LRU/LFU algorithms, without knowing about the `robj`. `object.c` knows about the `robj` without knowing about the details of the LRU/LFU algorithms. * Eliminated `server.lruclock`, instead using `server.unixtime`. This also eliminates the periodic need to call `mstime()` to maintain the lru clock. * Fixed a minor computation bug in the old `LFUTimeElapsed` function (off by 1 after rollover). * Eliminate specific IF checks for rollover, using defined behavior for unsigned rollover instead. * Fixed a bug in `debug.c` which would perform LFU modification on an LRU value. --------- Signed-off-by: Jim Brunner <brunnerj@amazon.com> Co-authored-by: Ran Shidlansik <ranshid@amazon.com>
General cleanup on LRU/LFU code. Improve modularity and maintainability. Specifically: * Consolidates the mathematical logic for LRU/LFU into `lrulfu.c`, with an API in `lrulfu.h`. Knowledge of the LRU/LFU implementation was previously spread out across `db.c`, `evict.c`, `object.c`, `server.c`, and `server.h`. * Separates knowledge of the LRU from knowledge of the object containing the LRU value. `lrulfu.c` knows about the LRU/LFU algorithms, without knowing about the `robj`. `object.c` knows about the `robj` without knowing about the details of the LRU/LFU algorithms. * Eliminated `server.lruclock`, instead using `server.unixtime`. This also eliminates the periodic need to call `mstime()` to maintain the lru clock. * Fixed a minor computation bug in the old `LFUTimeElapsed` function (off by 1 after rollover). * Eliminate specific IF checks for rollover, using defined behavior for unsigned rollover instead. * Fixed a bug in `debug.c` which would perform LFU modification on an LRU value. --------- Signed-off-by: Jim Brunner <brunnerj@amazon.com> Co-authored-by: Ran Shidlansik <ranshid@amazon.com> Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
General cleanup on LRU/LFU code. Improve modularity and maintainability.
Specifically:
lrulfu.c, with an API inlrulfu.h. Knowledge of the LRU/LFU implementation was previously spread out acrossdb.c,evict.c,object.c,server.c, andserver.h.lrulfu.cknows about the LRU/LFU algorithms, without knowing about therobj.object.cknows about therobjwithout knowing about the details of the LRU/LFU algorithms.server.lruclock, instead usingserver.unixtime. This also eliminates the periodic need to callmstime()to maintain the lru clock.LFUTimeElapsedfunction (off by 1 after rollover).debug.cwhich would perform LFU modification on an LRU value.