Update access LFU/LRU access times when overwriting key
Former-commit-id: f11fdf671700fd5445599c473d69e015eb6618e8
This commit is contained in:
parent
012228bd51
commit
5bdcb8fefb
28
src/db.cpp
28
src/db.cpp
@ -65,6 +65,22 @@ void updateExpire(redisDb *db, sds key, robj *valOld, robj *valNew)
|
|||||||
return;
|
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
|
/* Low level key lookup API, not actually called directly from commands
|
||||||
* implementations that should instead rely on lookupKeyRead(),
|
* implementations that should instead rely on lookupKeyRead(),
|
||||||
@ -74,16 +90,7 @@ static robj *lookupKey(redisDb *db, robj *key, int flags) {
|
|||||||
if (de) {
|
if (de) {
|
||||||
robj *val = (robj*)dictGetVal(de);
|
robj *val = (robj*)dictGetVal(de);
|
||||||
|
|
||||||
/* Update the access time for the ageing algorithm.
|
updateDbValAccess(de, flags);
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & LOOKUP_UPDATEMVCC) {
|
if (flags & LOOKUP_UPDATEMVCC) {
|
||||||
val->mvcc_tstamp = getMvccTstamp();
|
val->mvcc_tstamp = getMvccTstamp();
|
||||||
@ -312,6 +319,7 @@ void genericSetKey(redisDb *db, robj *key, robj *val, int keepttl) {
|
|||||||
if (de == NULL) {
|
if (de == NULL) {
|
||||||
dbAdd(db,key,val);
|
dbAdd(db,key,val);
|
||||||
} else {
|
} else {
|
||||||
|
updateDbValAccess(de, LOOKUP_NONE);
|
||||||
dbOverwriteCore(db,de,key,val,!!g_pserver->fActiveReplica,!keepttl);
|
dbOverwriteCore(db,de,key,val,!!g_pserver->fActiveReplica,!keepttl);
|
||||||
}
|
}
|
||||||
incrRefCount(val);
|
incrRefCount(val);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user