mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Add latency monitor sample when key is deleted via lazy expire (#9317)
Fix that there is no sample latency after the key expires via expireIfNeeded(). Some refactoring for shared code.
This commit is contained in:
parent
d32f8641ed
commit
ca559819f7
28
src/db.c
28
src/db.c
@ -30,6 +30,7 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "cluster.h"
|
#include "cluster.h"
|
||||||
#include "atomicvar.h"
|
#include "atomicvar.h"
|
||||||
|
#include "latency.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -1437,6 +1438,22 @@ long long getExpire(redisDb *db, robj *key) {
|
|||||||
return dictGetSignedIntegerVal(de);
|
return dictGetSignedIntegerVal(de);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Delete the specified expired key and propagate expire. */
|
||||||
|
void deleteExpiredKeyAndPropagate(redisDb *db, robj *keyobj) {
|
||||||
|
mstime_t expire_latency;
|
||||||
|
latencyStartMonitor(expire_latency);
|
||||||
|
if (server.lazyfree_lazy_expire)
|
||||||
|
dbAsyncDelete(db,keyobj);
|
||||||
|
else
|
||||||
|
dbSyncDelete(db,keyobj);
|
||||||
|
latencyEndMonitor(expire_latency);
|
||||||
|
latencyAddSampleIfNeeded("expire-del",expire_latency);
|
||||||
|
notifyKeyspaceEvent(NOTIFY_EXPIRED,"expired",keyobj,db->id);
|
||||||
|
signalModifiedKey(NULL, db, keyobj);
|
||||||
|
propagateExpire(db,keyobj,server.lazyfree_lazy_expire);
|
||||||
|
server.stat_expiredkeys++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Propagate expires into slaves and the AOF file.
|
/* Propagate expires into slaves and the AOF file.
|
||||||
* When a key expires in the master, a DEL operation for this key is sent
|
* When a key expires in the master, a DEL operation for this key is sent
|
||||||
* to all the slaves and the AOF file if enabled.
|
* to all the slaves and the AOF file if enabled.
|
||||||
@ -1541,16 +1558,7 @@ int expireIfNeeded(redisDb *db, robj *key) {
|
|||||||
if (checkClientPauseTimeoutAndReturnIfPaused()) return 1;
|
if (checkClientPauseTimeoutAndReturnIfPaused()) return 1;
|
||||||
|
|
||||||
/* Delete the key */
|
/* Delete the key */
|
||||||
if (server.lazyfree_lazy_expire) {
|
deleteExpiredKeyAndPropagate(db,key);
|
||||||
dbAsyncDelete(db,key);
|
|
||||||
} else {
|
|
||||||
dbSyncDelete(db,key);
|
|
||||||
}
|
|
||||||
server.stat_expiredkeys++;
|
|
||||||
propagateExpire(db,key,server.lazyfree_lazy_expire);
|
|
||||||
notifyKeyspaceEvent(NOTIFY_EXPIRED,
|
|
||||||
"expired",key,db->id);
|
|
||||||
signalModifiedKey(NULL,db,key);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
src/expire.c
15
src/expire.c
@ -53,24 +53,11 @@
|
|||||||
* to the function to avoid too many gettimeofday() syscalls. */
|
* to the function to avoid too many gettimeofday() syscalls. */
|
||||||
int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
|
int activeExpireCycleTryExpire(redisDb *db, dictEntry *de, long long now) {
|
||||||
long long t = dictGetSignedIntegerVal(de);
|
long long t = dictGetSignedIntegerVal(de);
|
||||||
mstime_t expire_latency;
|
|
||||||
if (now > t) {
|
if (now > t) {
|
||||||
sds key = dictGetKey(de);
|
sds key = dictGetKey(de);
|
||||||
robj *keyobj = createStringObject(key,sdslen(key));
|
robj *keyobj = createStringObject(key,sdslen(key));
|
||||||
|
deleteExpiredKeyAndPropagate(db,keyobj);
|
||||||
propagateExpire(db,keyobj,server.lazyfree_lazy_expire);
|
|
||||||
latencyStartMonitor(expire_latency);
|
|
||||||
if (server.lazyfree_lazy_expire)
|
|
||||||
dbAsyncDelete(db,keyobj);
|
|
||||||
else
|
|
||||||
dbSyncDelete(db,keyobj);
|
|
||||||
latencyEndMonitor(expire_latency);
|
|
||||||
latencyAddSampleIfNeeded("expire-del",expire_latency);
|
|
||||||
notifyKeyspaceEvent(NOTIFY_EXPIRED,
|
|
||||||
"expired",keyobj,db->id);
|
|
||||||
signalModifiedKey(NULL, db, keyobj);
|
|
||||||
decrRefCount(keyobj);
|
decrRefCount(keyobj);
|
||||||
server.stat_expiredkeys++;
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2377,6 +2377,7 @@ void initConfigValues();
|
|||||||
|
|
||||||
/* db.c -- Keyspace access API */
|
/* db.c -- Keyspace access API */
|
||||||
int removeExpire(redisDb *db, robj *key);
|
int removeExpire(redisDb *db, robj *key);
|
||||||
|
void deleteExpiredKeyAndPropagate(redisDb *db, robj *keyobj);
|
||||||
void propagateExpire(redisDb *db, robj *key, int lazy);
|
void propagateExpire(redisDb *db, robj *key, int lazy);
|
||||||
int keyIsExpired(redisDb *db, robj *key);
|
int keyIsExpired(redisDb *db, robj *key);
|
||||||
int expireIfNeeded(redisDb *db, robj *key);
|
int expireIfNeeded(redisDb *db, robj *key);
|
||||||
|
Loading…
Reference in New Issue
Block a user