Skip to content

Commit

Permalink
Handle keyIsExpiredWithDictIndex to make it check for import mode (va…
Browse files Browse the repository at this point in the history
…lkey-io#1368)

In valkey-io#1326 we make KEYS can visit expired key in import-source state
by updating keyIsExpired to check for import mode. But after valkey-io#1205,
we now use keyIsExpiredWithDictIndex to optimize and remove the
redundant dict_index, and keyIsExpiredWithDictIndex does not handle
this logic.

In this commit, we handle keyIsExpiredWithDictIndex to make it check
for import mode as well so that KEYS can visit the expired key.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin authored Nov 28, 2024
1 parent db7b739 commit a939cb8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ void propagateDeletion(serverDb *db, robj *key, int lazy) {
decrRefCount(argv[1]);
}

int keyIsExpiredWithDictIndex(serverDb *db, robj *key, int dict_index) {
static int keyIsExpiredWithDictIndexImpl(serverDb *db, robj *key, int dict_index) {
/* Don't expire anything while loading. It will be done later. */
if (server.loading) return 0;

Expand All @@ -1806,9 +1806,8 @@ int keyIsExpiredWithDictIndex(serverDb *db, robj *key, int dict_index) {
}

/* Check if the key is expired. */
int keyIsExpired(serverDb *db, robj *key) {
int dict_index = getKVStoreIndexForKey(key->ptr);
if (!keyIsExpiredWithDictIndex(db, key, dict_index)) return 0;
int keyIsExpiredWithDictIndex(serverDb *db, robj *key, int dict_index) {
if (!keyIsExpiredWithDictIndexImpl(db, key, dict_index)) return 0;

/* See expireIfNeededWithDictIndex for more details. */
if (server.primary_host == NULL && server.import_mode) {
Expand All @@ -1817,9 +1816,15 @@ int keyIsExpired(serverDb *db, robj *key) {
return 1;
}

/* Check if the key is expired. */
int keyIsExpired(serverDb *db, robj *key) {
int dict_index = getKVStoreIndexForKey(key->ptr);
return keyIsExpiredWithDictIndex(db, key, dict_index);
}

keyStatus expireIfNeededWithDictIndex(serverDb *db, robj *key, int flags, int dict_index) {
if (server.lazy_expire_disabled) return KEY_VALID;
if (!keyIsExpiredWithDictIndex(db, key, dict_index)) return KEY_VALID;
if (!keyIsExpiredWithDictIndexImpl(db, key, dict_index)) return KEY_VALID;

/* If we are running in the context of a replica, instead of
* evicting the expired key from the database, we return ASAP:
Expand Down

0 comments on commit a939cb8

Please sign in to comment.