Skip to content

Commit

Permalink
adding deleteExpiredKeyFromOverwriteAndPropagate
Browse files Browse the repository at this point in the history
Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Aug 8, 2024
1 parent db5349d commit 4a742cb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
5 changes: 1 addition & 4 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ void restoreCommand(client *c) {
if (ttl && !absttl) ttl += commandTimeSnapshot();
if (ttl && checkAlreadyExpired(ttl)) {
if (deleted) {
robj *aux = server.lazyfree_lazy_server_del ? shared.unlink : shared.del;
rewriteClientCommandVector(c, 2, aux, key);
signalModifiedKey(c, c->db, key);
notifyKeyspaceEvent(NOTIFY_GENERIC, "del", key, c->db->id);
deleteExpiredKeyFromOverwriteAndPropagate(c, key, 0);
server.dirty++;
}
decrRefCount(obj);
Expand Down
15 changes: 15 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,21 @@ void deleteExpiredKeyAndPropagate(serverDb *db, robj *keyobj) {
server.stat_expiredkeys++;
}

/* Delete the specified expired key from overwriting and propagate the DEL or UNLINK. */
void deleteExpiredKeyFromOverwriteAndPropagate(client *c, robj *keyobj, int do_delete) {
if (do_delete) {
int deleted = dbGenericDelete(c->db, keyobj, server.lazyfree_lazy_expire, DB_FLAG_KEY_EXPIRED);
serverAssertWithInfo(c, keyobj, deleted);
server.dirty++;
}

/* Replicate/AOF this as an explicit DEL or UNLINK. */
robj *aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del;
rewriteClientCommandVector(c, 2, aux, keyobj);
signalModifiedKey(c, c->db, keyobj);
notifyKeyspaceEvent(NOTIFY_GENERIC, "del", keyobj, c->db->id);
}

/* Propagate an implicit key deletion into replicas and the AOF file.
* When a key was deleted in the primary by eviction, expiration or a similar
* mechanism a DEL/UNLINK operation for this key is sent
Expand Down
12 changes: 1 addition & 11 deletions src/expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,17 +668,7 @@ void expireGenericCommand(client *c, long long basetime, int unit) {
}

if (checkAlreadyExpired(when)) {
robj *aux;

int deleted = dbGenericDelete(c->db, key, server.lazyfree_lazy_expire, DB_FLAG_KEY_EXPIRED);
serverAssertWithInfo(c, key, deleted);
server.dirty++;

/* Replicate/AOF this as an explicit DEL or UNLINK. */
aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del;
rewriteClientCommandVector(c, 2, aux, key);
signalModifiedKey(c, c->db, key);
notifyKeyspaceEvent(NOTIFY_GENERIC, "del", key, c->db->id);
deleteExpiredKeyFromOverwriteAndPropagate(c, key, 1);
addReply(c, shared.cone);
return;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3481,6 +3481,7 @@ int setModuleNumericConfig(ModuleConfig *config, long long val, const char **err
/* db.c -- Keyspace access API */
int removeExpire(serverDb *db, robj *key);
void deleteExpiredKeyAndPropagate(serverDb *db, robj *keyobj);
void deleteExpiredKeyFromOverwriteAndPropagate(client *c, robj *keyobj, int do_delete);
void propagateDeletion(serverDb *db, robj *key, int lazy);
int keyIsExpired(serverDb *db, robj *key);
long long getExpire(serverDb *db, robj *key);
Expand Down
25 changes: 3 additions & 22 deletions src/t_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,8 @@ void setGenericCommand(client *c,
* database, and then wait for the active expire to delete it, it is wasteful.
* If the key already exists, delete it. */
if (expire && checkAlreadyExpired(milliseconds)) {
if (found) {
int deleted = dbGenericDelete(c->db, key, server.lazyfree_lazy_expire, DB_FLAG_KEY_EXPIRED);
serverAssertWithInfo(c, key, deleted);
server.dirty++;

/* Replicate/AOF this as an explicit DEL or UNLINK. */
robj *aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del;
rewriteClientCommandVector(c, 2, aux, key);
signalModifiedKey(c, c->db, key);
notifyKeyspaceEvent(NOTIFY_GENERIC, "del", key, c->db->id);
}

if (!(flags & OBJ_SET_GET)) {
addReply(c, ok_reply ? ok_reply : shared.ok);
}
if (found) deleteExpiredKeyFromOverwriteAndPropagate(c, key, 1);
if (!(flags & OBJ_SET_GET)) addReply(c, shared.ok);
return;
}

Expand Down Expand Up @@ -417,13 +404,7 @@ void getexCommand(client *c) {
if (((flags & OBJ_PXAT) || (flags & OBJ_EXAT)) && checkAlreadyExpired(milliseconds)) {
/* When PXAT/EXAT absolute timestamp is specified, there can be a chance that timestamp
* has already elapsed so delete the key in that case. */
int deleted = dbGenericDelete(c->db, c->argv[1], server.lazyfree_lazy_expire, DB_FLAG_KEY_EXPIRED);
serverAssert(deleted);
robj *aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del;
rewriteClientCommandVector(c,2,aux,c->argv[1]);
signalModifiedKey(c, c->db, c->argv[1]);
notifyKeyspaceEvent(NOTIFY_GENERIC, "del", c->argv[1], c->db->id);
server.dirty++;
deleteExpiredKeyFromOverwriteAndPropagate(c, c->argv[1], 1);
} else if (expire) {
setExpire(c,c->db,c->argv[1],milliseconds);
/* Propagate as PXEXPIREAT millisecond-timestamp if there is
Expand Down

0 comments on commit 4a742cb

Please sign in to comment.