Fix dbExpand not dividing by slots, resulting in consuming slots times the dictExpand (#12773)

We meant to divide it by the number of slots, otherwise it will do slots
times
dictExpand, bug was introduced in #11695.
This commit is contained in:
Binbin 2023-11-22 17:16:06 +08:00 committed by GitHub
parent 58cb302526
commit dedbf99a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

@ -80,6 +80,7 @@ int clusterNodeIsMyself(clusterNode *n);
clusterNode *getMyClusterNode(void);
char *getMyClusterId(void);
int getClusterSize(void);
int getMyClusterSlotCount(void);
int handleDebugClusterCommand(client *c);
int clusterNodePending(clusterNode *node);
int clusterNodeIsMaster(clusterNode *n);

View File

@ -5773,6 +5773,10 @@ int getClusterSize(void) {
return dictSize(server.cluster->nodes);
}
int getMyClusterSlotCount(void) {
return server.cluster->myself->numslots;
}
char **getClusterNodesList(size_t *numnodes) {
size_t count = dictSize(server.cluster->nodes);
char **ids = zmalloc((count+1)*CLUSTER_NAMELEN);

View File

@ -2196,9 +2196,14 @@ 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 = getMyClusterSlotCount();
if (slots == 0) return C_OK;
db_size = db_size / slots;
for (int i = 0; i < CLUSTER_SLOTS; i++) {
if (clusterNodeCoversSlot(getMyClusterNode(), 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 {