Skip to content

Commit

Permalink
Fix dbExpand not dividing by slots, resulting in consuming slots time…
Browse files Browse the repository at this point in the history
…s the dictExpand

We meant to divide it by the number of slots, otherwise it will do slots times
dictExpand, bug was introduced in redis#11695.
  • Loading branch information
enjoy-binbin committed Nov 16, 2023
1 parent 4366bba commit e12ae47
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -2195,9 +2195,17 @@ int expireIfNeeded(redisDb *db, robj *key, int flags) {
int dbExpand(const redisDb *db, uint64_t db_size, dbKeyType keyType, int try_expand) {
dict *d;
if (server.cluster_enabled) {
/* We don't know exact number of keys that would fall into each slot, but we can
* approximate it, assuming even distribution, divide it by the number of slots. */
int slots = 0;
for (int i = 0; i < CLUSTER_SLOTS; i++) {
if (clusterNodeGetSlotBit(server.cluster->myself, i))
slots++;
}
if (slots > 0) db_size = db_size / slots;

for (int i = 0; i < CLUSTER_SLOTS; i++) {
if (clusterNodeGetSlotBit(server.cluster->myself, i)) {
/* We don't know exact number of keys that would fall into each slot, but we can approximate it, assuming even distribution. */
if (keyType == DB_MAIN) {
d = db->dict[i];
} else {
Expand Down

0 comments on commit e12ae47

Please sign in to comment.