Skip to content

Commit

Permalink
Updated test, dbFindExpiresWithSlot visibility and kvstore API usage
Browse files Browse the repository at this point in the history
Signed-off-by: Nadav Levanoni <[email protected]>
  • Loading branch information
nadavl-a committed Oct 15, 2024
1 parent 0e4e2e1 commit ad84873
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
17 changes: 9 additions & 8 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int keyIsExpiredWithSlot(serverDb *db, robj *key, int slot);
int keyIsExpired(serverDb *db, robj *key);
static void dbSetValue(serverDb *db, robj *key, robj *val, int overwrite, dictEntry *de);
static int getKVStoreIndexForKey(sds key);
dictEntry *dbFindExpiresWithSlot(serverDb *db, void *key, int slot);

/* Update LFU when an object is accessed.
* Firstly, decrement the counter if the decrement time is reached.
Expand Down Expand Up @@ -439,8 +440,8 @@ int dbGenericDeleteWithSlot(serverDb *db, robj *key, int async, int flags, int s

/* Helper for sync and async delete. */
int dbGenericDelete(serverDb *db, robj *key, int async, int flags) {
int slot = server.cluster_enabled ? getKeySlot(key->ptr) : 0;
return dbGenericDeleteWithSlot(db, key, async, flags, slot);
int dict_index = getKVStoreIndexForKey(key->ptr);
return dbGenericDeleteWithSlot(db, key, async, flags, dict_index);
}

/* Delete a key, value, and associated expiration entry if any, from the DB */
Expand Down Expand Up @@ -1711,8 +1712,8 @@ long long getExpireWithSlot(serverDb *db, robj *key, int slot) {
/* Return the expire time of the specified key, or -1 if no expire
* is associated with this key (i.e. the key is non volatile) */
long long getExpire(serverDb *db, robj *key) {
int slot = server.cluster_enabled ? getKeySlot(key->ptr) : 0;
return getExpireWithSlot(db, key, slot);
int dict_index = getKVStoreIndexForKey(key->ptr);
return getExpireWithSlot(db, key, dict_index);
}

void deleteExpiredKeyAndPropagateWithSlot(serverDb *db, robj *keyobj, int slot) {
Expand Down Expand Up @@ -1802,8 +1803,8 @@ int keyIsExpiredWithSlot(serverDb *db, robj *key, int slot) {

/* Check if the key is expired. */
int keyIsExpired(serverDb *db, robj *key) {
int slot = server.cluster_enabled ? getKeySlot(key->ptr) : 0;
return keyIsExpiredWithSlot(db, key, slot);
int dict_index = getKVStoreIndexForKey(key->ptr);
return keyIsExpiredWithSlot(db, key, dict_index);
}

keyStatus expireIfNeededWithSlot(serverDb *db, robj *key, int flags, int slot) {
Expand Down Expand Up @@ -1881,8 +1882,8 @@ keyStatus expireIfNeededWithSlot(serverDb *db, robj *key, int flags, int slot) {
* The function returns KEY_EXPIRED if the key is expired BUT not deleted,
* or returns KEY_DELETED if the key is expired and deleted. */
keyStatus expireIfNeeded(serverDb *db, robj *key, int flags) {
int slot = server.cluster_enabled ? getKeySlot(key->ptr) : 0;
return expireIfNeededWithSlot(db, key, flags, slot);
int dict_index = getKVStoreIndexForKey(key->ptr);
return expireIfNeededWithSlot(db, key, flags, dict_index);
}

/* CB passed to kvstoreExpand.
Expand Down
1 change: 0 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,6 @@ int calculateKeySlot(sds key);
int dbExpand(serverDb *db, uint64_t db_size, int try_expand);
int dbExpandExpires(serverDb *db, uint64_t db_size, int try_expand);
dictEntry *dbFind(serverDb *db, void *key);
dictEntry *dbFindExpiresWithSlot(serverDb *db, void *key, int slot);
dictEntry *dbFindExpires(serverDb *db, void *key);
unsigned long long dbSize(serverDb *db);
unsigned long long dbScan(serverDb *db, unsigned long long cursor, dictScanFunction *scan_cb, void *privdata);
Expand Down
12 changes: 0 additions & 12 deletions tests/unit/cluster/multi-slot-operations.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,3 @@ test "DELSLOTSRANGE command with several boundary conditions test suite" {
assert_match "*9829 11000*12001 12100*12201 13104*" [$master4 CLUSTER SLOTS]
}
} cluster_allocate_with_continuous_slots_local

start_cluster 1 0 {tags {external:skip cluster}} {
test "Regression test for multi-exec with RANDOMKEY accessing the wrong per-slot dictionary" {
R 0 SETEX FOO 10000 BAR
R 0 SETEX FIZZ 10000 BUZZ

R 0 MULTI
R 0 GET FOO
R 0 RANDOMKEY
R 0 EXEC
}
}
12 changes: 12 additions & 0 deletions tests/unit/multi.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -919,3 +919,15 @@ start_server {overrides {appendonly {yes} appendfilename {appendonly.aof} append
r get foo
} {}
}

start_cluster 1 0 {tags {"external:skip cluster"}} {
test "Regression test for multi-exec with RANDOMKEY accessing the wrong per-slot dictionary" {
R 0 SETEX FOO 10000 BAR
R 0 SETEX FIZZ 10000 BUZZ

R 0 MULTI
R 0 DEL FOO
R 0 RANDOMKEY
assert_equal [R 0 EXEC] {1 FIZZ}
}
}

0 comments on commit ad84873

Please sign in to comment.