From 87a9f79e20f19dbb09c4f3ad0eb621cef347cd66 Mon Sep 17 00:00:00 2001 From: John Sully Date: Mon, 11 May 2020 00:42:46 -0400 Subject: [PATCH] Update access LFU/LRU access times when overwriting key Former-commit-id: f11fdf671700fd5445599c473d69e015eb6618e8 --- src/db.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 01836d713..81e32f849 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -65,6 +65,22 @@ void updateExpire(redisDb *db, sds key, robj *valOld, robj *valNew) return; } +void updateDbValAccess(dictEntry *de, int flags) +{ + robj *val = (robj*)dictGetVal(de); + + /* Update the access time for the ageing algorithm. + * Don't do it if we have a saving child, as this will trigger + * a copy on write madness. */ + if (!hasActiveChildProcess() && !(flags & LOOKUP_NOTOUCH)){ + if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU) { + updateLFU(val); + } else { + val->lru = LRU_CLOCK(); + } + } +} + /* Low level key lookup API, not actually called directly from commands * implementations that should instead rely on lookupKeyRead(), @@ -74,16 +90,7 @@ static robj *lookupKey(redisDb *db, robj *key, int flags) { if (de) { robj *val = (robj*)dictGetVal(de); - /* Update the access time for the ageing algorithm. - * Don't do it if we have a saving child, as this will trigger - * a copy on write madness. */ - if (!hasActiveChildProcess() && !(flags & LOOKUP_NOTOUCH)){ - if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU) { - updateLFU(val); - } else { - val->lru = LRU_CLOCK(); - } - } + updateDbValAccess(de, flags); if (flags & LOOKUP_UPDATEMVCC) { val->mvcc_tstamp = getMvccTstamp(); @@ -312,6 +319,7 @@ void genericSetKey(redisDb *db, robj *key, robj *val, int keepttl) { if (de == NULL) { dbAdd(db,key,val); } else { + updateDbValAccess(de, LOOKUP_NONE); dbOverwriteCore(db,de,key,val,!!g_pserver->fActiveReplica,!keepttl); } incrRefCount(val);